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

[Feature] EIP-7742: Replace EIP-4844 constants with dynamic values #1709

Closed
Tracked by #1711
onbjerg opened this issue Nov 29, 2024 · 0 comments · Fixed by #1713
Closed
Tracked by #1711

[Feature] EIP-7742: Replace EIP-4844 constants with dynamic values #1709

onbjerg opened this issue Nov 29, 2024 · 0 comments · Fixed by #1713
Labels
enhancement New feature or request

Comments

@onbjerg
Copy link
Member

onbjerg commented Nov 29, 2024

Component

consensus, eips, genesis

Describe the feature you would like

These constants:

pub const MAX_DATA_GAS_PER_BLOCK: u64 = 786_432u64; // 0xC0000 = 6 * 0x20000
/// Target data gas for data blobs in a single block.
pub const TARGET_DATA_GAS_PER_BLOCK: u64 = 393_216u64; // 0x60000 = 3 * 0x20000
/// Maximum number of data blobs in a single block.
pub const MAX_BLOBS_PER_BLOCK: usize = (MAX_DATA_GAS_PER_BLOCK / DATA_GAS_PER_BLOB) as usize; // 786432 / 131072 = 6
/// Target number of data blobs in a single block.
pub const TARGET_BLOBS_PER_BLOCK: u64 = TARGET_DATA_GAS_PER_BLOCK / DATA_GAS_PER_BLOB; // 393216 / 131072 = 3

Should now change based on the values posted by CL over engine API from EIP-7742. For historical sync, these values are in the block header. If these parameters are not present in either engine API or in the header, we can assume we're pre-EIP-7742 and default to 3/6.

We already have some of this here:

/// Calculates the `excess_blob_gas` for the header of the block enabling EIP-7742.
///
/// Normalizes the parent's excess blob gas as per EIP-7742.
#[inline]
pub const fn calc_excess_blob_gas_at_transition(
parent_excess_blob_gas: u64,
parent_blob_gas_used: u64,
) -> u64 {
let normalized_parent_excess_blob_gas = parent_excess_blob_gas
* EXCESS_BLOB_GAS_NORMALIZATION_TARGET
/ eip4844::TARGET_BLOBS_PER_BLOCK;
calc_excess_blob_gas(
normalized_parent_excess_blob_gas,
parent_blob_gas_used,
eip4844::TARGET_BLOBS_PER_BLOCK,
)
}
/// Calculates the `excess_blob_gas` from the parent header's `blob_gas_used`, `excess_blob_gas` and
/// `target_blobs_per_block`.
///
/// Note: this function assumes that the parent block's excess blob gas is normalized as per
/// EIP-7742.
#[inline]
pub const fn calc_excess_blob_gas(
parent_excess_blob_gas: u64,
parent_blob_gas_used: u64,
parent_target_blobs_per_block: u64,
) -> u64 {
let normalized_blob_gas_used =
parent_blob_gas_used * EXCESS_BLOB_GAS_NORMALIZATION_TARGET / parent_target_blobs_per_block;
let normalized_target_blob_gas = DATA_GAS_PER_BLOB * EXCESS_BLOB_GAS_NORMALIZATION_TARGET;
(parent_excess_blob_gas normalized_blob_gas_used).saturating_sub(normalized_target_blob_gas)
}
/// Calculates the blob gas price from the header's excess blob gas field.
///
/// Similar to [crate::eip4844::calc_blob_gasprice], but adjusts the update rate based on
/// `target_blobs_per_block`.
#[inline]
pub fn calc_blob_gasprice(excess_blob_gas: u64) -> u128 {
fake_exponential(
BLOB_TX_MIN_BLOB_GASPRICE,
excess_blob_gas as u128,
BLOB_BASE_FEE_UPDATE_FRACTION_NORMALIZED,
)
}

But this is based on a PR that will not make it into Prague, as this also does normalization. We should instead just use the same logic as in EIP-4844, but replace the constants derived from 3/6 with dynamic values.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant