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

refactor: refactor da gas provider/oracle interfaces #861

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions bin/rundler/src/cli/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
provider,
ep_v0_6,
ep_v0_7,
da_gas_oracle_sync,
} = super::construct_providers(&common_args, &chain_spec)?;

BuilderTask::new(
Expand All @@ -473,6 +474,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
provider,
ep_v0_6,
ep_v0_7,
da_gas_oracle_sync,
)
.spawn(task_spawner)
.await?;
Expand Down
9 changes: 8 additions & 1 deletion 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,
};
use rundler_rpc::{EthApiSettings, RundlerApiSettings};
use rundler_sim::{
Expand Down Expand Up @@ -544,6 +545,7 @@ pub struct RundlerProviders<P, EP06, EP07> {
provider: P,
ep_v0_6: Option<EP06>,
ep_v0_7: Option<EP07>,
da_gas_oracle_sync: Option<Arc<dyn DAGasOracleSync>>,
}

pub fn construct_providers(
Expand All @@ -559,6 +561,8 @@ pub fn construct_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 +573,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 +586,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
3 changes: 3 additions & 0 deletions bin/rundler/src/cli/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
provider,
ep_v0_6,
ep_v0_7,
da_gas_oracle_sync,
} = super::construct_providers(&common_args, &chain_spec)?;

PoolTask::new(
Expand All @@ -123,6 +124,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
provider.clone(),
ep_v0_6.clone(),
ep_v0_7.clone(),
da_gas_oracle_sync.clone(),
)
.spawn(task_spawner.clone())
.await?;
Expand All @@ -135,6 +137,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
provider.clone(),
ep_v0_6.clone(),
ep_v0_7.clone(),
da_gas_oracle_sync,
)
.spawn(task_spawner.clone())
.await?;
Expand Down
2 changes: 2 additions & 0 deletions bin/rundler/src/cli/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
provider,
ep_v0_6,
ep_v0_7,
da_gas_oracle_sync,
} = super::construct_providers(&common_args, &chain_spec)?;

