From e215f3fdeada259a8886a7611151794d280ca298 Mon Sep 17 00:00:00 2001 From: zerosnacks <95942363+zerosnacks@users.noreply.github.com> Date: Mon, 7 Oct 2024 17:39:49 +0200 Subject: [PATCH] fix(`anvil`): eth_gasPrice returned `1000000000` with `--block-base-fee-per-gas 0`, adds new `--disable-min-priority-fee` to return `0` (#9049) * add new flag to disable min suggested priority fee: `--disable-min-priority-fee` * documentation * remove unnecessary value_name --- crates/anvil/src/cmd.rs | 5 +++++ crates/anvil/src/config.rs | 11 +++++++++++ crates/anvil/src/eth/api.rs | 6 +++++- crates/anvil/src/eth/backend/mem/mod.rs | 5 +++++ crates/anvil/src/eth/fees.rs | 8 ++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/crates/anvil/src/cmd.rs b/crates/anvil/src/cmd.rs index 149b9c863065..76eb0510a591 100644 --- a/crates/anvil/src/cmd.rs +++ b/crates/anvil/src/cmd.rs @@ -254,6 +254,7 @@ impl NodeArgs { .fork_compute_units_per_second(compute_units_per_second) .with_eth_rpc_url(self.evm_opts.fork_url.map(|fork| fork.url)) .with_base_fee(self.evm_opts.block_base_fee_per_gas) + .disable_min_priority_fee(self.evm_opts.disable_min_priority_fee) .with_storage_caching(self.evm_opts.no_storage_caching) .with_server_config(self.server_config) .with_host(self.host) @@ -547,6 +548,10 @@ pub struct AnvilEvmArgs { )] pub block_base_fee_per_gas: Option, + /// Disable the enforcement of a minimum suggested priority fee. + #[arg(long, visible_alias = "no-priority-fee", help_heading = "Environment config")] + pub disable_min_priority_fee: bool, + /// The chain ID. #[arg(long, alias = "chain", help_heading = "Environment config")] pub chain_id: Option, diff --git a/crates/anvil/src/config.rs b/crates/anvil/src/config.rs index 189cf51752d1..273dbad89ffd 100644 --- a/crates/anvil/src/config.rs +++ b/crates/anvil/src/config.rs @@ -99,6 +99,8 @@ pub struct NodeConfig { pub gas_price: Option, /// Default base fee pub base_fee: Option, + /// If set to `true`, disables the enforcement of a minimum suggested priority fee + pub disable_min_priority_fee: bool, /// Default blob excess gas and price pub blob_excess_gas_and_price: Option, /// The hardfork to use @@ -432,6 +434,7 @@ impl Default for NodeConfig { fork_choice: None, account_generator: None, base_fee: None, + disable_min_priority_fee: false, blob_excess_gas_and_price: None, enable_tracing: true, enable_steps_tracing: false, @@ -623,6 +626,13 @@ impl NodeConfig { self } + /// Disable the enforcement of a minimum suggested priority fee + #[must_use] + pub fn disable_min_priority_fee(mut self, disable_min_priority_fee: bool) -> Self { + self.disable_min_priority_fee = disable_min_priority_fee; + self + } + /// Sets the init genesis (genesis.json) #[must_use] pub fn with_genesis(mut self, genesis: Option) -> Self { @@ -994,6 +1004,7 @@ impl NodeConfig { let fees = FeeManager::new( cfg.handler_cfg.spec_id, self.get_base_fee(), + !self.disable_min_priority_fee, self.get_gas_price(), self.get_blob_excess_gas_and_price(), ); diff --git a/crates/anvil/src/eth/api.rs b/crates/anvil/src/eth/api.rs index c8fd497a3e81..78b52d49496a 100644 --- a/crates/anvil/src/eth/api.rs +++ b/crates/anvil/src/eth/api.rs @@ -592,7 +592,11 @@ impl EthApi { /// Returns the current gas price pub fn gas_price(&self) -> u128 { if self.backend.is_eip1559() { - (self.backend.base_fee() as u128).saturating_add(self.lowest_suggestion_tip()) + if self.backend.is_min_priority_fee_enforced() { + (self.backend.base_fee() as u128).saturating_add(self.lowest_suggestion_tip()) + } else { + self.backend.base_fee() as u128 + } } else { self.backend.fees().raw_gas_price() } diff --git a/crates/anvil/src/eth/backend/mem/mod.rs b/crates/anvil/src/eth/backend/mem/mod.rs index 05a7a3ff7a7b..0b7777f2db20 100644 --- a/crates/anvil/src/eth/backend/mem/mod.rs +++ b/crates/anvil/src/eth/backend/mem/mod.rs @@ -668,6 +668,11 @@ impl Backend { self.fees.base_fee() } + /// Returns whether the minimum suggested priority fee is enforced + pub fn is_min_priority_fee_enforced(&self) -> bool { + self.fees.is_min_priority_fee_enforced() + } + pub fn excess_blob_gas_and_price(&self) -> Option { self.fees.excess_blob_gas_and_price() } diff --git a/crates/anvil/src/eth/fees.rs b/crates/anvil/src/eth/fees.rs index 72d66b113055..f41c51505ff6 100644 --- a/crates/anvil/src/eth/fees.rs +++ b/crates/anvil/src/eth/fees.rs @@ -48,6 +48,8 @@ pub struct FeeManager { /// /// This value will be updated after a new block was mined base_fee: Arc>, + /// Whether the minimum suggested priority fee is enforced + is_min_priority_fee_enforced: bool, /// Tracks the excess blob gas, and the base fee, for the next block post Cancun /// /// This value will be updated after a new block was mined @@ -63,12 +65,14 @@ impl FeeManager { pub fn new( spec_id: SpecId, base_fee: u64, + is_min_priority_fee_enforced: bool, gas_price: u128, blob_excess_gas_and_price: BlobExcessGasAndPrice, ) -> Self { Self { spec_id, base_fee: Arc::new(RwLock::new(base_fee)), + is_min_priority_fee_enforced, gas_price: Arc::new(RwLock::new(gas_price)), blob_excess_gas_and_price: Arc::new(RwLock::new(blob_excess_gas_and_price)), elasticity: Arc::new(RwLock::new(default_elasticity())), @@ -105,6 +109,10 @@ impl FeeManager { } } + pub fn is_min_priority_fee_enforced(&self) -> bool { + self.is_min_priority_fee_enforced + } + /// Raw base gas price pub fn raw_gas_price(&self) -> u128 { *self.gas_price.read()