Apply beacon system call to trace_block (#12030)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Steven
2024-10-31 03:07:20 -06:00
committed by GitHub
parent 66cc619128
commit 41044a2601

View File

@ -98,6 +98,7 @@ where
cfg: CfgEnvWithHandlerCfg,
block_env: BlockEnv,
opts: GethDebugTracingOptions,
parent_beacon_block_root: Option<B256>,
) -> Result<Vec<TraceResult>, Eth::Error> {
if transactions.is_empty() {
// nothing to trace
@ -111,6 +112,26 @@ where
let block_hash = at.as_block_hash();
let mut results = Vec::with_capacity(transactions.len());
let mut db = CacheDB::new(StateProviderDatabase::new(state));
let mut system_caller = SystemCaller::new(
RpcNodeCore::evm_config(this.eth_api()).clone(),
RpcNodeCore::provider(this.eth_api()).chain_spec(),
);
// apply relevant system calls
system_caller
.pre_block_beacon_root_contract_call(
&mut db,
&cfg,
&block_env,
parent_beacon_block_root,
)
.map_err(|_| {
EthApiError::EvmCustom(
"failed to apply 4788 beacon root system call".to_string(),
)
})?;
let mut transactions = transactions.into_iter().enumerate().peekable();
let mut inspector = None;
while let Some((index, tx)) = transactions.next() {
@ -170,6 +191,9 @@ where
// we trace on top the block's parent block
let parent = block.parent_hash;
// we need the beacon block root for a system call
let parent_beacon_block_root = block.parent_beacon_block_root;
// Depending on EIP-2 we need to recover the transactions differently
let transactions =
if self.inner.provider.chain_spec().is_homestead_active_at_block(block.number) {
@ -196,7 +220,15 @@ where
.collect::<Result<Vec<_>, Eth::Error>>()?
};
self.trace_block(parent.into(), transactions, cfg, block_env, opts).await
self.trace_block(
parent.into(),
transactions,
cfg,
block_env,
opts,
parent_beacon_block_root,
)
.await
}
/// Replays a block and returns the trace of each transaction.
@ -228,6 +260,7 @@ where
cfg,
block_env,
opts,
block.parent_beacon_block_root,
)
.await
}