Skip to content

Commit

Permalink
feat(tracer): add link to docs and move variables
Browse files Browse the repository at this point in the history
  • Loading branch information
0xfourzerofour committed Jun 18, 2024
1 parent acb7b93 commit f4f8707
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 52 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions bin/rundler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion bin/rundler/src/cli/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 15 additions & 6 deletions bin/rundler/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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<Self, Self::Error> {
if let Err(_) = go_parse_duration::parse_duration(&value.tracer_timeout) {

Check failure on line 376 in bin/rundler/src/cli/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

redundant pattern matching, consider using `is_err()`

error: redundant pattern matching, consider using `is_err()` --> bin/rundler/src/cli/mod.rs:376:16 | 376 | if let Err(_) = go_parse_duration::parse_duration(&value.tracer_timeout) { | -------^^^^^^----------------------------------------------------------- help: try: `if go_parse_duration::parse_duration(&value.tracer_timeout).is_err()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching = note: `-D clippy::redundant-pattern-matching` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::redundant_pattern_matching)]`
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(),
)
))
}
}

Expand Down
2 changes: 1 addition & 1 deletion bin/rundler/src/cli/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion crates/sim/src/simulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
40 changes: 18 additions & 22 deletions crates/sim/src/simulation/v0_6/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<P>, 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,
}
}
Expand Down Expand Up @@ -280,8 +280,6 @@ mod tests {
&self,
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
) -> anyhow::Result<TracerOutput>;
}
}
Expand All @@ -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(),
Expand Down
19 changes: 12 additions & 7 deletions crates/sim/src/simulation/v0_6/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TracerOutput>;
}

Expand All @@ -53,6 +51,8 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static {
pub(crate) struct SimulateValidationTracerImpl<P, E> {
provider: Arc<P>,
entry_point: E,
max_validation_gas: u64,
tracer_timeout: String,
}

/// Runs the bundler's custom tracer on the entry point's `simulateValidation`
Expand All @@ -68,12 +68,10 @@ where
&self,
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
) -> anyhow::Result<TracerOutput> {
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
Expand All @@ -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),
Expand All @@ -98,10 +96,17 @@ where

impl<P, E> SimulateValidationTracerImpl<P, E> {
/// Creates a new instance of the bundler's custom tracer.
pub(crate) fn new(provider: Arc<P>, entry_point: E) -> Self {
pub(crate) fn new(
provider: Arc<P>,
entry_point: E,
max_validation_gas: u64,
tracer_timeout: String,
) -> Self {
Self {
provider,
entry_point,
max_validation_gas,
tracer_timeout,
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions crates/sim/src/simulation/v0_7/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ where
) -> Result<ValidationContext<Self::UO>, ViolationError<SimulationViolation>> {
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())?;
Expand Down Expand Up @@ -494,7 +489,12 @@ where
pub(crate) fn new(provider: Arc<P>, 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,
}
}
Expand Down
19 changes: 12 additions & 7 deletions crates/sim/src/simulation/v0_7/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TracerOutput>;
}

Expand All @@ -135,6 +133,8 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static {
pub(crate) struct SimulateValidationTracerImpl<P, E> {
provider: Arc<P>,
entry_point: E,
max_validation_gas: u64,
tracer_timeout: String,
}

/// Runs the bundler's custom tracer on the entry point's `simulateValidation`
Expand All @@ -150,12 +150,10 @@ where
&self,
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
) -> anyhow::Result<TracerOutput> {
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
Expand All @@ -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),
Expand All @@ -181,10 +179,17 @@ where

impl<P, E> SimulateValidationTracerImpl<P, E> {
/// Creates a new instance of the bundler's custom tracer.
pub(crate) fn new(provider: Arc<P>, entry_point: E) -> Self {
pub(crate) fn new(
provider: Arc<P>,
entry_point: E,
max_validation_gas: u64,
tracer_timeout: String,
) -> Self {
Self {
provider,
entry_point,
max_validation_gas,
tracer_timeout,
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit f4f8707

Please sign in to comment.