Skip to content

Commit

Permalink
feat: move limits to providers, add da to limit
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Oct 8, 2024
1 parent 81d88be commit 5b44cb9
Show file tree
Hide file tree
Showing 24 changed files with 174 additions and 270 deletions.
11 changes: 6 additions & 5 deletions bin/rundler/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,6 @@ impl TryFrom<&CommonArgs> for SimulationSettings {
Ok(Self::new(
value.min_unstake_delay,
U256::from(value.min_stake_value),
value.max_simulate_handle_ops_gas,
value.max_verification_gas,
value.tracer_timeout.clone(),
))
}
Expand All @@ -419,7 +417,6 @@ impl TryFrom<&CommonArgs> for RundlerApiSettings {
value.priority_fee_mode_value,
)?,
bundle_priority_fee_overhead_percent: value.bundle_priority_fee_overhead_percent,
max_verification_gas: value.max_verification_gas,
})
}
}
Expand Down Expand Up @@ -559,7 +556,9 @@ pub fn construct_providers(
None
} else {
Some(AlloyEntryPointV0_6::new(
chain_spec,
chain_spec.clone(),
args.max_verification_gas,
args.max_simulate_handle_ops_gas,
args.max_simulate_handle_ops_gas,
provider.clone(),
))
Expand All @@ -569,7 +568,9 @@ pub fn construct_providers(
None
} else {
Some(AlloyEntryPointV0_7::new(
chain_spec,
chain_spec.clone(),
args.max_verification_gas,
args.max_simulate_handle_ops_gas,
args.max_simulate_handle_ops_gas,
provider.clone(),
))
Expand Down
21 changes: 7 additions & 14 deletions crates/builder/src/bundle_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ where
.call_handle_ops(
context.to_ops_per_aggregator(),
self.settings.beneficiary,
gas,
Some(gas),
)
.await
.context("should call handle ops with candidate bundle")?;
Expand All @@ -745,7 +745,7 @@ where
}
HandleOpsOut::PostOpRevert => {
warn!("PostOpShortRevert error during gas estimation due to bug in the 0.6 entry point contract. Removing the offending op from the bundle.");
self.process_post_op_revert(context, gas).await?;
self.process_post_op_revert(context).await?;
Ok(None)
}
}
Expand Down Expand Up @@ -869,7 +869,6 @@ where
async fn process_post_op_revert(
&self,
context: &mut ProposalContext<UO>,
gas: u64,
) -> anyhow::Result<()> {
let agg_groups = context.to_ops_per_aggregator();
let mut op_index = 0;
Expand All @@ -880,15 +879,15 @@ where
if agg_group.aggregator.is_zero() {
for op in agg_group.user_ops {
futures.push(Box::pin(
self.check_for_post_op_revert_single_op(op, gas, op_index),
self.check_for_post_op_revert_single_op(op, op_index),
));
op_index += 1;
}
} else {
// For aggregated ops, re-simulate the group
let len = agg_group.user_ops.len();
futures.push(Box::pin(
self.check_for_post_op_revert_agg_ops(agg_group, gas, op_index),
self.check_for_post_op_revert_agg_ops(agg_group, op_index),
));
op_index += len;
}
Expand Down Expand Up @@ -919,12 +918,7 @@ where
Ok(())
}

