From f4f87072a7a72baf65699cf192e9994c118e97c0 Mon Sep 17 00:00:00 2001 From: 0xfourzerofour Date: Tue, 18 Jun 2024 12:56:15 -0400 Subject: [PATCH] feat(tracer): add link to docs and move variables --- Cargo.lock | 7 ++++ bin/rundler/Cargo.toml | 1 + bin/rundler/src/cli/builder.rs | 2 +- bin/rundler/src/cli/mod.rs | 21 ++++++++---- bin/rundler/src/cli/pool.rs | 2 +- crates/sim/src/simulation/mod.rs | 3 +- crates/sim/src/simulation/v0_6/context.rs | 40 ++++++++++------------- crates/sim/src/simulation/v0_6/tracer.rs | 19 +++++++---- crates/sim/src/simulation/v0_7/context.rs | 14 ++++---- crates/sim/src/simulation/v0_7/tracer.rs | 19 +++++++---- docs/cli.md | 2 ++ 11 files changed, 78 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0d67859fc..041db3126 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2016,6 +2016,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "go-parse-duration" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "558b88954871f5e5b2af0e62e2e176c8bde7a6c2c4ed41b13d138d96da2e2cbd" + [[package]] name = "group" version = "0.13.0" @@ -4027,6 +4033,7 @@ dependencies = [ "config", "dotenv", "ethers", + "go-parse-duration", "itertools 0.12.1", "metrics", "metrics-exporter-prometheus", diff --git a/bin/rundler/Cargo.toml b/bin/rundler/Cargo.toml index 08e0e4476..5fc29f88f 100644 --- a/bin/rundler/Cargo.toml +++ b/bin/rundler/Cargo.toml @@ -27,6 +27,7 @@ dotenv = "0.15.0" ethers.workspace = true itertools = "0.12.1" metrics = "0.22.1" +go-parse-duration = "0.1" metrics-exporter-prometheus = { version = "0.13.1", default-features = false, features = ["http-listener"] } metrics-process = "1.2.1" metrics-util = "0.16.2" diff --git a/bin/rundler/src/cli/builder.rs b/bin/rundler/src/cli/builder.rs index 2a5d73c0d..0cd5bed81 100644 --- a/bin/rundler/src/cli/builder.rs +++ b/bin/rundler/src/cli/builder.rs @@ -286,7 +286,7 @@ impl BuilderArgs { priority_fee_mode, sender_args, eth_poll_interval: Duration::from_millis(common.eth_poll_interval_millis), - sim_settings: common.into(), + sim_settings: common.try_into()?, max_blocks_to_wait_for_mine: self.max_blocks_to_wait_for_mine, replacement_fee_percent_increase: self.replacement_fee_percent_increase, max_fee_increases: self.max_fee_increases, diff --git a/bin/rundler/src/cli/mod.rs b/bin/rundler/src/cli/mod.rs index 3d3af5714..ff62abbd9 100644 --- a/bin/rundler/src/cli/mod.rs +++ b/bin/rundler/src/cli/mod.rs @@ -11,7 +11,7 @@ // You should have received a copy of the GNU General Public License along with Rundler. // If not, see https://www.gnu.org/licenses/. -use anyhow::Context; +use anyhow::{bail, Context}; use clap::{builder::PossibleValuesParser, Args, Parser, Subcommand}; mod builder; @@ -163,11 +163,14 @@ pub struct CommonArgs { )] min_unstake_delay: u32, + /// String representation of timeount in a format that is parsable by the + /// `ParseDuration` function on the ethereum node. + /// Docs: https://pkg.go.dev/time#ParseDuration #[arg( long = "tracer_timeout", name = "tracer_timeout", env = "TRACER_TIMEOUT", - default_value = "10s", + default_value = "15s", global = true )] tracer_timeout: String, @@ -366,15 +369,21 @@ impl TryFrom<&CommonArgs> for PrecheckSettings { } } -impl From<&CommonArgs> for SimulationSettings { - fn from(value: &CommonArgs) -> Self { - Self::new( +impl TryFrom<&CommonArgs> for SimulationSettings { + type Error = anyhow::Error; + + fn try_from(value: &CommonArgs) -> Result { + if let Err(_) = go_parse_duration::parse_duration(&value.tracer_timeout) { + bail!("Invalid value for tracer_timeout, must be parsable by the ParseDuration function. See docs https://pkg.go.dev/time#ParseDuration") + } + + Ok(Self::new( value.min_unstake_delay, value.min_stake_value, value.max_simulate_handle_ops_gas, value.max_verification_gas, value.tracer_timeout.clone(), - ) + )) } } diff --git a/bin/rundler/src/cli/pool.rs b/bin/rundler/src/cli/pool.rs index 0f1728c08..53c6cf992 100644 --- a/bin/rundler/src/cli/pool.rs +++ b/bin/rundler/src/cli/pool.rs @@ -195,7 +195,7 @@ impl PoolArgs { blocklist: blocklist.clone(), allowlist: allowlist.clone(), precheck_settings: common.try_into()?, - sim_settings: common.into(), + sim_settings: common.try_into()?, throttled_entity_mempool_count: self.throttled_entity_mempool_count, throttled_entity_live_blocks: self.throttled_entity_live_blocks, paymaster_tracking_enabled: self.paymaster_tracking_enabled, diff --git a/crates/sim/src/simulation/mod.rs b/crates/sim/src/simulation/mod.rs index 58af5357e..eb035d488 100644 --- a/crates/sim/src/simulation/mod.rs +++ b/crates/sim/src/simulation/mod.rs @@ -162,7 +162,8 @@ pub struct Settings { pub max_simulate_handle_ops_gas: u64, /// The maximum amount of verification gas that can be used during the simulation call pub max_verification_gas: u64, - /// The max duration of the custom javascript tracer + /// The max duration of the custom javascript tracer. Must be in a format parseable by the + /// ParseDuration function on an ethereum node. See Docs: https://pkg.go.dev/time#ParseDuration pub tracer_timeout: String, } diff --git a/crates/sim/src/simulation/v0_6/context.rs b/crates/sim/src/simulation/v0_6/context.rs index 25448e7a4..3cd621671 100644 --- a/crates/sim/src/simulation/v0_6/context.rs +++ b/crates/sim/src/simulation/v0_6/context.rs @@ -55,12 +55,7 @@ where let paymaster_address = op.paymaster(); let tracer_out = self .simulate_validation_tracer - .trace_simulate_validation( - op.clone(), - block_id, - self.sim_settings.max_verification_gas, - self.sim_settings.tracer_timeout.clone(), - ) + .trace_simulate_validation(op.clone(), block_id) .await?; let num_phases = tracer_out.phases.len() as u32; // Check if there are too many phases here, then check too few at the @@ -186,7 +181,12 @@ where /// Creates a new `ValidationContextProvider` for entry point v0.6 with the given provider and entry point. pub(crate) fn new(provider: Arc

, entry_point: E, sim_settings: SimulationSettings) -> Self { Self { - simulate_validation_tracer: SimulateValidationTracerImpl::new(provider, entry_point), + simulate_validation_tracer: SimulateValidationTracerImpl::new( + provider, + entry_point, + sim_settings.max_verification_gas, + sim_settings.tracer_timeout.clone(), + ), sim_settings, } } @@ -280,8 +280,6 @@ mod tests { &self, op: UserOperation, block_id: BlockId, - max_validation_gas: u64, - tracer_timeout: String, ) -> anyhow::Result; } } @@ -290,19 +288,17 @@ mod tests { async fn test_create_context_two_phases_unintended_revert() { let mut tracer = MockTracer::new(); - tracer - .expect_trace_simulate_validation() - .returning(|_, _, _, _| { - let mut tracer_output = get_test_tracer_output(); - tracer_output.revert_data = Some(hex::encode( - FailedOp { - op_index: U256::from(100), - reason: "AA23 reverted (or OOG)".to_string(), - } - .encode(), - )); - Ok(tracer_output) - }); + tracer.expect_trace_simulate_validation().returning(|_, _| { + let mut tracer_output = get_test_tracer_output(); + tracer_output.revert_data = Some(hex::encode( + FailedOp { + op_index: U256::from(100), + reason: "AA23 reverted (or OOG)".to_string(), + } + .encode(), + )); + Ok(tracer_output) + }); let user_operation = UserOperation { sender: Address::from_str("b856dbd4fa1a79a46d426f537455e7d3e79ab7c4").unwrap(), diff --git a/crates/sim/src/simulation/v0_6/tracer.rs b/crates/sim/src/simulation/v0_6/tracer.rs index c000f7965..b5f8aad2f 100644 --- a/crates/sim/src/simulation/v0_6/tracer.rs +++ b/crates/sim/src/simulation/v0_6/tracer.rs @@ -43,8 +43,6 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static { &self, op: UserOperation, block_id: BlockId, - max_validation_gas: u64, - tracer_timeout: String, ) -> anyhow::Result; } @@ -53,6 +51,8 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static { pub(crate) struct SimulateValidationTracerImpl { provider: Arc

, entry_point: E, + max_validation_gas: u64, + tracer_timeout: String, } /// Runs the bundler's custom tracer on the entry point's `simulateValidation` @@ -68,12 +68,10 @@ where &self, op: UserOperation, block_id: BlockId, - max_validation_gas: u64, - tracer_timeout: String, ) -> anyhow::Result { let (tx, state_override) = self .entry_point - .get_tracer_simulate_validation_call(op, max_validation_gas); + .get_tracer_simulate_validation_call(op, self.max_validation_gas); TracerOutput::try_from( self.provider @@ -85,7 +83,7 @@ where tracer: Some(GethDebugTracerType::JsTracer( validation_tracer_js().to_string(), )), - timeout: Some(tracer_timeout), + timeout: Some(self.tracer_timeout.clone()), ..Default::default() }, state_overrides: Some(state_override), @@ -98,10 +96,17 @@ where impl SimulateValidationTracerImpl { /// Creates a new instance of the bundler's custom tracer. - pub(crate) fn new(provider: Arc

, entry_point: E) -> Self { + pub(crate) fn new( + provider: Arc

, + entry_point: E, + max_validation_gas: u64, + tracer_timeout: String, + ) -> Self { Self { provider, entry_point, + max_validation_gas, + tracer_timeout, } } } diff --git a/crates/sim/src/simulation/v0_7/context.rs b/crates/sim/src/simulation/v0_7/context.rs index 064cd3669..348f843c2 100644 --- a/crates/sim/src/simulation/v0_7/context.rs +++ b/crates/sim/src/simulation/v0_7/context.rs @@ -101,12 +101,7 @@ where ) -> Result, ViolationError> { let tracer_out = self .simulate_validation_tracer - .trace_simulate_validation( - op.clone(), - block_id, - self.sim_settings.max_verification_gas, - self.sim_settings.tracer_timeout.clone(), - ) + .trace_simulate_validation(op.clone(), block_id) .await?; let call_stack = self.parse_call_stack(tracer_out.calls.clone())?; @@ -494,7 +489,12 @@ where pub(crate) fn new(provider: Arc

, entry_point: E, sim_settings: SimulationSettings) -> Self { Self { entry_point_address: entry_point.address(), - simulate_validation_tracer: SimulateValidationTracerImpl::new(provider, entry_point), + simulate_validation_tracer: SimulateValidationTracerImpl::new( + provider, + entry_point, + sim_settings.max_verification_gas, + sim_settings.tracer_timeout.clone(), + ), sim_settings, } } diff --git a/crates/sim/src/simulation/v0_7/tracer.rs b/crates/sim/src/simulation/v0_7/tracer.rs index 5a036c1b9..2eb10545c 100644 --- a/crates/sim/src/simulation/v0_7/tracer.rs +++ b/crates/sim/src/simulation/v0_7/tracer.rs @@ -125,8 +125,6 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static { &self, op: UserOperation, block_id: BlockId, - max_validation_gas: u64, - tracer_timeout: String, ) -> anyhow::Result; } @@ -135,6 +133,8 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static { pub(crate) struct SimulateValidationTracerImpl { provider: Arc

, entry_point: E, + max_validation_gas: u64, + tracer_timeout: String, } /// Runs the bundler's custom tracer on the entry point's `simulateValidation` @@ -150,12 +150,10 @@ where &self, op: UserOperation, block_id: BlockId, - max_validation_gas: u64, - tracer_timeout: String, ) -> anyhow::Result { let (tx, state_override) = self .entry_point - .get_tracer_simulate_validation_call(op, max_validation_gas); + .get_tracer_simulate_validation_call(op, self.max_validation_gas); let out = self .provider @@ -167,7 +165,7 @@ where tracer: Some(GethDebugTracerType::JsTracer( validation_tracer_js().to_string(), )), - timeout: Some(tracer_timeout), + timeout: Some(self.tracer_timeout.clone()), ..Default::default() }, state_overrides: Some(state_override), @@ -181,10 +179,17 @@ where impl SimulateValidationTracerImpl { /// Creates a new instance of the bundler's custom tracer. - pub(crate) fn new(provider: Arc

, entry_point: E) -> Self { + pub(crate) fn new( + provider: Arc

, + entry_point: E, + max_validation_gas: u64, + tracer_timeout: String, + ) -> Self { Self { provider, entry_point, + max_validation_gas, + tracer_timeout, } } } diff --git a/docs/cli.md b/docs/cli.md index 6249d3b02..3ac1402b7 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -73,6 +73,8 @@ See [chain spec](./architecture/chain_spec.md) for a detailed description of cha - env: *DISABLE_ENTRY_POINT_V0_7* - `--num_builders_v0_7`: The number of bundle builders to run on entry point v0.7 (default: `1`) - env: *NUM_BUILDERS_V0_7* +- `--tracer_timeout`: The timeout used for custom javascript tracers, the string must be in a valid parseable format that can be used in the `ParseDuration` function on an ethereum node. See Docs [Here](https://pkg.go.dev/time#ParseDuration). (default: `15s`) + - env: *TRACER_TIMEOUT* ## Metrics Options