Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make API implementation of eth_feeHistory compliant with the spec
Browse files Browse the repository at this point in the history
popzxc committed Jun 27, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 0387471 commit 8b053db
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions core/lib/eth_client/src/clients/http/query.rs
Original file line number Diff line number Diff line change
@@ -112,6 +112,18 @@ where
.with_arg("block", &chunk_end)
.await?;

// Check that the lengths are the same.
// Per specification, the values should always be provided, and must be 0 for blocks
// prior to EIP-4844.
// https://ethereum.github.io/execution-apis/api-documentation/
if fee_history.base_fee_per_gas.len() != fee_history.base_fee_per_blob_gas.len() {
tracing::warn!(
"base_fee_per_gas and base_fee_per_blob_gas have different lengths: {} and {}",
fee_history.base_fee_per_gas.len(),
fee_history.base_fee_per_blob_gas.len()
);
}

for (base, blob) in fee_history
.base_fee_per_gas
.into_iter()
8 changes: 6 additions & 2 deletions core/node/api_server/src/web3/namespaces/eth.rs
Original file line number Diff line number Diff line change
@@ -688,15 +688,19 @@ impl EthNamespace {
base_fee_per_gas.len()
]);

// We do not support EIP-4844, but per API specification we should return 0 for pre EIP-4844 blocks.
let base_fee_per_blob_gas = vec![U256::zero(); base_fee_per_gas.len()];
let blob_gas_used_ratio = vec![0.0; base_fee_per_gas.len()];

// `base_fee_per_gas` for next L2 block cannot be calculated, appending last fee as a placeholder.
base_fee_per_gas.push(*base_fee_per_gas.last().unwrap());
Ok(FeeHistory {
oldest_block: web3::BlockNumber::Number(oldest_block.into()),
base_fee_per_gas,
gas_used_ratio,
reward,
base_fee_per_blob_gas: vec![],
blob_gas_used_ratio: vec![],
base_fee_per_blob_gas,
blob_gas_used_ratio,
})
}

0 comments on commit 8b053db

Please sign in to comment.