diff --git a/crates/driver/src/boundary/mempool.rs b/crates/driver/src/boundary/mempool.rs index 03d6f2baa9..5ce4c907b9 100644 --- a/crates/driver/src/boundary/mempool.rs +++ b/crates/driver/src/boundary/mempool.rs @@ -36,6 +36,7 @@ pub struct Config { pub max_confirm_time: std::time::Duration, pub retry_interval: std::time::Duration, pub kind: Kind, + pub submission: SubmissionLogic, } #[derive(Debug, Clone)] @@ -71,6 +72,15 @@ pub enum RevertProtection { Disabled, } +/// The submission logic to use for publishing settlements to the blockchain. +/// Can either use the battle tested legacy code, or the new domain native +/// driver logic. +#[derive(Debug, Clone)] +pub enum SubmissionLogic { + Boundary, + Native, +} + /// The mempool to use for publishing settlements to the blockchain. #[derive(Clone)] pub struct Mempool { diff --git a/crates/driver/src/domain/mempools.rs b/crates/driver/src/domain/mempools.rs index 44012847b6..f42734d3d9 100644 --- a/crates/driver/src/domain/mempools.rs +++ b/crates/driver/src/domain/mempools.rs @@ -2,7 +2,7 @@ use { super::eth, crate::{ domain::competition::solution::Settlement, - infra::{self, observe, solver::Solver}, + infra::{self, observe, solver::Solver, Ethereum}, }, futures::{future::select_ok, FutureExt}, thiserror::Error, @@ -11,14 +11,14 @@ use { /// The mempools used to execute settlements. #[derive(Debug, Clone)] -pub struct Mempools(Vec); +pub struct Mempools(Vec, Ethereum); impl Mempools { - pub fn new(mempools: Vec) -> Result { + pub fn new(mempools: Vec, ethereum: Ethereum) -> Result { if mempools.is_empty() { Err(NoMempools) } else { - Ok(Self(mempools)) + Ok(Self(mempools, ethereum)) } } @@ -33,7 +33,14 @@ impl Mempools { let (tx_hash, _remaining_futures) = select_ok(self.0.iter().cloned().map(|mempool| { async move { - let result = mempool.execute(solver, settlement.clone()).await; + let result = match &mempool { + infra::Mempool::Boundary(mempool) => { + mempool.execute(solver, settlement.clone()).await + } + infra::Mempool::Native(_) => { + todo!("implement") + } + }; observe::mempool_executed(&mempool, settlement, &result); result } diff --git a/crates/driver/src/infra/config/file/load.rs b/crates/driver/src/infra/config/file/load.rs index 1a370877cc..1ac67a4205 100644 --- a/crates/driver/src/infra/config/file/load.rs +++ b/crates/driver/src/infra/config/file/load.rs @@ -287,6 +287,10 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config { use_soft_cancellations: *use_soft_cancellations, }, }, + submission: match config.submission.logic { + file::Logic::Boundary => mempool::SubmissionLogic::Boundary, + file::Logic::Native => mempool::SubmissionLogic::Native, + }, }) .collect(), simulator: match (config.tenderly, config.enso) { diff --git a/crates/driver/src/infra/config/file/mod.rs b/crates/driver/src/infra/config/file/mod.rs index 434c172ea7..a74ea9c659 100644 --- a/crates/driver/src/infra/config/file/mod.rs +++ b/crates/driver/src/infra/config/file/mod.rs @@ -85,6 +85,9 @@ struct SubmissionConfig { /// mempool of a node or the private MEVBlocker mempool. #[serde(rename = "mempool", default)] mempools: Vec, + + #[serde(default)] + logic: Logic, } #[derive(Debug, Deserialize)] @@ -446,6 +449,16 @@ enum BalancerV2Preset { BalancerV2, } +#[derive(Debug, Deserialize, Default)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +enum Logic { + /// Use legacy submissions logic (default) + #[default] + Boundary, + /// Use Driver domain native submission logic + Native, +} + #[derive(Clone, Debug, Deserialize)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] struct ZeroExConfig { diff --git a/crates/driver/src/infra/mempool/mod.rs b/crates/driver/src/infra/mempool/mod.rs index 15cbda1dac..9ad8b43408 100644 --- a/crates/driver/src/infra/mempool/mod.rs +++ b/crates/driver/src/infra/mempool/mod.rs @@ -1 +1,44 @@ -pub use crate::boundary::mempool::{Config, GlobalTxPool, Kind, Mempool, RevertProtection}; +pub use crate::boundary::mempool::{Config, GlobalTxPool, Kind, RevertProtection, SubmissionLogic}; + +#[derive(Debug, Clone)] +pub enum Mempool { + /// Legacy implementation of the mempool, using the shared and solvers crate + Boundary(crate::boundary::mempool::Mempool), + /// Driver native mempool implementation + Native(Inner), +} + +impl std::fmt::Display for Mempool { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Boundary(mempool) => write!(f, "Boundary({mempool})"), + Self::Native(mempool) => write!(f, "Native({mempool})"), + } + } +} + +impl Mempool { + pub fn config(&self) -> &Config { + match self { + Self::Boundary(mempool) => mempool.config(), + Self::Native(mempool) => &mempool.config, + } + } +} + +#[derive(Debug, Clone)] +pub struct Inner { + config: Config, +} + +impl std::fmt::Display for Inner { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "Mempool({})", self.config.kind.format_variant()) + } +} + +impl Inner { + pub fn config(&self) -> &Config { + &self.config + } +} diff --git a/crates/driver/src/run.rs b/crates/driver/src/run.rs index ce5da5c126..2bf1dcf66d 100644 --- a/crates/driver/src/run.rs +++ b/crates/driver/src/run.rs @@ -60,10 +60,19 @@ async fn run_with(args: cli::Args, addr_sender: Option Mempool::Boundary( + crate::boundary::Mempool::new( + mempool.to_owned(), + eth.clone(), + tx_pool.clone(), + ) + .unwrap(), + ), + infra::mempool::SubmissionLogic::Native => todo!("implement"), }) .collect(), + eth.clone(), ) .unwrap(), eth,