Skip to content

Commit

Permalink
refactor: refactor da gas provider/oracle interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Oct 18, 2024
1 parent 164a501 commit d3dc80c
Show file tree
Hide file tree
Showing 26 changed files with 679 additions and 644 deletions.
12 changes: 2 additions & 10 deletions bin/rundler/src/cli/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use rundler_types::{chain::ChainSpec, EntryPointVersion};
use rundler_utils::emit::{self, WithEntryPoint, EVENT_CHANNEL_CAPACITY};
use tokio::sync::broadcast;

use super::{json::get_json_config, CommonArgs, RundlerProviders};
use super::{json::get_json_config, CommonArgs};

const REQUEST_CHANNEL_CAPACITY: usize = 1024;

Expand Down Expand Up @@ -459,20 +459,12 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
)
.await?;

let RundlerProviders {
provider,
ep_v0_6,
ep_v0_7,
} = super::construct_providers(&common_args, &chain_spec)?;

BuilderTask::new(
task_args,
event_sender,
LocalBuilderBuilder::new(REQUEST_CHANNEL_CAPACITY),
pool,
provider,
ep_v0_6,
ep_v0_7,
super::construct_providers(&common_args, &chain_spec)?,
)
.spawn(task_spawner)
.await?;
Expand Down
49 changes: 40 additions & 9 deletions bin/rundler/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ use pool::PoolCliArgs;
use reth_tasks::TaskManager;
use rpc::RpcCliArgs;
use rundler_provider::{
AlloyEntryPointV0_6, AlloyEntryPointV0_7, AlloyEvmProvider, EntryPointProvider, EvmProvider,
AlloyEntryPointV0_6, AlloyEntryPointV0_7, AlloyEvmProvider, DAGasOracleSync,
EntryPointProvider, EvmProvider, Providers,
};
use rundler_rpc::{EthApiSettings, RundlerApiSettings};
use rundler_sim::{
Expand Down Expand Up @@ -540,25 +541,52 @@ pub struct Cli {
logs: LogsArgs,
}

pub struct RundlerProviders<P, EP06, EP07> {
#[derive(Clone)]
pub struct RundlerProviders<P, EP06, EP07, D> {
provider: P,
ep_v0_6: Option<EP06>,
ep_v0_7: Option<EP07>,
da_gas_oracle_sync: Option<D>,
}

impl<P, EP06, EP07, D> Providers for RundlerProviders<P, EP06, EP07, D>
where
P: EvmProvider + Clone,
EP06: EntryPointProvider<UserOperationV0_6> + Clone,
EP07: EntryPointProvider<UserOperationV0_7> + Clone,
D: DAGasOracleSync + Clone,
{
type Evm = P;
type EntryPointV0_6 = EP06;
type EntryPointV0_7 = EP07;
type DAGasOracleSync = D;

fn evm(&self) -> &Self::Evm {
&self.provider
}

fn ep_v0_6(&self) -> &Option<Self::EntryPointV0_6> {
&self.ep_v0_6
}

fn ep_v0_7(&self) -> &Option<Self::EntryPointV0_7> {
&self.ep_v0_7
}

fn da_gas_oracle_sync(&self) -> &Option<Self::DAGasOracleSync> {
&self.da_gas_oracle_sync
}
}

pub fn construct_providers(
args: &CommonArgs,
chain_spec: &ChainSpec,
) -> anyhow::Result<
RundlerProviders<
impl EvmProvider + Clone + 'static,
impl EntryPointProvider<UserOperationV0_6> + Clone + 'static,
impl EntryPointProvider<UserOperationV0_7> + Clone + 'static,
>,
> {
) -> anyhow::Result<impl Providers> {
let provider = Arc::new(rundler_provider::new_alloy_provider(
args.node_http.as_ref().context("must provide node_http")?,
)?);
let (da_gas_oracle, da_gas_oracle_sync) =
rundler_provider::new_alloy_da_gas_oracle(chain_spec, provider.clone());

let ep_v0_6 = if args.disable_entry_point_v0_6 {
None
Expand All @@ -569,6 +597,7 @@ pub fn construct_providers(
args.max_simulate_handle_ops_gas,
args.max_simulate_handle_ops_gas,
provider.clone(),
da_gas_oracle.clone(),
))
};

Expand All @@ -581,13 +610,15 @@ pub fn construct_providers(
args.max_simulate_handle_ops_gas,
args.max_simulate_handle_ops_gas,
provider.clone(),
da_gas_oracle.clone(),
))
};

