Skip to content

Commit

Permalink
remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
Eason committed Jun 20, 2023
1 parent 33d8057 commit 1c0dbfe
Showing 1 changed file with 31 additions and 88 deletions.
119 changes: 31 additions & 88 deletions core/executor/src/tracing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{cell::RefCell, ops::Index, ptr::NonNull, rc::Rc};
use std::{cell::RefCell, ptr::NonNull, rc::Rc};

use evm::gasometer::tracing as gas_tracing;
use evm::{tracing as evm_tracing, Capture};
Expand All @@ -9,37 +9,24 @@ use protocol::types::{Hex, TransactionTrace as Web3TransactionTrace, H160, H256,
use crate::tracing::{wrapped_event::WrappedEvent, wrapped_opcode::Opcode};

macro_rules! trace_type {
($($name: ident,)*) => {
$(
#[derive(Default, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct $name(pub [u8; 32]);

impl $name {
pub fn into_raw(self) -> [u8; 32] {
self.0
}
}
)*
($name: ident, $type_: ty) => {
#[derive(Default, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct $name(pub $type_);
};

(Vec $(, $name: ident)*) => {
$(
#[derive(Default, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct $name(pub Vec<[u8; 32]>);

impl $name {
pub fn len(&self) -> usize {
self.0.len()
}
($name: ident, Vec, $type_: ty) => {
#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct $name(pub Vec<$type_>);

pub fn into_raw(self) -> Vec<[u8; 32]> {
self.0
}
impl $name {
#[allow(dead_code)]
pub fn len(&self) -> usize {
self.0.len()
}
)*
}
};

($name: ident, $key: ident, $val: ident) => {
($name: ident, BTreeMap, ($key: ident, $val: ident)) => {
#[derive(Default, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct $name(pub std::collections::BTreeMap<$key, $val>);

Expand All @@ -48,7 +35,7 @@ macro_rules! trace_type {
self.0.insert(key, value);
}
}
}
};
}

pub fn trace_using<T, R, F>(listener: &mut T, enable_gasometer: bool, f: F) -> R
Expand Down Expand Up @@ -245,10 +232,9 @@ impl runtime_tracing::EventListener for AxonListener {
self.logs.push(self.current.clone());
}
Err(Capture::Exit(reason)) => {
// Step completed, push current log into the record
// Step completed, push current log into the record, reduce depth by 1
self.logs.push(self.current.clone());
self.current.output = return_value.to_vec();
// Current sub-call completed, reduce depth by 1
self.current.depth -= 1;

// if the depth is 0 then the transaction is complete
Expand Down Expand Up @@ -342,7 +328,12 @@ impl AxonListener {
}

pub fn finish(self) -> TransactionTrace {
TransactionTrace::new(self.gas_used, self.failed, self.output, Logs(self.logs))
TransactionTrace {
gas: self.gas_used,
failed: self.failed,
return_value: self.output,
struct_logs: Logs(self.logs),
}
}
}

Expand Down Expand Up @@ -377,7 +368,7 @@ impl TryFrom<TransactionTrace> for Web3TransactionTrace {
type Error = String;

fn try_from(mut value: TransactionTrace) -> Result<Self, Self::Error> {
let log_len = value.logs().len();
let log_len = value.struct_logs.len();

if log_len == 0 {
return Err("No logs".to_string());
Expand All @@ -392,14 +383,14 @@ impl TryFrom<TransactionTrace> for Web3TransactionTrace {
input: Hex::encode(root.input),
output: Hex::encode(&value.return_value),
gas: U256::zero(),
gas_used: value.gas().into(),
gas_used: value.gas.into(),
error: None,
revert_reason: None,
calls: None,
};

if log_len > 1 {
let logs = &value.logs().0;
let logs = &value.struct_logs.0;

if !logs.windows(2).all(|pair| {
let (prev, next) = (&pair[0], &pair[1]);
Expand Down Expand Up @@ -456,58 +447,12 @@ fn build_subcalls(
stack
}

impl TransactionTrace {
pub fn new(
gas: u64,
failed: bool,
return_value: Vec<u8>,
struct_logs: Logs,
) -> TransactionTrace {
Self {
gas,
failed,
return_value,
struct_logs,
}
}

pub fn gas(&self) -> u64 {
self.gas
}

pub fn result(&self) -> &[u8] {
self.return_value.as_slice()
}

pub fn logs(&self) -> &Logs {
&self.struct_logs
}
}

#[derive(Default, Clone, Debug, PartialEq, Eq)]
pub struct Logs(pub Vec<TraceLog>);

impl Logs {
pub fn len(&self) -> usize {
self.0.len()
}

pub fn is_empty(&self) -> bool {
self.0.is_empty()
}
}

impl Index<usize> for Logs {
type Output = TraceLog;

fn index(&self, index: usize) -> &Self::Output {
&self.0[index]
}
}

trace_type!(LogStorageKey, LogStorageValue,);
trace_type!(Vec, LogMemory, LogStack);
trace_type!(LogStorage, LogStorageKey, LogStorageValue);
trace_type!(LogStorageKey, [u8; 32]);
trace_type!(LogStorageValue, [u8; 32]);
trace_type!(LogMemory, Vec, [u8; 32]);
trace_type!(LogStack, Vec, [u8; 32]);
trace_type!(Logs, Vec, TraceLog);
trace_type!(LogStorage, BTreeMap, (LogStorageKey, LogStorageValue));

impl From<&[u8]> for LogMemory {
fn from(bytes: &[u8]) -> Self {
Expand Down Expand Up @@ -702,10 +647,8 @@ mod tests {
mock_trace(2),
mock_trace(1),
];
let mut i = 0usize;

let res = build_subcalls(&logs, &mut i, 1);

let res = build_subcalls(&logs, &mut 0, 1);
let data = r#"[
{
"type_": "",
Expand Down

0 comments on commit 1c0dbfe

Please sign in to comment.