Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion crates/consensus/src/block/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use alloy_eips::{
calc_blob_gasprice,
eip1559::{calc_next_block_base_fee, BaseFeeParams},
eip1898::BlockWithParent,
eip4844::{self},
eip4844::{self, calc_blob_gasprice_with_update_fraction},
eip7742,
merge::ALLOWED_FUTURE_BLOCK_TIME_SECONDS,
BlockNumHash,
Expand Down Expand Up @@ -214,10 +214,39 @@ impl Header {
/// Returns `None` if `excess_blob_gas` is None.
///
/// See also [Self::next_block_excess_blob_gas]
#[deprecated(
since = "0.8.1",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

not sure if you are okay with this version the current one is 0.8.0 so for the next one is 0.8.1;

lmk if you want me to change or remove this

note = "Use `next_block_blob_fee_with_fraction` to account for update fractions"
)]
pub fn next_block_blob_fee(&self) -> Option<u128> {
Some(eip4844::calc_blob_gasprice(self.next_block_excess_blob_gas()?))
}

/// Returns the blob fee for the next block according to the EIP-4844 spec,
/// applying the provided update fraction.
///
/// # Arguments
///
/// - `update_fraction`: Fraction for the fee adjustment calculation (must be between 0.0 and
/// 1.0).
///
/// # Returns
///
/// - `Some(u128)` containing the calculated blob fee if `excess_blob_gas` is `Some`.
/// - `None` if `excess_blob_gas` is `None`.
///
/// # Panics
///
/// - Panics if `update_fraction` is not within the range [0.0, 1.0].
pub fn next_block_blob_fee_with_fraction(&self, update_fraction: f64) -> Option<u128> {
if !(0.0..=1.0).contains(&update_fraction) {
panic!("update_fraction must be between 0.0 and 1.0");
}

let excess_blob_gas = self.next_block_excess_blob_gas()?;
Some(calc_blob_gasprice_with_update_fraction(excess_blob_gas, update_fraction))
}

/// Calculate base fee for next block according to the EIP-1559 spec.
///
/// Returns a `None` if no base fee is set, no EIP-1559 support
Expand Down Expand Up @@ -731,6 +760,17 @@ pub trait BlockHeader {
txs_and_ommers_empty && withdrawals_root == EMPTY_ROOT_HASH
})
}

/// Returns the blob fee for the next block according to the EIP-4844 spec,
/// applying the provided update fraction.
fn next_block_blob_fee_with_fraction(&self, update_fraction: f64) -> Option<u128> {
if !(0.0..=1.0).contains(&update_fraction) {
panic!("update_fraction must be between 0.0 and 1.0");
}

let excess_blob_gas = self.next_block_excess_blob_gas()?;
Some(calc_blob_gasprice_with_update_fraction(excess_blob_gas, update_fraction))
}
}

impl BlockHeader for Header {
Expand Down
9 changes: 8 additions & 1 deletion crates/eips/src/eip4844/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,14 @@ pub fn calc_blob_gasprice(excess_blob_gas: u64) -> u128 {
BLOB_GASPRICE_UPDATE_FRACTION,
)
}

/// Calculate the blob gas price using an update fraction.
pub fn calc_blob_gasprice_with_update_fraction(excess_blob_gas: u64, update_fraction: f64) -> u128 {
fake_exponential(
BLOB_TX_MIN_BLOB_GASPRICE,
(excess_blob_gas as f64 * update_fraction) as u128,
BLOB_GASPRICE_UPDATE_FRACTION,
)
}
/// Approximates `factor * e ** (numerator / denominator)` using Taylor expansion.
///
/// This is used to calculate the blob price.
Expand Down