Skip to content

Commit

Permalink
Support tips for public mempool submission (#3041)
Browse files Browse the repository at this point in the history
# Description
We had issues with submitting solutions on arbitrum whenever the gas
prices went above the 0.01 Gwei it usually is. To address that we
configured an additional tip. That worked well while we submitted via
`merkle`. Since we stopped using `merkle` we see a bunch of
[errors](https://aws-es.cow.fi/_dashboards/app/data-explorer/discover#?_a=(discover:(columns:!(log,log_level),isDirty:!f,sort:!()),metadata:(indexPattern:'86e4a5a0-4e4b-11ef-85c5-3946a99ed1a7',view:discover))&_g=(filters:!(),refreshInterval:(pause:!t,value:0),time:(from:'2024-09-08T19:45:08.598Z',to:'2024-10-08T01:21:43.919Z'))&_q=(filters:!(),query:(language:kuery,query:'%22gas:%20max%20fee%20per%20gas%20less%20than%20block%20base%20fee%22%20AND%20%22arbitrum%22')))
indicating that we provide a too low gas price for the transactions.
Turns out we only have the ability to configure additional tips using
private mempools but not with the public mempool. That's way we stopped
seeing those errors while `merkle` was active.

# Changes
Added the ability to also configure gas price tips when submitting via
public mempool.

Will create the necessary follow up PR afterwards.

## How to test
Compiler
  • Loading branch information
MartinquaXD authored Oct 15, 2024
1 parent ee6423e commit bcd024e
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 24 deletions.
3 changes: 2 additions & 1 deletion crates/driver/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ gas-price-cap = "1000000000000"

[[submission.mempool]]
mempool = "public"
revert-protection = true
max-additional-tip = "5000000000"
additional-tip-percentage = 0.05

[[submission.mempool]]
mempool = "mev-blocker"
Expand Down
5 changes: 4 additions & 1 deletion crates/driver/src/domain/mempools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ impl Mempools {
if self.mempools.iter().any(|mempool| {
matches!(
mempool.config().kind,
infra::mempool::Kind::Public(infra::mempool::RevertProtection::Disabled)
infra::mempool::Kind::Public {
revert_protection: infra::mempool::RevertProtection::Disabled,
..
}
)
}) {
RevertProtection::Disabled
Expand Down
10 changes: 7 additions & 3 deletions crates/driver/src/infra/blockchain/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ impl GasPriceEstimator {
};
let additional_tip = mempools
.iter()
.filter_map(|mempool| match mempool.kind {
.map(|mempool| match mempool.kind {
mempool::Kind::MEVBlocker {
max_additional_tip,
additional_tip_percentage,
..
} => Some((max_additional_tip, additional_tip_percentage)),
mempool::Kind::Public(_) => None,
} => (max_additional_tip, additional_tip_percentage),
mempool::Kind::Public {
max_additional_tip,
additional_tip_percentage,
..
} => (max_additional_tip, additional_tip_percentage),
})
.next();
// Use the lowest max_fee_per_gas of all mempools as the max_fee_per_gas
Expand Down
33 changes: 20 additions & 13 deletions crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,29 @@ pub async fn load(chain: eth::ChainId, path: &Path) -> infra::Config {
target_confirm_time: config.submission.target_confirm_time,
retry_interval: config.submission.retry_interval,
kind: match mempool {
file::Mempool::Public => {
file::Mempool::Public {
max_additional_tip,
additional_tip_percentage,
} => {
// If there is no private mempool, revert protection is
// disabled, otherwise driver would not even try to settle revertable
// settlements
mempool::Kind::Public(
if config
.submission
.mempools
.iter()
.any(|pool| matches!(pool, file::Mempool::MevBlocker { .. }))
{
mempool::RevertProtection::Enabled
} else {
mempool::RevertProtection::Disabled
},
)
let revert_protection = if config
.submission
.mempools
.iter()
.any(|pool| matches!(pool, file::Mempool::MevBlocker { .. }))
{
mempool::RevertProtection::Enabled
} else {
mempool::RevertProtection::Disabled
};

mempool::Kind::Public {
max_additional_tip: *max_additional_tip,
additional_tip_percentage: *additional_tip_percentage,
revert_protection,
}
}
file::Mempool::MevBlocker {
url,
Expand Down
14 changes: 13 additions & 1 deletion crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,19 @@ struct SubmissionConfig {
#[serde(tag = "mempool")]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
enum Mempool {
Public,
#[serde(rename_all = "kebab-case")]
Public {
/// Maximum additional tip in Gwei that we are willing to pay
/// above regular gas price estimation.
#[serde(default = "default_max_additional_tip")]
#[serde_as(as = "serialize::U256")]
max_additional_tip: eth::U256,
/// Additional tip in percentage of max_fee_per_gas we are willing to
/// pay above regular gas price estimation. Expects a
/// floating point value between 0 and 1.
#[serde(default = "default_additional_tip_percentage")]
additional_tip_percentage: f64,
},
#[serde(rename_all = "kebab-case")]
MevBlocker {
/// The MEVBlocker URL to use.
Expand Down
12 changes: 8 additions & 4 deletions crates/driver/src/infra/mempool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ pub struct Config {
#[derive(Debug, Clone)]
pub enum Kind {
/// The public mempool of the [`Ethereum`] node.
Public(RevertProtection),
Public {
max_additional_tip: eth::U256,
additional_tip_percentage: f64,
revert_protection: RevertProtection,
},
/// The MEVBlocker private mempool.
MEVBlocker {
url: reqwest::Url,
Expand All @@ -33,7 +37,7 @@ impl Kind {
/// for instrumentization purposes
pub fn format_variant(&self) -> &'static str {
match self {
Kind::Public(_) => "PublicMempool",
Kind::Public { .. } => "PublicMempool",
Kind::MEVBlocker { .. } => "MEVBlocker",
}
}
Expand Down Expand Up @@ -65,7 +69,7 @@ impl std::fmt::Display for Mempool {
impl Mempool {
pub fn new(config: Config, transport: DynWeb3) -> Self {
let transport = match &config.kind {
Kind::Public(_) => transport,
Kind::Public { .. } => transport,
// Flashbots Protect RPC fallback doesn't support buffered transport
Kind::MEVBlocker { url, .. } => unbuffered_web3_client(url),
};
Expand Down Expand Up @@ -104,7 +108,7 @@ impl Mempool {

pub fn may_revert(&self) -> bool {
match &self.config.kind {
Kind::Public(_) => true,
Kind::Public { .. } => true,
Kind::MEVBlocker { .. } => false,
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/driver/src/tests/setup/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ async fn create_config_file(
file,
r#"[[submission.mempool]]
mempool = "public"
additional-tip-percentage = 0.0
"#,
)
.unwrap();
Expand Down
6 changes: 5 additions & 1 deletion crates/driver/src/tests/setup/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,11 @@ impl Solver {
gas_price_cap: eth::U256::MAX,
target_confirm_time: Default::default(),
retry_interval: Default::default(),
kind: infra::mempool::Kind::Public(infra::mempool::RevertProtection::Disabled),
kind: infra::mempool::Kind::Public {
max_additional_tip: 0.into(),
additional_tip_percentage: 0.,
revert_protection: infra::mempool::RevertProtection::Disabled,
},
}],
)
.await
Expand Down

0 comments on commit bcd024e

Please sign in to comment.