Skip to content

Commit e215f3f

Browse files
authored
fix(anvil): eth_gasPrice returned 1000000000 with --block-base-fee-per-gas 0, adds new --disable-min-priority-fee to return 0 (foundry-rs#9049)
* add new flag to disable min suggested priority fee: `--disable-min-priority-fee` * documentation * remove unnecessary value_name
1 parent 1ba5d6f commit e215f3f

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

crates/anvil/src/cmd.rs

+5
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ impl NodeArgs {
254254
.fork_compute_units_per_second(compute_units_per_second)
255255
.with_eth_rpc_url(self.evm_opts.fork_url.map(|fork| fork.url))
256256
.with_base_fee(self.evm_opts.block_base_fee_per_gas)
257+
.disable_min_priority_fee(self.evm_opts.disable_min_priority_fee)
257258
.with_storage_caching(self.evm_opts.no_storage_caching)
258259
.with_server_config(self.server_config)
259260
.with_host(self.host)
@@ -547,6 +548,10 @@ pub struct AnvilEvmArgs {
547548
)]
548549
pub block_base_fee_per_gas: Option<u64>,
549550

551+
/// Disable the enforcement of a minimum suggested priority fee.
552+
#[arg(long, visible_alias = "no-priority-fee", help_heading = "Environment config")]
553+
pub disable_min_priority_fee: bool,
554+
550555
/// The chain ID.
551556
#[arg(long, alias = "chain", help_heading = "Environment config")]
552557
pub chain_id: Option<Chain>,

crates/anvil/src/config.rs

+11
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ pub struct NodeConfig {
9999
pub gas_price: Option<u128>,
100100
/// Default base fee
101101
pub base_fee: Option<u64>,
102+
/// If set to `true`, disables the enforcement of a minimum suggested priority fee
103+
pub disable_min_priority_fee: bool,
102104
/// Default blob excess gas and price
103105
pub blob_excess_gas_and_price: Option<BlobExcessGasAndPrice>,
104106
/// The hardfork to use
@@ -432,6 +434,7 @@ impl Default for NodeConfig {
432434
fork_choice: None,
433435
account_generator: None,
434436
base_fee: None,
437+
disable_min_priority_fee: false,
435438
blob_excess_gas_and_price: None,
436439
enable_tracing: true,
437440
enable_steps_tracing: false,
@@ -623,6 +626,13 @@ impl NodeConfig {
623626
self
624627
}
625628

629+
/// Disable the enforcement of a minimum suggested priority fee
630+
#[must_use]
631+
pub fn disable_min_priority_fee(mut self, disable_min_priority_fee: bool) -> Self {
632+
self.disable_min_priority_fee = disable_min_priority_fee;
633+
self
634+
}
635+
626636
/// Sets the init genesis (genesis.json)
627637
#[must_use]
628638
pub fn with_genesis(mut self, genesis: Option<Genesis>) -> Self {
@@ -994,6 +1004,7 @@ impl NodeConfig {
9941004
let fees = FeeManager::new(
9951005
cfg.handler_cfg.spec_id,
9961006
self.get_base_fee(),
1007+
!self.disable_min_priority_fee,
9971008
self.get_gas_price(),
9981009
self.get_blob_excess_gas_and_price(),
9991010
);

crates/anvil/src/eth/api.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,11 @@ impl EthApi {
592592
/// Returns the current gas price
593593
pub fn gas_price(&self) -> u128 {
594594
if self.backend.is_eip1559() {
595-
(self.backend.base_fee() as u128).saturating_add(self.lowest_suggestion_tip())
595+
if self.backend.is_min_priority_fee_enforced() {
596+
(self.backend.base_fee() as u128).saturating_add(self.lowest_suggestion_tip())
597+
} else {
598+
self.backend.base_fee() as u128
599+
}
596600
} else {
597601
self.backend.fees().raw_gas_price()
598602
}

crates/anvil/src/eth/backend/mem/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,11 @@ impl Backend {
668668
self.fees.base_fee()
669669
}
670670

671+
/// Returns whether the minimum suggested priority fee is enforced
672+
pub fn is_min_priority_fee_enforced(&self) -> bool {
673+
self.fees.is_min_priority_fee_enforced()
674+
}
675+
671676
pub fn excess_blob_gas_and_price(&self) -> Option<BlobExcessGasAndPrice> {
672677
self.fees.excess_blob_gas_and_price()
673678
}

crates/anvil/src/eth/fees.rs

+8
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct FeeManager {
4848
///
4949
/// This value will be updated after a new block was mined
5050
base_fee: Arc<RwLock<u64>>,
51+
/// Whether the minimum suggested priority fee is enforced
52+
is_min_priority_fee_enforced: bool,
5153
/// Tracks the excess blob gas, and the base fee, for the next block post Cancun
5254
///
5355
/// This value will be updated after a new block was mined
@@ -63,12 +65,14 @@ impl FeeManager {
6365
pub fn new(
6466
spec_id: SpecId,
6567
base_fee: u64,
68+
is_min_priority_fee_enforced: bool,
6669
gas_price: u128,
6770
blob_excess_gas_and_price: BlobExcessGasAndPrice,
6871
) -> Self {
6972
Self {
7073
spec_id,
7174
base_fee: Arc::new(RwLock::new(base_fee)),
75+
is_min_priority_fee_enforced,
7276
gas_price: Arc::new(RwLock::new(gas_price)),
7377
blob_excess_gas_and_price: Arc::new(RwLock::new(blob_excess_gas_and_price)),
7478
elasticity: Arc::new(RwLock::new(default_elasticity())),
@@ -105,6 +109,10 @@ impl FeeManager {
105109
}
106110
}
107111

112+
pub fn is_min_priority_fee_enforced(&self) -> bool {
113+
self.is_min_priority_fee_enforced
114+
}
115+
108116
/// Raw base gas price
109117
pub fn raw_gas_price(&self) -> u128 {
110118
*self.gas_price.read()

0 commit comments

Comments
 (0)