async fn check_for_post_op_revert_single_op(
&self,
op: UO,
gas: u64,
op_index: usize,
) -> Vec<usize> {
async fn check_for_post_op_revert_single_op(&self, op: UO, op_index: usize) -> Vec<usize> {
let op_hash = self.op_hash(&op);
let bundle = vec![UserOpsPerAggregator {
aggregator: Address::ZERO,
Expand All @@ -933,7 +927,7 @@ where
}];
let ret = self
.entry_point
.call_handle_ops(bundle, self.settings.beneficiary, gas)
.call_handle_ops(bundle, self.settings.beneficiary, None)
.await;
match ret {
Ok(out) => {
Expand All @@ -958,15 +952,14 @@ where
async fn check_for_post_op_revert_agg_ops(
&self,
group: UserOpsPerAggregator<UO>,
gas: u64,
start_index: usize,
) -> Vec<usize> {
let len = group.user_ops.len();
let agg = group.aggregator;
let bundle = vec![group];
let ret = self
.entry_point
.call_handle_ops(bundle, self.settings.beneficiary, gas)
.call_handle_ops(bundle, self.settings.beneficiary, None)
.await;
match ret {
Ok(out) => {
Expand Down
12 changes: 2 additions & 10 deletions crates/builder/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,7 @@ where
i + ep.bundle_builder_index_offset,
self.provider.clone(),
ep_v0_6.clone(),
UnsafeSimulator::new(
self.provider.clone(),
ep_v0_6.clone(),
self.args.sim_settings.clone(),
),
UnsafeSimulator::new(self.provider.clone(), ep_v0_6.clone()),
pk_iter,
)
.await?
Expand Down Expand Up @@ -277,11 +273,7 @@ where
i + ep.bundle_builder_index_offset,
self.provider.clone(),
ep_v0_7.clone(),
UnsafeSimulator::new(
self.provider.clone(),
ep_v0_7.clone(),
self.args.sim_settings.clone(),
),
UnsafeSimulator::new(self.provider.clone(), ep_v0_7.clone()),
pk_iter,
)
.await?
Expand Down
12 changes: 2 additions & 10 deletions crates/pool/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ where
.context("entry point v0.6 not supplied")?;

if unsafe_mode {
let simulator = UnsafeSimulator::new(
self.provider.clone(),
ep.clone(),
pool_config.sim_settings.clone(),
);
let simulator = UnsafeSimulator::new(self.provider.clone(), ep.clone());
Self::create_mempool(
task_spawner,
chain_spec,
Expand Down Expand Up @@ -255,11 +251,7 @@ where
.context("entry point v0.7 not supplied")?;

if unsafe_mode {
let simulator = UnsafeSimulator::new(
self.provider.clone(),
ep.clone(),
pool_config.sim_settings.clone(),
);
let simulator = UnsafeSimulator::new(self.provider.clone(), ep.clone());
Self::create_mempool(
task_spawner,
chain_spec,
Expand Down
88 changes: 62 additions & 26 deletions crates/provider/src/alloy/entry_point/v0_6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ use rundler_contracts::v0_6::{
UserOperation as ContractUserOperation, UserOpsPerAggregator as UserOpsPerAggregatorV0_6,
};
use rundler_types::{
chain::ChainSpec, v0_6::UserOperation, GasFees, UserOpsPerAggregator, ValidationOutput,
ValidationRevert,
chain::ChainSpec, v0_6::UserOperation, GasFees, UserOperation as _, UserOpsPerAggregator,
ValidationOutput, ValidationRevert,
};

use super::DAGasOracle;
Expand All @@ -45,7 +45,10 @@ use crate::{
pub struct EntryPointProvider<AP, T> {
i_entry_point: IEntryPointInstance<T, AP>,
da_gas_oracle: DAGasOracle,
max_verification_gas: u64,
max_simulate_handle_op_gas: u64,
max_aggregation_gas: u64,
chain_spec: ChainSpec,
}

impl<AP, T> EntryPointProvider<AP, T>
Expand All @@ -54,11 +57,20 @@ where
AP: AlloyProvider<T>,
{
/// Create a new `EntryPoint` instance for v0.6
pub fn new(chain_spec: &ChainSpec, max_aggregation_gas: u64, provider: AP) -> Self {
pub fn new(
chain_spec: ChainSpec,
max_verification_gas: u64,
max_simulate_handle_op_gas: u64,
max_aggregation_gas: u64,
provider: AP,
) -> Self {
Self {
i_entry_point: IEntryPointInstance::new(chain_spec.entry_point_address_v0_6, provider),
da_gas_oracle: DAGasOracle::new(chain_spec),
da_gas_oracle: DAGasOracle::new(&chain_spec),
max_verification_gas,
max_simulate_handle_op_gas,
max_aggregation_gas,
chain_spec,
}
}
}
Expand Down Expand Up @@ -133,12 +145,20 @@ where
ops: Vec<Self::UO>,
) -> ProviderResult<Option<Bytes>> {
let aggregator = IAggregator::new(aggregator_address, self.i_entry_point.provider());
let ops_len = ops.len();
let da_gas: u64 = ops
.iter()
.map(|op: &UserOperation| {
op.pre_verification_da_gas_limit(&self.chain_spec, Some(ops_len))
})
.sum::<u128>()
.try_into()
.unwrap_or(u64::MAX);
let ops: Vec<ContractUserOperation> = ops.into_iter().map(Into::into).collect();

// TODO(danc): HERE
let result = aggregator
.aggregateSignatures(ops)
.gas(self.max_aggregation_gas)
.gas(self.max_aggregation_gas.saturating_add(da_gas))
.call()
.await;

Expand All @@ -159,13 +179,16 @@ where
&self,
aggregator_address: Address,
user_op: Self::UO,
gas_cap: u64,
) -> ProviderResult<AggregatorOut> {
let aggregator = IAggregator::new(aggregator_address, self.i_entry_point.provider());
let da_gas: u64 = user_op
.pre_verification_da_gas_limit(&self.chain_spec, Some(1))
.try_into()
.unwrap_or(u64::MAX);

let result = aggregator
.validateUserOpSignature(user_op.into())
.gas(gas_cap)
.gas(self.max_verification_gas.saturating_add(da_gas))
.call()
.await;

Expand Down Expand Up @@ -198,9 +221,15 @@ where
&self,
ops_per_aggregator: Vec<UserOpsPerAggregator<UserOperation>>,
beneficiary: Address,
gas: u64,
gas_limit: Option<u64>,
) -> ProviderResult<HandleOpsOut> {
let tx = get_handle_ops_call(&self.i_entry_point, ops_per_aggregator, beneficiary, gas);
let gas_limit = gas_limit.unwrap_or(self.max_simulate_handle_op_gas);
let tx = get_handle_ops_call(
&self.i_entry_point,
ops_per_aggregator,
beneficiary,
gas_limit,
);
let res = self.i_entry_point.provider().call(&tx).await;

match res {
Expand Down Expand Up @@ -256,12 +285,17 @@ where
&self,
ops_per_aggregator: Vec<UserOpsPerAggregator<UserOperation>>,
beneficiary: Address,
gas: u64,
gas_limit: u64,
gas_fees: GasFees,
) -> TransactionRequest {
get_handle_ops_call(&self.i_entry_point, ops_per_aggregator, beneficiary, gas)
.max_fee_per_gas(gas_fees.max_fee_per_gas)
.max_priority_fee_per_gas(gas_fees.max_priority_fee_per_gas)
get_handle_ops_call(
&self.i_entry_point,
ops_per_aggregator,
beneficiary,
gas_limit,
)
.max_fee_per_gas(gas_fees.max_fee_per_gas)
.max_priority_fee_per_gas(gas_fees.max_priority_fee_per_gas)
}
}

Expand Down Expand Up @@ -311,34 +345,32 @@ where
fn get_tracer_simulate_validation_call(
&self,
user_op: UserOperation,
max_validation_gas: u64,
) -> ProviderResult<(TransactionRequest, StateOverride)> {
let pvg: u64 = user_op
.pre_verification_gas
let da_gas: u64 = user_op
.pre_verification_da_gas_limit(&self.chain_spec, Some(1))
.try_into()
.context("pre verification gas larger than u64")?;
.unwrap_or(u64::MAX);
let call = self
.i_entry_point
.simulateValidation(user_op.into())
.gas(max_validation_gas + pvg)
.gas(self.max_verification_gas.saturating_add(da_gas))
.into_transaction_request();
Ok((call, StateOverride::default()))
}

async fn simulate_validation(
&self,
user_op: UserOperation,
max_validation_gas: u64,
block_id: Option<BlockId>,
) -> ProviderResult<Result<ValidationOutput, ValidationRevert>> {
let pvg: u64 = user_op
.pre_verification_gas
let da_gas: u64 = user_op
.pre_verification_da_gas_limit(&self.chain_spec, Some(1))
.try_into()
.context("pre verification gas larger than u64")?;
.unwrap_or(u64::MAX);
let blockless = self
.i_entry_point
.simulateValidation(user_op.into())
.gas(max_validation_gas + pvg);
.gas(self.max_verification_gas.saturating_add(da_gas));
let call = match block_id {
Some(block_id) => blockless.block(block_id),
None => blockless,
Expand Down Expand Up @@ -397,14 +429,18 @@ where
target: Address,
target_call_data: Bytes,
block_id: BlockId,
gas: u64,
state_override: StateOverride,
) -> ProviderResult<Result<ExecutionResult, ValidationRevert>> {
let da_gas: u64 = op
.pre_verification_da_gas_limit(&self.chain_spec, Some(1))
.try_into()
.unwrap_or(u64::MAX);

let contract_error = self
.i_entry_point
.simulateHandleOp(op.into(), target, target_call_data)
.block(block_id)
.gas(gas)
.gas(self.max_simulate_handle_op_gas.saturating_add(da_gas))
.state(state_override)
.call()
.await
Expand Down
Loading

0 comments on commit 5b44cb9

Please sign in to comment.