Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add blobs to eth history #6469

Merged
merged 9 commits into from
Feb 8, 2024
9 changes: 9 additions & 0 deletions crates/rpc/rpc/src/eth/api/fee_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,12 @@ pub struct FeeHistoryEntry {
pub base_fee_per_gas: u64,
/// Gas used ratio this block.
pub gas_used_ratio: f64,
/// The base per blob gas for EIP-4844.
/// For pre EIP-4844 equals to zero.
pub base_fee_per_blob_gas: Option<u128>,
/// Blob gas used ratio for this block.
/// Calculated as the ratio pf gasUsed and gasLimit.
pub blob_gas_used_ratio: f64,
/// Gas used by this block.
pub gas_used: u64,
/// Gas limit by this block.
Expand All @@ -342,6 +348,9 @@ impl FeeHistoryEntry {
FeeHistoryEntry {
base_fee_per_gas: block.base_fee_per_gas.unwrap_or_default(),
gas_used_ratio: block.gas_used as f64 / block.gas_limit as f64,
base_fee_per_blob_gas: block.blob_fee(),
blob_gas_used_ratio: block.blob_gas_used() as f64 /
reth_primitives::constants::eip4844::MAX_DATA_GAS_PER_BLOCK as f64,
Comment on lines +360 to +362
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks correct to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gas_used: block.gas_used,
header_hash: block.hash,
gas_limit: block.gas_limit,
Expand Down
16 changes: 14 additions & 2 deletions crates/rpc/rpc/src/eth/api/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ where
// Collect base fees, gas usage ratios and (optionally) reward percentile data
let mut base_fee_per_gas: Vec<U256> = Vec::new();
let mut gas_used_ratio: Vec<f64> = Vec::new();

let mut base_fee_per_blob_gas: Vec<U256> = Vec::new();
let mut blob_gas_used_ratio: Vec<f64> = Vec::new();

let mut rewards: Vec<Vec<U256>> = Vec::new();

// Check if the requested range is within the cache bounds
Expand All @@ -122,6 +126,9 @@ where
for entry in &fee_entries {
base_fee_per_gas.push(U256::from(entry.base_fee_per_gas));
gas_used_ratio.push(entry.gas_used_ratio);
base_fee_per_blob_gas
.push(U256::from(entry.base_fee_per_blob_gas.unwrap_or_default()));
blob_gas_used_ratio.push(entry.blob_gas_used_ratio);

if let Some(percentiles) = &reward_percentiles {
let mut block_rewards = Vec::with_capacity(percentiles.len());
Expand Down Expand Up @@ -155,6 +162,11 @@ where
for header in &headers {
base_fee_per_gas.push(U256::from(header.base_fee_per_gas.unwrap_or_default()));
gas_used_ratio.push(header.gas_used as f64 / header.gas_limit as f64);
base_fee_per_blob_gas.push(U256::from(header.blob_fee().unwrap_or_default()));
blob_gas_used_ratio.push(
header.blob_gas_used.unwrap_or_default() as f64 /
reth_primitives::constants::eip4844::MAX_DATA_GAS_PER_BLOCK as f64,
);

// Percentiles were specified, so we need to collect reward percentile ino
if let Some(percentiles) = &reward_percentiles {
Expand Down Expand Up @@ -199,10 +211,10 @@ where
Ok(FeeHistory {
base_fee_per_gas,
gas_used_ratio,
base_fee_per_blob_gas,
blob_gas_used_ratio,
oldest_block: U256::from(start_block),
reward: reward_percentiles.map(|_| rewards),
base_fee_per_blob_gas: Default::default(),
blob_gas_used_ratio: Default::default(),
})
}

Expand Down
Loading