chore: move pre_block_beacon_root_contract_call to evm crates (#9244)

This commit is contained in:
joshieDo
2024-07-03 16:54:28 +02:00
committed by GitHub
parent 08fc298e55
commit 7a647f4f1e
17 changed files with 302 additions and 207 deletions

View File

@ -7,6 +7,7 @@ use reth_evm::{
BatchExecutor, BlockExecutionError, BlockExecutionInput, BlockExecutionOutput,
BlockExecutorProvider, BlockValidationError, Executor, ProviderError,
},
system_calls::apply_beacon_root_contract_call,
ConfigureEvm,
};
use reth_execution_types::ExecutionOutcome;
@ -16,7 +17,7 @@ use reth_prune_types::PruneModes;
use reth_revm::{
batch::{BlockBatchRecord, BlockExecutorStats},
db::states::bundle_state::BundleRetention,
state_change::{apply_beacon_root_contract_call, post_block_balance_increments},
state_change::post_block_balance_increments,
Evm, State,
};
use revm_primitives::{
@ -121,7 +122,7 @@ where
DB: Database<Error: Into<ProviderError> + std::fmt::Display>,
{
// apply pre execution changes
apply_beacon_root_contract_call(
apply_beacon_root_contract_call::<EvmConfig, _, _>(
&self.chain_spec,
block.timestamp,
block.number,

View File

@ -27,6 +27,7 @@ pub use l1::*;
mod error;
pub use error::OptimismBlockExecutionError;
use revm_primitives::{Bytes, Env, OptimismFields, TxKind};
/// Optimism-related EVM configuration.
#[derive(Debug, Default, Clone, Copy)]
@ -38,6 +39,49 @@ impl ConfigureEvmEnv for OptimismEvmConfig {
transaction.fill_tx_env(tx_env, sender);
}
fn fill_tx_env_system_contract_call(
env: &mut Env,
caller: Address,
contract: Address,
data: Bytes,
) {
env.tx = TxEnv {
caller,
transact_to: TxKind::Call(contract),
// Explicitly set nonce to None so revm does not do any nonce checks
nonce: None,
gas_limit: 30_000_000,
value: U256::ZERO,
data,
// Setting the gas price to zero enforces that no value is transferred as part of the
// call, and that the call will not count against the block's gas limit
gas_price: U256::ZERO,
// The chain ID check is not relevant here and is disabled if set to None
chain_id: None,
// Setting the gas priority fee to None ensures the effective gas price is derived from
// the `gas_price` field, which we need to be zero
gas_priority_fee: None,
access_list: Vec::new(),
// blob fields can be None for this tx
blob_hashes: Vec::new(),
max_fee_per_blob_gas: None,
optimism: OptimismFields {
source_hash: None,
mint: None,
is_system_transaction: Some(false),
// The L1 fee is not charged for the EIP-4788 transaction, submit zero bytes for the
// enveloped tx size.
enveloped_tx: Some(Bytes::default()),
},
};
// ensure the block gas limit is >= the tx
env.block.gas_limit = U256::from(env.tx.gas_limit);
// disable the base fee check for this call by setting the base fee to zero
env.block.basefee = U256::ZERO;
}
fn fill_cfg_env(
cfg_env: &mut CfgEnvWithHandlerCfg,
chain_spec: &ChainSpec,

View File

@ -6,7 +6,7 @@ use crate::{
};
use reth_basic_payload_builder::*;
use reth_chainspec::{ChainSpec, EthereumHardforks, OptimismHardfork};
use reth_evm::ConfigureEvm;
use reth_evm::{system_calls::pre_block_beacon_root_contract_call, ConfigureEvm};
use reth_execution_types::ExecutionOutcome;
use reth_payload_builder::error::PayloadBuilderError;
use reth_primitives::{
@ -125,11 +125,13 @@ where
// apply eip-4788 pre block contract call
pre_block_beacon_root_contract_call(
&mut db,
self.evm_config.clone(),
&chain_spec,
block_number,
&initialized_cfg,
&initialized_block_env,
&attributes,
block_number,
attributes.payload_attributes.timestamp,
attributes.payload_attributes.parent_beacon_block_root,
)
.map_err(|err| {
warn!(target: "payload_builder",
@ -137,7 +139,7 @@ where
%err,
"failed to apply beacon root contract call for empty payload"
);
err
PayloadBuilderError::Internal(err.into())
})?;
let WithdrawalsOutcome { withdrawals_root, withdrawals } = commit_withdrawals(
@ -286,12 +288,22 @@ where
// apply eip-4788 pre block contract call
pre_block_beacon_root_contract_call(
&mut db,
evm_config.clone(),
&chain_spec,
block_number,
&initialized_cfg,
&initialized_block_env,
&attributes,
)?;
block_number,
attributes.payload_attributes.timestamp,
attributes.payload_attributes.parent_beacon_block_root,
)
.map_err(|err| {
warn!(target: "payload_builder",
parent_hash=%parent_block.hash(),
%err,
"failed to apply beacon root contract call for empty payload"
);
PayloadBuilderError::Internal(err.into())
})?;
// Ensure that the create2deployer is force-deployed at the canyon transition. Optimism
// blocks will always have at least a single transaction in them (the L1 info transaction),