Skip to content

Commit

Permalink
patch with traceconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
zfy0701 committed Sep 15, 2024
1 parent 32e95aa commit 2fd3fd4
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 37 deletions.
3 changes: 2 additions & 1 deletion client/evm-tracing/src/listeners/sentio_call_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use std::{collections::HashMap, str::FromStr, vec, vec::Vec};
use crate::listeners::sentio_util::{
copy_memory, copy_stack, format_memory, stack_back, to_opcode, unpack_revert,
};
use crate::types::sentio;
use crate::types::{sentio};
use crate::types::sentio::{
FunctionInfo, SentioBaseTrace, SentioCallTrace, SentioEventTrace, SentioTrace,
};
Expand Down Expand Up @@ -750,6 +750,7 @@ impl Listener {
}
}
}
EvmEvent::Log { .. } => {}
}
}

Expand Down
1 change: 1 addition & 0 deletions client/evm-tracing/src/listeners/sentio_prestate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl<B, C> Listener<B, C>
EvmEvent::Exit { .. } => {
self.context_stack.pop();
}
EvmEvent::Log { .. } => {}
}
}

Expand Down
10 changes: 0 additions & 10 deletions client/evm-tracing/src/types/sentio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,16 +247,6 @@ fn is_zero(n: &u64) -> bool {
return *n == 0;
}

#[test]
fn test_tracer_config_parse() {
let config_string = "{\n \"calls\": {\n \"0x18dd7bca62deee6f633221de26096fdd0c734daa\": [\n 79\n ],\n \"0x3773e1e9deb273fcdf9f80bc88bb387b1e6ce34d\": [\n 2959\n ]\n },\n \"debug\": true,\n \"functions\": {\n \"0x18dd7bca62deee6f633221de26096fdd0c734daa\": [\n {\n \"inputMemory\": false,\n \"inputSize\": 1,\n \"name\": \"_setImplementation\",\n \"outputMemory\": false,\n \"outputSize\": 0,\n \"pc\": 1593,\n \"signatureHash\": \"0x\"\n }\n ]\n },\n \"noInternalCalls\": false,\n \"withInternalCalls\": true\n}";

let v: SentioTracerConfig = serde_json::from_str(&config_string).unwrap();
assert_eq!(v.debug, true);
assert_eq!(v.calls.len(), 2);
assert_eq!(v.functions.len(), 1);
}

