From b0fa8cbaff5121f3ef3fa752ff7c43d9abcbc1eb Mon Sep 17 00:00:00 2001 From: Eason Date: Wed, 14 Jun 2023 13:31:52 +0800 Subject: [PATCH] remove useless code --- core/executor/src/tracing.rs | 119 +++++++++-------------------------- 1 file changed, 31 insertions(+), 88 deletions(-) diff --git a/core/executor/src/tracing.rs b/core/executor/src/tracing.rs index ac072fd41..86b23645a 100644 --- a/core/executor/src/tracing.rs +++ b/core/executor/src/tracing.rs @@ -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}; @@ -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>); @@ -48,7 +35,7 @@ macro_rules! trace_type { self.0.insert(key, value); } } - } + }; } pub fn trace_using(listener: &mut T, enable_gasometer: bool, f: F) -> R @@ -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 @@ -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), + } } } @@ -377,7 +368,7 @@ impl TryFrom for Web3TransactionTrace { type Error = String; fn try_from(mut value: TransactionTrace) -> Result { - let log_len = value.logs().len(); + let log_len = value.struct_logs.len(); if log_len == 0 { return Err("No logs".to_string()); @@ -392,14 +383,14 @@ impl TryFrom 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]); @@ -456,58 +447,12 @@ fn build_subcalls( stack } -impl TransactionTrace { - pub fn new( - gas: u64, - failed: bool, - return_value: Vec, - 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); - -impl Logs { - pub fn len(&self) -> usize { - self.0.len() - } - - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } -} - -impl Index 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 { @@ -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_": "",