Skip to content

Commit

Permalink
Allow to configure a min priority fee (#2413)
Browse files Browse the repository at this point in the history
# Description
We are seeing errors on Gnosis Chain where our priority fee is deemed
`TooLowToCompete`. Unfortunately, the `additional_tip_percentage` is
currently only applied to MEVBlocker txs (which don't exist on Gnosis
Chain). This is to avoid paying additional tip for public mempool
transactions (which don't require it). This PR allows configuring a
minimum absolute tip amount.

# Changes
- [x] Move `additional_tip_percentage` on the MEVBlocker config, as it's
only valid there
- [x] Introduce a new parameter `min_priority_fee` which is considered
for all mempool kinds

## How to test
- [x] adjust e2e test to run with new config and print settlement tx
receipt
  • Loading branch information
fleupold authored Feb 20, 2024
1 parent 45985dc commit f42eafe
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 25 deletions.
2 changes: 1 addition & 1 deletion crates/driver/example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ account = "0x0000000000000000000000000000000000000000000000000000000000000001" #

[submission]
gas-price-cap = "1000000000000"
additional-tip-percentage = 0.05

[[submission.mempool]]
mempool = "public"
Expand All @@ -23,6 +22,7 @@ revert-protection = true
mempool = "mev-blocker"
url = "https://your.custom.rpc.endpoint"
max-additional-tip = "5000000000"
additional-tip-percentage = 0.05
use-soft-cancellations = true

[contracts] # Optionally override the contract addresses, necessary on less popular blockchains
Expand Down
18 changes: 16 additions & 2 deletions crates/driver/src/boundary/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub use {gas_estimation::GasPriceEstimating, solver::settlement_submission::Glob

#[derive(Debug, Clone)]
pub struct Config {
pub additional_tip_percentage: f64,
pub min_priority_fee: eth::U256,
pub gas_price_cap: eth::U256,
pub target_confirm_time: std::time::Duration,
pub max_confirm_time: std::time::Duration,
Expand All @@ -52,6 +52,7 @@ pub enum Kind {
MEVBlocker {
url: reqwest::Url,
max_additional_tip: eth::U256,
additional_tip_percentage: f64,
use_soft_cancellations: bool,
},
}
Expand Down Expand Up @@ -152,7 +153,20 @@ impl Mempool {
let gas_price_estimator = SubmitterGasPriceEstimator {
inner: self.gas_price_estimator.as_ref(),
max_fee_per_gas: max_fee_per_gas.min(self.config.gas_price_cap.to_f64_lossy()),
additional_tip_percentage_of_max_fee: self.config.additional_tip_percentage,
additional_tip_percentage_of_max_fee: match (
&self.config.kind,
settlement.boundary.revertable(),
) {
(
Kind::MEVBlocker {
additional_tip_percentage,
..
},
true,
) => *additional_tip_percentage,
(Kind::MEVBlocker { .. }, false) => 0.,
(Kind::Public(_), _) => 0.,
},
max_additional_tip: match (&self.config.kind, settlement.boundary.revertable()) {
(
Kind::MEVBlocker {
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/domain/eth/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl From<EffectiveGasPrice> for GasPrice {
/// `{max,max_priority,base}_fee_per_gas` as defined by EIP-1559.
///
/// https://eips.ethereum.org/EIPS/eip-1559#specification
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, Ord, Eq, PartialEq, PartialOrd)]
pub struct FeePerGas(pub Ether);

impl FeePerGas {
Expand Down
35 changes: 22 additions & 13 deletions crates/driver/src/infra/blockchain/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct GasPriceEstimator {
pub(super) gas: Arc<NativeGasEstimator>,
additional_tip: Option<AdditionalTip>,
max_fee_per_gas: eth::U256,
min_priority_fee: eth::U256,
}

impl GasPriceEstimator {
Expand All @@ -31,28 +32,33 @@ impl GasPriceEstimator {
);
let additional_tip = mempools
.iter()
.find(|mempool| matches!(mempool.kind, mempool::Kind::MEVBlocker { .. }))
.map(|mempool| {
(
match mempool.kind {
mempool::Kind::MEVBlocker {
max_additional_tip, ..
} => max_additional_tip,
_ => unreachable!(),
},
mempool.additional_tip_percentage,
)
});
.filter_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,
})
.next();
// Use the lowest max_fee_per_gas of all mempools as the max_fee_per_gas
let max_fee_per_gas = mempools
.iter()
.map(|mempool| mempool.gas_price_cap)
.min()
.expect("at least one mempool");

// Use the highest min_priority_fee of all mempools as the min_priority_fee
let min_priority_fee = mempools
.iter()
.map(|mempool| mempool.min_priority_fee)
.max()
.expect("at least one mempool");
Ok(Self {
gas,
additional_tip,
max_fee_per_gas,
min_priority_fee,
})
}

Expand All @@ -78,7 +84,10 @@ impl GasPriceEstimator {
};
eth::GasPrice::new(
self.max_fee_per_gas.into(),
eth::U256::from_f64_lossy(estimate.max_priority_fee_per_gas).into(),
std::cmp::max(
self.min_priority_fee.into(),
eth::U256::from_f64_lossy(estimate.max_priority_fee_per_gas).into(),
),
eth::U256::from_f64_lossy(estimate.base_fee_per_gas).into(),
)
})
Expand Down
4 changes: 3 additions & 1 deletion crates/driver/src/infra/config/file/load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config {
.mempools
.iter()
.map(|mempool| mempool::Config {
additional_tip_percentage: config.submission.additional_tip_percentage,
min_priority_fee: config.submission.min_priority_fee,
gas_price_cap: config.submission.gas_price_cap,
target_confirm_time: config.submission.target_confirm_time,
max_confirm_time: config.submission.max_confirm_time,
Expand All @@ -280,10 +280,12 @@ pub async fn load(network: &blockchain::Network, path: &Path) -> infra::Config {
file::Mempool::MevBlocker {
url,
max_additional_tip,
additional_tip_percentage,
use_soft_cancellations,
} => mempool::Kind::MEVBlocker {
url: url.to_owned(),
max_additional_tip: *max_additional_tip,
additional_tip_percentage: *additional_tip_percentage,
use_soft_cancellations: *use_soft_cancellations,
},
},
Expand Down
15 changes: 10 additions & 5 deletions crates/driver/src/infra/config/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ struct Config {
#[derive(Debug, Default, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
struct SubmissionConfig {
/// Additional tip in percentage of max_fee_per_gas we are willing to give
/// to miners above regular gas price estimation. Expects a floating point
/// value between 0 and 1.
#[serde(default = "default_additional_tip_percentage")]
additional_tip_percentage: f64,
/// The minimum priority fee in Gwei the solver is ensuring to pay in a
/// settlement.
#[serde(default)]
#[serde_as(as = "serialize::U256")]
min_priority_fee: eth::U256,

/// The maximum gas price in Gwei the solver is willing to pay in a
/// settlement.
Expand Down Expand Up @@ -107,6 +107,11 @@ enum Mempool {
#[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 giving to
/// MEVBlocker above regular gas price estimation. Expects a
/// floating point value between 0 and 1.
#[serde(default = "default_additional_tip_percentage")]
additional_tip_percentage: f64,
/// Configures whether the submission logic is allowed to assume the
/// submission nodes implement soft cancellations. With soft
/// cancellations a cancellation transaction doesn't have to get mined
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/tests/setup/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ async fn create_config_file(
[submission]
gas-price-cap = "1000000000000"
additional-tip-percentage = 0.0
logic = "native"
"#,
hex_address(blockchain.settlement.address()),
Expand All @@ -210,6 +209,7 @@ async fn create_config_file(
file,
r#"[[submission.mempool]]
mempool = "mev-blocker"
additional-tip-percentage = 0.0
url = "{}"
"#,
url.clone().unwrap_or(blockchain.web3_url.clone()),
Expand Down
2 changes: 1 addition & 1 deletion crates/driver/src/tests/setup/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Solver {
infra::blockchain::GasPriceEstimator::new(
rpc.web3(),
&[infra::mempool::Config {
additional_tip_percentage: Default::default(),
min_priority_fee: Default::default(),
gas_price_cap: eth::U256::MAX,
target_confirm_time: Default::default(),
max_confirm_time: Default::default(),
Expand Down

0 comments on commit f42eafe

Please sign in to comment.