Ok(RundlerProviders {
provider: AlloyEvmProvider::new(provider),
ep_v0_6,
ep_v0_7,
da_gas_oracle_sync,
})
}

Expand Down
28 changes: 6 additions & 22 deletions bin/rundler/src/cli/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use rundler_utils::emit::{self, WithEntryPoint, EVENT_CHANNEL_CAPACITY};
use tokio::sync::broadcast;

use self::events::Event;
use super::RundlerProviders;
use crate::cli::{
builder::{self, BuilderArgs},
pool::PoolArgs,
Expand Down Expand Up @@ -110,19 +109,13 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
let builder_builder = LocalBuilderBuilder::new(REQUEST_CHANNEL_CAPACITY);
let builder_handle = builder_builder.get_handle();

let RundlerProviders {
provider,
ep_v0_6,
ep_v0_7,
} = super::construct_providers(&common_args, &chain_spec)?;
let providers = super::construct_providers(&common_args, &chain_spec)?;

PoolTask::new(
pool_task_args,
op_pool_event_sender,
pool_builder,
provider.clone(),
ep_v0_6.clone(),
ep_v0_7.clone(),
providers.clone(),
)
.spawn(task_spawner.clone())
.await?;
Expand All @@ -132,23 +125,14 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
builder_event_sender,
builder_builder,
pool_handle.clone(),
provider.clone(),
ep_v0_6.clone(),
ep_v0_7.clone(),
providers.clone(),
)
.spawn(task_spawner.clone())
.await?;

RpcTask::new(
rpc_task_args,
pool_handle,
builder_handle,
provider,
ep_v0_6,
ep_v0_7,
)
.spawn(task_spawner)
.await?;
RpcTask::new(rpc_task_args, pool_handle, builder_handle, providers)
.spawn(task_spawner)
.await?;

Ok(())
}
12 changes: 2 additions & 10 deletions bin/rundler/src/cli/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rundler_types::{chain::ChainSpec, EntryPointVersion};
use rundler_utils::emit::{self, EVENT_CHANNEL_CAPACITY};
use tokio::sync::broadcast;

use super::{CommonArgs, RundlerProviders};
use super::CommonArgs;
use crate::cli::json::get_json_config;

const REQUEST_CHANNEL_CAPACITY: usize = 1024;
Expand Down Expand Up @@ -301,19 +301,11 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
Box::pin(emit::receive_and_log_events_with_filter(event_rx, |_| true)),
);

let RundlerProviders {
provider,
ep_v0_6,
ep_v0_7,
} = super::construct_providers(&common_args, &chain_spec)?;

PoolTask::new(
task_args,
event_sender,
LocalPoolBuilder::new(REQUEST_CHANNEL_CAPACITY, BLOCK_CHANNEL_CAPACITY),
provider,
ep_v0_6,
ep_v0_7,
super::construct_providers(&common_args, &chain_spec)?,
)
.spawn(task_spawner)
.await?;
Expand Down
20 changes: 9 additions & 11 deletions bin/rundler/src/cli/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use rundler_sim::{EstimationSettings, PrecheckSettings};
use rundler_task::{server::connect_with_retries_shutdown, TaskSpawnerExt};
use rundler_types::chain::ChainSpec;

use super::{CommonArgs, RundlerProviders};
use super::CommonArgs;

/// CLI options for the RPC server
#[derive(Args, Debug)]
Expand Down Expand Up @@ -79,7 +79,6 @@ pub struct RpcArgs {
impl RpcArgs {
/// Convert the CLI arguments into the arguments for the RPC server combining
/// common and rpc specific arguments.
#[allow(clippy::too_many_arguments)]
pub fn to_args(
&self,
chain_spec: ChainSpec,
Expand Down Expand Up @@ -176,15 +175,14 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
)
.await?;

let RundlerProviders {
provider,
ep_v0_6,
ep_v0_7,
} = super::construct_providers(&common_args, &chain_spec)?;

RpcTask::new(task_args, pool, builder, provider, ep_v0_6, ep_v0_7)
.spawn(task_spawner)
.await?;
RpcTask::new(
task_args,
pool,
builder,
super::construct_providers(&common_args, &chain_spec)?,
)
.spawn(task_spawner)
.await?;

Ok(())
}
Loading

0 comments on commit d3dc80c

Please sign in to comment.