diff --git a/src/node/evm/executor.rs b/src/node/evm/executor.rs index 2192335..9775dc4 100644 --- a/src/node/evm/executor.rs +++ b/src/node/evm/executor.rs @@ -12,7 +12,7 @@ use crate::{ }; use alloy_consensus::{Transaction, TxReceipt}; use alloy_eips::{eip7685::Requests, Encodable2718}; -use alloy_evm::{block::ExecutableTx, eth::receipt_builder::ReceiptBuilderCtx}; +use alloy_evm::{block::{ExecutableTx, StateChangeSource}, eth::receipt_builder::ReceiptBuilderCtx}; use alloy_primitives::{uint, Address, TxKind, U256, BlockNumber, Bytes}; use alloy_sol_macro::sol; use alloy_sol_types::SolCall; @@ -62,6 +62,8 @@ where _ctx: EthBlockExecutionCtx<'a>, /// Utility to call system caller. system_caller: SystemCaller, + /// state hook + hook: Option>, } impl<'a, DB, EVM, Spec, R: ReceiptBuilder> BscBlockExecutor<'a, EVM, Spec, R> @@ -99,6 +101,7 @@ where system_contracts, _ctx, system_caller: SystemCaller::new(spec_clone), + hook: None, } } @@ -204,6 +207,10 @@ where let ResultAndState { result, state } = result_and_state; + if let Some(hook) = &mut self.hook { + hook.on_state(StateChangeSource::Transaction(self.receipts.len()), &state); + } + let tx = tx.clone(); let gas_used = result.gas_used(); self.gas_used += gas_used; @@ -470,6 +477,13 @@ where f(&result); + // Call state hook if it exists, passing the evmstate + if let Some(hook) = &mut self.hook { + let mut temp_state = state.clone(); + temp_state.remove(&SYSTEM_ADDRESS); + hook.on_state(StateChangeSource::Transaction(self.receipts.len()), &temp_state); + } + let gas_used = result.gas_used(); self.gas_used += gas_used; self.receipts.push(self.receipt_builder.build_receipt(ReceiptBuilderCtx { @@ -544,7 +558,9 @@ where )) } - fn set_state_hook(&mut self, _hook: Option>) {} + fn set_state_hook(&mut self, _hook: Option>) { + self.hook = _hook; + } fn evm_mut(&mut self) -> &mut Self::Evm { &mut self.evm