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

fix(executor): Holocene EIP-1559 params in Header #622

Merged
merged 6 commits into from
Oct 4, 2024
Merged
Changes from 1 commit
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
77 changes: 51 additions & 26 deletions crates/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@
payload: OptimismPayloadAttributes,
) -> ExecutorResult<&Header> {
// Prepare the `revm` environment.
let base_fee_params =
Self::active_base_fee_params(self.config, &payload, self.trie_db.parent_block_header());
let initialized_block_env = Self::prepare_block_env(
self.revm_spec_id(payload.payload_attributes.timestamp),
self.config,
self.trie_db.parent_block_header(),
&payload,
&base_fee_params,
);
let initialized_cfg = self.evm_cfg_env(payload.payload_attributes.timestamp);
let block_number = initialized_block_env.number.to::<u64>();
Expand Down Expand Up @@ -305,6 +307,21 @@
})
.unwrap_or_default();

let encoded_base_fee_params = self
.config
.is_holocene_active(payload.payload_attributes.timestamp)
.then(|| {
let mut encoded_params = B64::ZERO;
encoded_params[0..4].copy_from_slice(
(base_fee_params.max_change_denominator as u32).to_be_bytes().as_ref(),
);
encoded_params[4..8].copy_from_slice(
(base_fee_params.elasticity_multiplier as u32).to_be_bytes().as_ref(),
);
encoded_params

Check warning on line 321 in crates/executor/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/executor/src/lib.rs#L314-L321

Added lines #L314 - L321 were not covered by tests
})
.unwrap_or_default();

// Construct the new header.
let header = Header {
parent_hash: state.database.parent_block_header().seal(),
Expand All @@ -322,12 +339,7 @@
gas_used: cumulative_gas_used,
timestamp: payload.payload_attributes.timestamp,
mix_hash: payload.payload_attributes.prev_randao,
nonce: self
.config
.is_holocene_active(payload.payload_attributes.timestamp)
.then_some(payload.eip_1559_params)
.flatten()
.unwrap_or_default(),
nonce: encoded_base_fee_params,
base_fee_per_gas: base_fee.try_into().ok(),
blob_gas_used,
excess_blob_gas: excess_blob_gas.and_then(|x| x.try_into().ok()),
Expand Down Expand Up @@ -502,23 +514,49 @@
/// Prepares a [BlockEnv] with the given [OptimismPayloadAttributes].
///
/// ## Takes
/// - `payload`: The payload to prepare the environment for.
/// - `env`: The block environment to prepare.
/// - `spec_id`: The [SpecId] to prepare the environment for.
/// - `parent_header`: The parent header of the block to be executed.
/// - `payload_attrs`: The payload to prepare the environment for.
/// - `base_fee_params`: The active base fee parameters for the block.
fn prepare_block_env(
spec_id: SpecId,
config: &RollupConfig,
parent_header: &Header,
payload_attrs: &OptimismPayloadAttributes,
base_fee_params: &BaseFeeParams,
) -> BlockEnv {
let blob_excess_gas_and_price = parent_header
.next_block_excess_blob_gas()
.or_else(|| spec_id.is_enabled_in(SpecId::ECOTONE).then_some(0))
.map(BlobExcessGasAndPrice::new);
let next_block_base_fee =
parent_header.next_block_base_fee(*base_fee_params).unwrap_or_default();

BlockEnv {
number: U256::from(parent_header.number + 1),
coinbase: address!("4200000000000000000000000000000000000011"),
timestamp: U256::from(payload_attrs.payload_attributes.timestamp),
gas_limit: U256::from(payload_attrs.gas_limit.expect("Gas limit not provided")),
basefee: U256::from(next_block_base_fee),
difficulty: U256::ZERO,
prevrandao: Some(payload_attrs.payload_attributes.prev_randao),
blob_excess_gas_and_price,
}
}

/// Returns the active base fee parameters for the given payload attributes.
///
/// ## Takes
/// - `config`: The rollup config to use for the computation.
/// - `payload_attrs`: The payload attributes to use for the computation.
/// - `parent_header`: The parent header of the block to be executed.
fn active_base_fee_params(
config: &RollupConfig,
payload_attrs: &OptimismPayloadAttributes,
parent_header: &Header,
) -> BaseFeeParams {
// If the payload attribute timestamp is past canyon activation,
// use the canyon base fee params from the rollup config.
let base_fee_params = if config
.is_holocene_active(payload_attrs.payload_attributes.timestamp)
{
if config.is_holocene_active(payload_attrs.payload_attributes.timestamp) {
// If the parent header nonce is zero, use the default base fee params.
if parent_header.nonce == B64::ZERO {
config.canyon_base_fee_params
Expand All @@ -534,19 +572,6 @@
config.canyon_base_fee_params
} else {
config.base_fee_params
};
let next_block_base_fee =
parent_header.next_block_base_fee(base_fee_params).unwrap_or_default();

BlockEnv {
number: U256::from(parent_header.number + 1),
coinbase: address!("4200000000000000000000000000000000000011"),
timestamp: U256::from(payload_attrs.payload_attributes.timestamp),
gas_limit: U256::from(payload_attrs.gas_limit.expect("Gas limit not provided")),
basefee: U256::from(next_block_base_fee),
difficulty: U256::ZERO,
prevrandao: Some(payload_attrs.payload_attributes.prev_randao),
blob_excess_gas_and_price,
}
}

Expand Down