feat: implement EIP-7002 (#8485)

This commit is contained in:
Alexey Shekhirin
2024-05-30 16:30:59 +01:00
committed by GitHub
parent f43ccc760b
commit 716976f0d1
10 changed files with 360 additions and 51 deletions

View File

@ -18,13 +18,14 @@ use reth_payload_builder::{
};
use reth_primitives::{
constants::{EMPTY_WITHDRAWALS, RETH_CLIENT_VERSION, SLOT_DURATION},
proofs, BlockNumberOrTag, Bytes, ChainSpec, SealedBlock, Withdrawals, B256, U256,
proofs, BlockNumberOrTag, Bytes, ChainSpec, Request, SealedBlock, Withdrawals, B256, U256,
};
use reth_provider::{
BlockReaderIdExt, BlockSource, CanonStateNotification, ProviderError, StateProviderFactory,
};
use reth_revm::state_change::{
apply_beacon_root_contract_call, post_block_withdrawals_balance_increments,
apply_beacon_root_contract_call, apply_withdrawal_requests_contract_call,
post_block_withdrawals_balance_increments,
};
use reth_tasks::TaskSpawner;
use reth_transaction_pool::TransactionPool;
@ -888,6 +889,36 @@ where
.map_err(|err| PayloadBuilderError::Internal(err.into()))
}
/// Apply the [EIP-7002](https://eips.ethereum.org/EIPS/eip-7002) post block contract call.
///
/// This constructs a new [Evm] with the given DB, and environment
/// ([CfgEnvWithHandlerCfg] and [BlockEnv]) to execute the post block contract call.
///
/// This uses [apply_withdrawal_requests_contract_call] to ultimately calculate the
/// [requests](Request).
pub fn post_block_withdrawal_requests_contract_call<DB: Database + DatabaseCommit>(
db: &mut DB,
initialized_cfg: &CfgEnvWithHandlerCfg,
initialized_block_env: &BlockEnv,
) -> Result<Vec<Request>, PayloadBuilderError>
where
DB::Error: std::fmt::Display,
{
// apply post-block EIP-7002 contract call
let mut evm_post_block = Evm::builder()
.with_db(db)
.with_env_with_handler_cfg(EnvWithHandlerCfg::new_with_cfg_env(
initialized_cfg.clone(),
initialized_block_env.clone(),
Default::default(),
))
.build();
// initialize a block from the env, because the post block call needs the block itself
apply_withdrawal_requests_contract_call(&mut evm_post_block)
.map_err(|err| PayloadBuilderError::Internal(err.into()))
}
/// Checks if the new payload is better than the current best.
///
/// This compares the total fees of the blocks, higher is better.