Skip to content

Commit 16658c2

Browse files
authored
fix: use next fee blob basefee for missing blob fee (#11782)
fix: use fee blob basefee for missing blob fee
1 parent ad1f9ab commit 16658c2

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

crates/anvil/src/eth/api.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3235,10 +3235,8 @@ impl EthApi {
32353235
m.tx.max_fee_per_gas = self.gas_price();
32363236
}
32373237
if max_fee_per_blob_gas.is_none() {
3238-
m.tx.max_fee_per_blob_gas = self
3239-
.excess_blob_gas_and_price()
3240-
.unwrap_or_default()
3241-
.map_or(0, |g| g.blob_gasprice)
3238+
m.tx.max_fee_per_blob_gas =
3239+
self.backend.fees().get_next_block_blob_base_fee_per_gas();
32423240
}
32433241
TxEip4844Variant::TxEip4844WithSidecar(m)
32443242
}
@@ -3255,10 +3253,8 @@ impl EthApi {
32553253
tx.max_fee_per_gas = self.gas_price();
32563254
}
32573255
if max_fee_per_blob_gas.is_none() {
3258-
tx.max_fee_per_blob_gas = self
3259-
.excess_blob_gas_and_price()
3260-
.unwrap_or_default()
3261-
.map_or(0, |g| g.blob_gasprice)
3256+
tx.max_fee_per_blob_gas =
3257+
self.backend.fees().get_next_block_blob_base_fee_per_gas();
32623258
}
32633259

32643260
TxEip4844Variant::TxEip4844(tx)

crates/anvil/src/eth/fees.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,11 @@ impl FeeManager {
156156
calculate_next_block_base_fee(gas_used, gas_limit, last_fee_per_gas)
157157
}
158158

159-
/// Calculates the next block blob base fee, using the provided excess blob gas
160-
pub fn get_next_block_blob_base_fee_per_gas(&self, excess_blob_gas: u128) -> u128 {
161-
alloy_eips::eip4844::calc_blob_gasprice(excess_blob_gas as u64)
159+
/// Calculates the next block blob base fee.
160+
pub fn get_next_block_blob_base_fee_per_gas(&self) -> u128 {
161+
alloy_eips::eip4844::calc_blob_gasprice(
162+
self.blob_excess_gas_and_price.read().excess_blob_gas,
163+
)
162164
}
163165

164166
/// Calculates the next block blob excess gas, using the provided parent blob gas used and

crates/anvil/tests/it/eip4844.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use alloy_provider::Provider;
1111
use alloy_rpc_types::{BlockId, TransactionRequest};
1212
use alloy_serde::WithOtherFields;
1313
use anvil::{NodeConfig, spawn};
14+
use foundry_test_utils::rpc;
1415

1516
#[tokio::test(flavor = "multi_thread")]
1617
async fn can_send_eip4844_transaction() {
@@ -48,6 +49,33 @@ async fn can_send_eip4844_transaction() {
4849
assert_eq!(receipt.blob_gas_price, Some(0x1)); // 1 wei
4950
}
5051

52+
#[tokio::test(flavor = "multi_thread")]
53+
async fn can_send_eip4844_transaction_fork() {
54+
let node_config = NodeConfig::test()
55+
.with_eth_rpc_url(Some(rpc::next_http_archive_rpc_url()))
56+
.with_fork_block_number(Some(23432306u64))
57+
.with_hardfork(Some(EthereumHardfork::Cancun.into()));
58+
let (api, handle) = spawn(node_config).await;
59+
let provider = handle.http_provider();
60+
let accounts = provider.get_accounts().await.unwrap();
61+
let alice = accounts[0];
62+
let bob = accounts[1];
63+
64+
let sidecar: SidecarBuilder<SimpleCoder> = SidecarBuilder::from_slice(b"Blobs are fun!");
65+
let sidecar = sidecar.build().unwrap();
66+
67+
let tx = TransactionRequest::default()
68+
.with_from(alice)
69+
.with_to(bob)
70+
.with_blob_sidecar(sidecar.clone());
71+
72+
let pending_tx = provider.send_transaction(tx.into()).await.unwrap();
73+
let receipt = pending_tx.get_receipt().await.unwrap();
74+
let tx_hash = receipt.transaction_hash;
75+
76+
let _blobs = api.anvil_get_blob_by_tx_hash(tx_hash).unwrap().unwrap();
77+
}
78+
5179
#[tokio::test(flavor = "multi_thread")]
5280
async fn can_send_multiple_blobs_in_one_tx() {
5381
let node_config = NodeConfig::test().with_hardfork(Some(EthereumHardfork::Cancun.into()));

0 commit comments

Comments
 (0)