Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracer): add timeout of 10s to tracer #730

Merged
merged 4 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bin/rundler/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ pub struct CommonArgs {
)]
min_unstake_delay: u32,

#[arg(
0xfourzerofour marked this conversation as resolved.
Show resolved Hide resolved
long = "tracer_timeout",
name = "tracer_timeout",
env = "TRACER_TIMEOUT",
default_value = "10s",
global = true
)]
tracer_timeout: String,

/// Amount of blocks to search when calling eth_getUserOperationByHash.
/// Defaults from 0 to latest block
#[arg(
Expand Down Expand Up @@ -364,6 +373,7 @@ impl From<&CommonArgs> for SimulationSettings {
value.min_stake_value,
value.max_simulate_handle_ops_gas,
value.max_verification_gas,
value.tracer_timeout.clone(),
0xfourzerofour marked this conversation as resolved.
Show resolved Hide resolved
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions crates/builder/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ where
UnsafeSimulator::new(
Arc::clone(&provider),
ep_v0_6.clone(),
self.args.sim_settings,
self.args.sim_settings.clone(),
),
)
.await?
Expand All @@ -279,7 +279,7 @@ where
simulation::new_v0_6_simulator(
Arc::clone(&provider),
ep_v0_6.clone(),
self.args.sim_settings,
self.args.sim_settings.clone(),
ep.mempool_configs.clone(),
),
)
Expand Down Expand Up @@ -316,7 +316,7 @@ where
UnsafeSimulator::new(
Arc::clone(&provider),
ep_v0_7.clone(),
self.args.sim_settings,
self.args.sim_settings.clone(),
),
)
.await?
Expand All @@ -328,7 +328,7 @@ where
simulation::new_v0_7_simulator(
Arc::clone(&provider),
ep_v0_7.clone(),
self.args.sim_settings,
self.args.sim_settings.clone(),
ep.mempool_configs.clone(),
),
)
Expand Down
18 changes: 12 additions & 6 deletions crates/pool/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,11 @@ impl PoolTask {
);

