From db41c00713e1afe2af128a801defe0435d547391 Mon Sep 17 00:00:00 2001 From: stevencartavia Date: Thu, 24 Oct 2024 02:14:26 -0600 Subject: [PATCH 1/3] Apply beacon system call to trace_block --- crates/rpc/rpc/src/debug.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 2d9d6f7822e1..fc4f98e6d079 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -104,6 +104,15 @@ where return Ok(Vec::new()) } + // Retrieve the block from the block ID + let block = match self.eth_api().block_with_senders(at).await? { + None => return Err(EthApiError::HeaderNotFound(at).into()), + Some(block) => block, + }; + + // Extract the parent beacon block root from the block + let parent_beacon_block_root = block.parent_beacon_block_root; + // replay all transactions of the block let this = self.clone(); self.eth_api() @@ -112,6 +121,26 @@ where let mut results = Vec::with_capacity(transactions.len()); let mut db = CacheDB::new(StateProviderDatabase::new(state)); let mut transactions = transactions.into_iter().enumerate().peekable(); + + let mut system_caller = SystemCaller::new( + Call::evm_config(this.eth_api()).clone(), + LoadState::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(), + ) + })?; + while let Some((index, tx)) = transactions.next() { let tx_hash = tx.hash; From 3ef29efdbecbca27ddf32872f06daec33eeed7d2 Mon Sep 17 00:00:00 2001 From: stevencartavia Date: Fri, 25 Oct 2024 17:22:41 -0600 Subject: [PATCH 2/3] adding the parent beacon block root as another argument --- crates/rpc/rpc/src/debug.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index fc4f98e6d079..ca823400c3fa 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -98,21 +98,13 @@ where cfg: CfgEnvWithHandlerCfg, block_env: BlockEnv, opts: GethDebugTracingOptions, + parent_beacon_block_root: Option, ) -> Result, Eth::Error> { if transactions.is_empty() { // nothing to trace return Ok(Vec::new()) } - // Retrieve the block from the block ID - let block = match self.eth_api().block_with_senders(at).await? { - None => return Err(EthApiError::HeaderNotFound(at).into()), - Some(block) => block, - }; - - // Extract the parent beacon block root from the block - let parent_beacon_block_root = block.parent_beacon_block_root; - // replay all transactions of the block let this = self.clone(); self.eth_api() @@ -200,6 +192,7 @@ where block .body .transactions + .clone() .into_iter() .map(|tx| { tx.into_ecrecovered() @@ -211,6 +204,7 @@ where block .body .transactions + .clone() .into_iter() .map(|tx| { tx.into_ecrecovered_unchecked() @@ -220,7 +214,15 @@ where .collect::, Eth::Error>>()? }; - self.trace_block(parent.into(), transactions, cfg, block_env, opts).await + self.trace_block( + parent.into(), + transactions, + cfg, + block_env, + opts, + block.parent_beacon_block_root, + ) + .await } /// Replays a block and returns the trace of each transaction. @@ -252,6 +254,7 @@ where cfg, block_env, opts, + block.parent_beacon_block_root, ) .await } From 99dc50056b601e82ecd0ff2eb58d1c387bdae49d Mon Sep 17 00:00:00 2001 From: stevencartavia Date: Sat, 26 Oct 2024 20:56:35 -0600 Subject: [PATCH 3/3] new call::evm_config --- crates/rpc/rpc/src/debug.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/crates/rpc/rpc/src/debug.rs b/crates/rpc/rpc/src/debug.rs index 4c8be6ae7aae..9551647d5aef 100644 --- a/crates/rpc/rpc/src/debug.rs +++ b/crates/rpc/rpc/src/debug.rs @@ -112,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() {