Skip to content

Commit

Permalink
Prepare code for Native Mempool implementation (#2293)
Browse files Browse the repository at this point in the history
# Description
Sets the foundation for a driver native solution submission strategy,
that can be conditionally turned on and tested via the config file.

# Changes
<!-- List of detailed changes (how the change is accomplished) -->

- [x] Defines a new SubmissionLogic enum which can be set in the toml
config
- [x] inside infra, divide between the boundary implementation and the
not yet implemented native driver infra mempool implementation
- [x] Pipe config and implementation together

Note, that currently the system would fail to start with the non-default
Native solution submission configuration.

## How to test
No logic change, just compilation

## Related Issues

Part of #2216
  • Loading branch information
fleupold authored Jan 22, 2024
1 parent 83cea49 commit 268e7c2
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 8 deletions.
10 changes: 10 additions & 0 deletions crates/driver/src/boundary/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 12 additions & 5 deletions crates/driver/src/domain/mempools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -11,14 +11,14 @@ use {

/// The mempools used to execute settlements.
#[derive(Debug, Clone)]
pub struct Mempools(Vec<infra::Mempool>);
pub struct Mempools(Vec<infra::Mempool>, Ethereum);

impl Mempools {
pub fn new(mempools: Vec<infra::Mempool>) -> Result<Self, NoMempools> {
pub fn new(mempools: Vec<infra::Mempool>, ethereum: Ethereum) -> Result<Self, NoMempools> {
if mempools.is_empty() {
Err(NoMempools)
} else {
Ok(Self(mempools))
Ok(Self(mempools, ethereum))
}
}

Expand All @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 13 additions & 0 deletions crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ struct SubmissionConfig {
/// mempool of a node or the private MEVBlocker mempool.
#[serde(rename = "mempool", default)]
mempools: Vec<Mempool>,

#[serde(default)]
logic: Logic,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -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 {
Expand Down
45 changes: 44 additions & 1 deletion crates/driver/src/infra/mempool/mod.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
13 changes: 11 additions & 2 deletions crates/driver/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,19 @@ async fn run_with(args: cli::Args, addr_sender: Option<oneshot::Sender<SocketAdd
config
.mempools
.iter()
.map(|mempool| {
Mempool::new(mempool.to_owned(), eth.clone(), tx_pool.clone()).unwrap()
.map(|mempool| match mempool.submission {
infra::mempool::SubmissionLogic::Boundary => 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,
Expand Down

0 comments on commit 268e7c2

Please sign in to comment.