if unsafe_mode {
let simulator =
UnsafeSimulator::new(Arc::clone(&provider), ep.clone(), pool_config.sim_settings);
let simulator = UnsafeSimulator::new(
Arc::clone(&provider),
ep.clone(),
pool_config.sim_settings.clone(),
);
Self::create_mempool(
chain_spec,
pool_config,
Expand All @@ -210,7 +213,7 @@ impl PoolTask {
let simulator = simulation::new_v0_6_simulator(
Arc::clone(&provider),
ep.clone(),
pool_config.sim_settings,
pool_config.sim_settings.clone(),
pool_config.mempool_channel_configs.clone(),
);
Self::create_mempool(
Expand Down Expand Up @@ -239,8 +242,11 @@ impl PoolTask {
);

if unsafe_mode {
let simulator =
UnsafeSimulator::new(Arc::clone(&provider), ep.clone(), pool_config.sim_settings);
let simulator = UnsafeSimulator::new(
Arc::clone(&provider),
ep.clone(),
pool_config.sim_settings.clone(),
);
Self::create_mempool(
chain_spec,
pool_config,
Expand All @@ -253,7 +259,7 @@ impl PoolTask {
let simulator = simulation::new_v0_7_simulator(
Arc::clone(&provider),
ep.clone(),
pool_config.sim_settings,
pool_config.sim_settings.clone(),
pool_config.mempool_channel_configs.clone(),
);
Self::create_mempool(
Expand Down
4 changes: 2 additions & 2 deletions crates/sim/src/simulation/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ pub(crate) fn infos_from_validation_output(
sender_address: Address,
paymaster_address: Option<Address>,
entry_point_out: &ValidationOutput,
sim_settings: Settings,
sim_settings: &Settings,
) -> EntityInfos {
let mut ei = EntityInfos::default();
ei.set_sender(
Expand Down Expand Up @@ -153,7 +153,7 @@ pub(crate) fn infos_from_validation_output(
ei
}

pub(crate) fn is_staked(info: StakeInfo, sim_settings: Settings) -> bool {
pub(crate) fn is_staked(info: StakeInfo, sim_settings: &Settings) -> bool {
info.stake >= sim_settings.min_stake_value.into()
&& info.unstake_delay_sec >= sim_settings.min_unstake_delay.into()
}
Expand Down
7 changes: 6 additions & 1 deletion crates/sim/src/simulation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub trait Simulator: Send + Sync + 'static {
}

/// Simulation Settings
#[derive(Debug, Copy, Clone)]
#[derive(Debug, Clone)]
pub struct Settings {
/// The minimum amount of time that a staked entity must have configured as
/// their unstake delay on the entry point contract in order to be considered staked.
Expand All @@ -162,6 +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
0xfourzerofour marked this conversation as resolved.
Show resolved Hide resolved
pub tracer_timeout: String,
}

impl Settings {
Expand All @@ -171,12 +173,14 @@ impl Settings {
min_stake_value: u128,
max_simulate_handle_ops_gas: u64,
max_verification_gas: u64,
tracer_timeout: String,
) -> Self {
Self {
min_unstake_delay,
min_stake_value,
max_simulate_handle_ops_gas,
max_verification_gas,
tracer_timeout,
}
}
}
Expand All @@ -192,6 +196,7 @@ impl Default for Settings {
// 550 million gas: currently the defaults for Alchemy eth_call
max_simulate_handle_ops_gas: 550_000_000,
max_verification_gas: 5_000_000,
tracer_timeout: "10s".to_string(),
}
}
}
10 changes: 5 additions & 5 deletions crates/sim/src/simulation/simulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where
SimulatorImpl::new(
provider.clone(),
entry_point.clone(),
ValidationContextProviderV0_6::new(provider, entry_point, sim_settings),
ValidationContextProviderV0_6::new(provider, entry_point, sim_settings.clone()),
sim_settings,
mempool_configs,
)
Expand All @@ -86,7 +86,7 @@ where
SimulatorImpl::new(
provider.clone(),
entry_point.clone(),
ValidationContextProviderV0_7::new(provider, entry_point, sim_settings),
ValidationContextProviderV0_7::new(provider, entry_point, sim_settings.clone()),
sim_settings,
mempool_configs,
)
Expand Down Expand Up @@ -345,7 +345,7 @@ where
}

if let Some(aggregator_info) = entry_point_out.aggregator_info {
if !context::is_staked(aggregator_info.stake_info, self.sim_settings) {
if !context::is_staked(aggregator_info.stake_info, &self.sim_settings) {
// [EREP-040]
violations.push(SimulationViolation::UnstakedAggregator)
}
Expand Down Expand Up @@ -514,7 +514,7 @@ where
sender_info,
..
} = entry_point_out;
let account_is_staked = context::is_staked(sender_info, self.sim_settings);
let account_is_staked = context::is_staked(sender_info, &self.sim_settings);
let ValidationReturnInfo {
pre_op_gas,
valid_after,
Expand Down Expand Up @@ -798,7 +798,7 @@ mod tests {
paymaster_info: StakeInfo::from((U256::default(), U256::default())),
aggregator_info: None,
},
Settings::default(),
&Settings::default(),
),
tracer_out,
entry_point_out: ValidationOutput {
Expand Down
12 changes: 9 additions & 3 deletions crates/sim/src/simulation/v0_6/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ 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)
.trace_simulate_validation(
op.clone(),
block_id,
self.sim_settings.max_verification_gas,
self.sim_settings.tracer_timeout.clone(),
)
.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 @@ -107,7 +112,7 @@ where
sender_address,
paymaster_address,
&entry_point_out,
self.sim_settings,
&self.sim_settings,
);

let associated_addresses = tracer_out.associated_slots_by_address.addresses();
Expand Down Expand Up @@ -276,6 +281,7 @@ mod tests {
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
) -> anyhow::Result<TracerOutput>;
}
}
Expand All @@ -286,7 +292,7 @@ mod tests {

tracer
.expect_trace_simulate_validation()
.returning(|_, _, _| {
.returning(|_, _, _, _| {
let mut tracer_output = get_test_tracer_output();
tracer_output.revert_data = Some(hex::encode(
FailedOp {
Expand Down
3 changes: 3 additions & 0 deletions crates/sim/src/simulation/v0_6/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static {
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
) -> anyhow::Result<TracerOutput>;
}

Expand All @@ -68,6 +69,7 @@ where
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
0xfourzerofour marked this conversation as resolved.
Show resolved Hide resolved
) -> anyhow::Result<TracerOutput> {
let (tx, state_override) = self
.entry_point
Expand All @@ -83,6 +85,7 @@ where
tracer: Some(GethDebugTracerType::JsTracer(
validation_tracer_js().to_string(),
)),
timeout: Some(tracer_timeout),
..Default::default()
},
state_overrides: Some(state_override),
Expand Down
9 changes: 7 additions & 2 deletions crates/sim/src/simulation/v0_7/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ 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)
.trace_simulate_validation(
op.clone(),
block_id,
self.sim_settings.max_verification_gas,
self.sim_settings.tracer_timeout.clone(),
)
.await?;

let call_stack = self.parse_call_stack(tracer_out.calls.clone())?;
Expand Down Expand Up @@ -133,7 +138,7 @@ where
op.sender(),
op.paymaster(),
&entry_point_out,
self.sim_settings,
&self.sim_settings,
);

let mut tracer_out = self.parse_tracer_out(&op, tracer_out)?;
Expand Down
3 changes: 3 additions & 0 deletions crates/sim/src/simulation/v0_7/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub(super) trait SimulateValidationTracer: Send + Sync + 'static {
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
) -> anyhow::Result<TracerOutput>;
}

Expand All @@ -150,6 +151,7 @@ where
op: UserOperation,
block_id: BlockId,
max_validation_gas: u64,
tracer_timeout: String,
) -> anyhow::Result<TracerOutput> {
let (tx, state_override) = self
.entry_point
Expand All @@ -165,6 +167,7 @@ where
tracer: Some(GethDebugTracerType::JsTracer(
validation_tracer_js().to_string(),
)),
timeout: Some(tracer_timeout),
..Default::default()
},
state_overrides: Some(state_override),
Expand Down
Loading