PoolTask::new(
Expand All @@ -314,6 +315,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
provider,
ep_v0_6,
ep_v0_7,
da_gas_oracle_sync,
)
.spawn(task_spawner)
.await?;
Expand Down
1 change: 1 addition & 0 deletions bin/rundler/src/cli/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub async fn spawn_tasks<T: TaskSpawnerExt + 'static>(
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)
Expand Down
23 changes: 17 additions & 6 deletions crates/builder/src/bundle_proposer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use linked_hash_map::LinkedHashMap;
#[cfg(test)]
use mockall::automock;
use rundler_provider::{
BundleHandler, DAGasProvider, EntryPoint, EvmProvider, HandleOpsOut, SignatureAggregator,
BundleHandler, DAGasOracleSync, DAGasProvider, EntryPoint, EvmProvider, HandleOpsOut,
SignatureAggregator,
};
use rundler_sim::{
ExpectedStorage, FeeEstimator, PriorityFeeMode, SimulationError, SimulationResult, Simulator,
Expand Down Expand Up @@ -134,7 +135,6 @@ pub(crate) enum BundleProposerError {
Other(#[from] anyhow::Error),
}

#[derive(Debug)]
pub(crate) struct BundleProposerImpl<UO, S, E, P, M, F> {
builder_index: u64,
pool: M,
Expand All @@ -145,6 +145,7 @@ pub(crate) struct BundleProposerImpl<UO, S, E, P, M, F> {
fee_estimator: F,
event_sender: broadcast::Sender<WithEntryPoint<BuilderEvent>>,
condition_not_met_notified: bool,
da_gas_oracle: Option<Arc<dyn DAGasOracleSync>>,
_uo_type: PhantomData<UO>,
}

Expand Down Expand Up @@ -216,8 +217,11 @@ where
.filter_map(|op| op.uo.paymaster())
.collect::<Vec<Address>>();

let da_block_data = if self.settings.da_gas_tracking_enabled {
match self.entry_point.block_data(block_hash.into()).await {
let da_block_data = if self.settings.da_gas_tracking_enabled && self.da_gas_oracle.is_some()
{
let da_gas_oracle = self.da_gas_oracle.as_ref().unwrap();

match da_gas_oracle.block_data(block_hash.into()).await {
Ok(block_data) => Some(block_data),
Err(e) => {
error!("Failed to get block data for block hash {block_hash:?}, falling back to async da gas calculations: {e:?}");
Expand Down Expand Up @@ -342,6 +346,7 @@ where
entry_point: E,
provider: P,
fee_estimator: F,
da_gas_oracle: Option<Arc<dyn DAGasOracleSync>>,
settings: Settings,
event_sender: broadcast::Sender<WithEntryPoint<BuilderEvent>>,
) -> Self {
Expand All @@ -352,6 +357,7 @@ where
entry_point,
provider,
fee_estimator,
da_gas_oracle,
settings,
event_sender,
condition_not_met_notified: false,
Expand Down Expand Up @@ -398,9 +404,13 @@ where
return Some(op);
}

let required_da_gas = if self.settings.da_gas_tracking_enabled && da_block_data.is_some() {
let required_da_gas = if self.settings.da_gas_tracking_enabled
&& da_block_data.is_some()
&& self.da_gas_oracle.is_some()
{
let da_gas_oracle = self.da_gas_oracle.as_ref().unwrap();
let da_block_data = da_block_data.unwrap();
self.entry_point.calc_da_gas_sync(
da_gas_oracle.calc_da_gas_sync(
&op.da_gas_data,
da_block_data,
required_op_fees.max_fee_per_gas,
Expand Down Expand Up @@ -2415,6 +2425,7 @@ mod tests {
entry_point,
provider,
fee_estimator,
None,
Settings {
chain_spec: ChainSpec::default(),
max_bundle_size,
Expand Down
10 changes: 7 additions & 3 deletions crates/builder/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
// You should have received a copy of the GNU General Public License along with Rundler.
// If not, see https://www.gnu.org/licenses/.

use std::{collections::HashMap, net::SocketAddr, time::Duration};
use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration};

use alloy_primitives::{Address, B256};
use anyhow::Context;
use rundler_provider::{EntryPointProvider, EvmProvider};
use rundler_provider::{DAGasOracleSync, EntryPointProvider, EvmProvider};
use rundler_sim::{
gas::{self, FeeEstimatorImpl},
simulation::{self, UnsafeSimulator},
Expand Down Expand Up @@ -107,7 +107,6 @@ pub struct EntryPointBuilderSettings {
}

/// Builder task
#[derive(Debug)]
pub struct BuilderTask<P, PR, E06, E07> {
args: Args,
event_sender: broadcast::Sender<WithEntryPoint<BuilderEvent>>,
Expand All @@ -116,10 +115,12 @@ pub struct BuilderTask<P, PR, E06, E07> {
provider: PR,
ep_06: Option<E06>,
ep_07: Option<E07>,
da_gas_oracle: Option<Arc<dyn DAGasOracleSync>>,
}

impl<P, PR, E06, E07> BuilderTask<P, PR, E06, E07> {
/// Create a new builder task
#[allow(clippy::too_many_arguments)]
pub fn new(
args: Args,
event_sender: broadcast::Sender<WithEntryPoint<BuilderEvent>>,
Expand All @@ -128,6 +129,7 @@ impl<P, PR, E06, E07> BuilderTask<P, PR, E06, E07> {
provider: PR,
ep_06: Option<E06>,
ep_07: Option<E07>,
da_gas_oracle: Option<Arc<dyn DAGasOracleSync>>,
) -> Self {
Self {
args,
Expand All @@ -137,6 +139,7 @@ impl<P, PR, E06, E07> BuilderTask<P, PR, E06, E07> {
provider,
ep_06,
ep_07,
da_gas_oracle,
}
}
}
Expand Down Expand Up @@ -404,6 +407,7 @@ where
entry_point.clone(),
provider.clone(),
fee_estimator,
self.da_gas_oracle.clone(),
proposer_settings,
self.event_sender.clone(),
);
Expand Down
35 changes: 14 additions & 21 deletions crates/pool/src/mempool/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use anyhow::Context;
use metrics::{Gauge, Histogram};
use metrics_derive::Metrics;
use parking_lot::RwLock;
use rundler_provider::DAGasProvider;
use rundler_provider::DAGasOracleSync;
use rundler_types::{
chain::ChainSpec,
da::DAGasBlockData,
Expand Down Expand Up @@ -67,8 +67,8 @@ impl From<PoolConfig> for PoolInnerConfig {
pub(crate) struct PoolInner<D> {
/// Pool settings
config: PoolInnerConfig,
/// DA Gas Provider
da_gas_provider: D,
/// DA Gas Oracle
da_gas_oracle: Option<D>,
/// Operations by hash
by_hash: HashMap<B256, Arc<OrderedPoolOperation>>,
/// Operations by operation ID
Expand Down Expand Up @@ -104,17 +104,17 @@ pub(crate) struct PoolInner<D> {

impl<D> PoolInner<D>
where
D: DAGasProvider,
D: DAGasOracleSync,
{
pub(crate) fn new(
config: PoolInnerConfig,
da_gas_provider: D,
da_gas_oracle: Option<D>,
event_sender: broadcast::Sender<WithEntryPoint<PoolEvent>>,
) -> Self {
let entry_point = config.entry_point.to_string();
Self {
config,
da_gas_provider,
da_gas_oracle,
by_hash: HashMap::new(),
by_id: HashMap::new(),
best: BTreeSet::new(),
Expand Down Expand Up @@ -259,9 +259,11 @@ where
continue;
}

if self.config.da_gas_tracking_enabled && block_da_data.is_some() {
if self.da_gas_oracle.is_some() && block_da_data.is_some() {
let da_gas_oracle = self.da_gas_oracle.as_ref().unwrap();
let block_da_data = block_da_data.unwrap();
let required_da_gas = self.da_gas_provider.calc_da_gas_sync(

let required_da_gas = da_gas_oracle.calc_da_gas_sync(
&op.po.da_gas_data,
block_da_data,
candidate_gas_price,
Expand Down Expand Up @@ -764,7 +766,6 @@ struct PoolMetrics {
#[cfg(test)]
mod tests {
use alloy_primitives::U256;
use rundler_provider::MockEntryPointV0_6;
use rundler_types::{
v0_6::UserOperation, EntityInfo, EntityInfos, UserOperation as UserOperationTrait,
ValidTimeRange,
Expand Down Expand Up @@ -1238,20 +1239,12 @@ mod tests {
}
}

fn pool() -> PoolInner<MockEntryPointV0_6> {
PoolInner::new(
conf(),
MockEntryPointV0_6::new(),
broadcast::channel(100000).0,
)
fn pool() -> PoolInner<Box<dyn DAGasOracleSync>> {
PoolInner::new(conf(), None, broadcast::channel(100000).0)
}

fn pool_with_conf(conf: PoolInnerConfig) -> PoolInner<MockEntryPointV0_6> {
PoolInner::new(
conf,
MockEntryPointV0_6::new(),
broadcast::channel(100000).0,
)
fn pool_with_conf(conf: PoolInnerConfig) -> PoolInner<Box<dyn DAGasOracleSync>> {
PoolInner::new(conf, None, broadcast::channel(100000).0)
}

fn mem_size_of_ordered_pool_op() -> usize {
Expand Down
Loading
Loading