From 27a28ae5761a4b6c35a6641558ba1873ba5930df Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 21 Oct 2024 00:05:04 +0800 Subject: [PATCH 1/2] feat(rpc-types-trace/prestate): support disable_{code,storage} Signed-off-by: jsvisa --- crates/rpc-types-trace/src/geth/mux.rs | 2 +- crates/rpc-types-trace/src/geth/pre_state.rs | 44 ++++++++++++++++++-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/crates/rpc-types-trace/src/geth/mux.rs b/crates/rpc-types-trace/src/geth/mux.rs index 1714b32c8c3..c7ffd569a17 100644 --- a/crates/rpc-types-trace/src/geth/mux.rs +++ b/crates/rpc-types-trace/src/geth/mux.rs @@ -60,7 +60,7 @@ mod tests { Some(GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::MuxTracer)); let call_config = CallConfig { only_top_call: Some(true), with_log: Some(true) }; - let prestate_config = PreStateConfig { diff_mode: Some(true) }; + let prestate_config = PreStateConfig { diff_mode: Some(true), ..Default::default() }; opts.tracing_options.tracer_config = MuxConfig(HashMap::from_iter([ (GethDebugBuiltInTracerType::FourByteTracer, None), diff --git a/crates/rpc-types-trace/src/geth/pre_state.rs b/crates/rpc-types-trace/src/geth/pre_state.rs index 4202228b64d..bf4150f019a 100644 --- a/crates/rpc-types-trace/src/geth/pre_state.rs +++ b/crates/rpc-types-trace/src/geth/pre_state.rs @@ -211,6 +211,12 @@ pub struct PreStateConfig { /// storage necessary to execute the transaction. #[serde(default, skip_serializing_if = "Option::is_none")] pub diff_mode: Option, + /// If `disableCode` is set to true, the response frame will not include code. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub disable_code: Option, + /// If `disableStorage` is set to true, the response frame will not include storage. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub disable_storage: Option, } impl PreStateConfig { @@ -225,6 +231,18 @@ impl PreStateConfig { pub fn is_default_mode(&self) -> bool { !self.is_diff_mode() } + + /// Returns true if code is enabled. + #[inline] + pub fn code_enabled(&self) -> bool { + !self.disable_code.unwrap_or_default() + } + + /// Returns true if storage is enabled. + #[inline] + pub fn storage_enabled(&self) -> bool { + !self.disable_storage.unwrap_or_default() + } } #[cfg(test)] @@ -245,7 +263,9 @@ mod tests { opts.tracing_options.tracer = Some(GethDebugTracerType::BuiltInTracer(GethDebugBuiltInTracerType::PreStateTracer)); opts.tracing_options.tracer_config = - serde_json::to_value(PreStateConfig { diff_mode: Some(true) }).unwrap().into(); + serde_json::to_value(PreStateConfig { diff_mode: Some(true), ..Default::default() }) + .unwrap() + .into(); assert_eq!( serde_json::to_string(&opts).unwrap(), @@ -270,9 +290,25 @@ mod tests { #[test] fn test_is_diff_mode() { - assert!(PreStateConfig { diff_mode: Some(true) }.is_diff_mode()); - assert!(!PreStateConfig { diff_mode: Some(false) }.is_diff_mode()); - assert!(!PreStateConfig { diff_mode: None }.is_diff_mode()); + assert!(PreStateConfig { diff_mode: Some(true), ..Default::default() }.is_diff_mode()); + assert!(!PreStateConfig { diff_mode: Some(false), ..Default::default() }.is_diff_mode()); + assert!(!PreStateConfig { diff_mode: None, ..Default::default() }.is_diff_mode()); + } + + #[test] + fn test_disable_code() { + assert!(PreStateConfig { ..Default::default() }.code_enabled()); + assert!(PreStateConfig { disable_code: Some(true), ..Default::default() }.code_enabled()); + assert!(!PreStateConfig { disable_code: Some(false), ..Default::default() }.code_enabled()); + } + #[test] + fn test_disable_storage() { + assert!(PreStateConfig { ..Default::default() }.storage_enabled()); + assert!( + PreStateConfig { disable_storage: Some(true), ..Default::default() }.storage_enabled() + ); + assert!(!PreStateConfig { disable_storage: Some(false), ..Default::default() } + .storage_enabled()); } #[test] From 3d02378973d747a3fe3713bfc1f7eb8b24445815 Mon Sep 17 00:00:00 2001 From: jsvisa Date: Mon, 21 Oct 2024 00:26:12 +0800 Subject: [PATCH 2/2] wrong tests Signed-off-by: jsvisa --- crates/rpc-types-trace/src/geth/pre_state.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/crates/rpc-types-trace/src/geth/pre_state.rs b/crates/rpc-types-trace/src/geth/pre_state.rs index bf4150f019a..a7339944858 100644 --- a/crates/rpc-types-trace/src/geth/pre_state.rs +++ b/crates/rpc-types-trace/src/geth/pre_state.rs @@ -298,17 +298,18 @@ mod tests { #[test] fn test_disable_code() { assert!(PreStateConfig { ..Default::default() }.code_enabled()); - assert!(PreStateConfig { disable_code: Some(true), ..Default::default() }.code_enabled()); - assert!(!PreStateConfig { disable_code: Some(false), ..Default::default() }.code_enabled()); + assert!(PreStateConfig { disable_code: Some(false), ..Default::default() }.code_enabled()); + assert!(!PreStateConfig { disable_code: Some(true), ..Default::default() }.code_enabled()); } #[test] fn test_disable_storage() { assert!(PreStateConfig { ..Default::default() }.storage_enabled()); assert!( - PreStateConfig { disable_storage: Some(true), ..Default::default() }.storage_enabled() + PreStateConfig { disable_storage: Some(false), ..Default::default() }.storage_enabled() + ); + assert!( + !PreStateConfig { disable_storage: Some(true), ..Default::default() }.storage_enabled() ); - assert!(!PreStateConfig { disable_storage: Some(false), ..Default::default() } - .storage_enabled()); } #[test]