#[test]
fn test_h256_to_u256() {
let string = "0f02ba4d7f83e59eaa32eae9c3c4d99b68ce76decade21cdab7ecce8f4aef81a";
Expand Down
36 changes: 26 additions & 10 deletions client/evm-tracing/src/types/single.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use super::serialization::*;
use serde::{Deserialize, Serialize};


use crate::types::sentio::{
SentioCallTrace, SentioPrestateTrace, SentioPrestateTracerConfig, SentioTracerConfig,
};
use crate::types::sentio::{FunctionInfo, SentioCallTrace, SentioPrestateTrace};
use ethereum_types::{H160, H256, U256};
use parity_scale_codec::{Decode, Encode};
use sp_std::{collections::btree_map::BTreeMap, vec::Vec};
Expand All @@ -49,12 +47,8 @@ pub enum TraceType {
CallList,
/// A single block trace. Use in `debug_traceTransactionByNumber` / `traceTransactionByHash`.
Block,
SentioCallList {
tracer_config: Option<SentioTracerConfig>,
},
SentioPrestate {
tracer_config: Option<SentioPrestateTracerConfig>,
},
SentioCallList,
SentioPrestate,
}

/// Single transaction trace.
Expand Down Expand Up @@ -117,11 +111,33 @@ pub struct RawStepLog {
#[serde(rename_all = "camelCase")]
pub struct TraceCallConfig {
pub with_log: bool,

#[serde(default)]
pub functions: BTreeMap<String, Vec<FunctionInfo>>,

#[serde(default)]
pub calls: BTreeMap<String, Vec<u64>>,

#[serde(default)]
pub debug: bool,

#[serde(default)]
pub with_internal_calls: bool,

#[serde(default)]
pub diff_mode: bool,
}

impl Default for TraceCallConfig {
fn default() -> Self {
Self { with_log: false }
Self {
with_log: false,
functions: Default::default(),
calls: Default::default(),
debug: false,
with_internal_calls: false,
diff_mode: false
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions client/rpc-core/debug/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub struct TraceParams {
pub disable_stack: Option<bool>,
/// Javascript tracer (we just check if it's Blockscout tracer string)
pub tracer: Option<String>,
// pub tracer_config: Option<single::TraceCallConfig>,
pub tracer_config: Option<Value>,
pub tracer_config: Option<single::TraceCallConfig>,
// pub tracer_config: Option<Value>,
pub timeout: Option<String>,
}

Expand Down
34 changes: 21 additions & 13 deletions client/rpc/debug/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use ethereum_types::H256;
use fc_rpc::{frontier_backend_client, internal_err};
use fc_storage::StorageOverride;
use fp_rpc::EthereumRuntimeRPCApi;
use jsonrpsee::core::__reexports::serde_json;
use moonbeam_client_evm_tracing::{formatters::ResponseFormatter, types::single};
use moonbeam_rpc_core_types::{RequestBlockId, RequestBlockTag};
use moonbeam_rpc_primitives_debug::{DebugRuntimeApi, TracerInput};
Expand All @@ -42,6 +41,7 @@ use sp_runtime::{
traits::{BlakeTwo256, Block as BlockT, Header as HeaderT, UniqueSaturatedInto},
};
use std::{future::Future, marker::PhantomData, sync::Arc};
use moonbeam_client_evm_tracing::types::sentio;

pub enum RequesterInput {
Call((RequestBlockId, TraceCallParams)),
Expand Down Expand Up @@ -328,18 +328,13 @@ where
} else if tracer == "sentioTracer" {
return Ok((
TracerInput::None,
single::TraceType::SentioCallList {
tracer_config: tracer_config
.map(|x| serde_json::from_value(x).unwrap_or_default()),
},
single::TraceType::SentioCallList, tracer_config,
));
} else if tracer == "sentioPrestateTracer" {
return Ok((
TracerInput::None,
single::TraceType::SentioPrestate {
tracer_config: tracer_config
.map(|x| serde_json::from_value(x).unwrap_or_default()),
},
single::TraceType::SentioPrestate,
tracer_config
));
} else {
None
Expand Down Expand Up @@ -690,9 +685,17 @@ where
)?,
))
}
single::TraceType::SentioCallList { tracer_config } => {
single::TraceType::SentioCallList => {
let tracer_config_or_default = tracer_config.unwrap_or_default();

let mut proxy = moonbeam_client_evm_tracing::listeners::SentioCallList::new(
tracer_config.unwrap_or_default(),
// tracer_config.unwrap_or_default(),
sentio::SentioTracerConfig {
functions: tracer_config_or_default.functions,
calls: tracer_config_or_default.calls,
debug: tracer_config_or_default.debug,
with_internal_calls: tracer_config_or_default.with_internal_calls,
}
);
proxy.using(f)?;
proxy.finish_transaction();
Expand All @@ -704,7 +707,9 @@ where

Ok(Response::Single(res.pop().expect("Trace result is empty.")))
}
single::TraceType::SentioPrestate { tracer_config } => {
single::TraceType::SentioPrestate => {
let tracer_config_or_default = tracer_config.unwrap_or_default();

let new_api = client.runtime_api();
new_api
.initialize_block(parent_block_hash, &header)
Expand All @@ -716,7 +721,10 @@ where
B,
C,
> = moonbeam_client_evm_tracing::listeners::SentioPrestate::new(
tracer_config.unwrap_or_default(),
sentio::SentioPrestateTracerConfig {
diff_mode: tracer_config_or_default.diff_mode,
debug: tracer_config_or_default.debug,
},
header.parent_hash().clone(),
try_ext,
block.header.beneficiary.clone(),
Expand Down
2 changes: 1 addition & 1 deletion push-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cargo build --release

VERSION=v0.39.1-3100-latest
VERSION=v0.40.0-3101-latest

cp target/release/moonbeam .

Expand Down

0 comments on commit 2fd3fd4

Please sign in to comment.