Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/node/evm/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,6 +62,8 @@ where
_ctx: EthBlockExecutionCtx<'a>,
/// Utility to call system caller.
system_caller: SystemCaller<Spec>,
/// state hook
hook: Option<Box<dyn OnStateHook>>,
}

impl<'a, DB, EVM, Spec, R: ReceiptBuilder> BscBlockExecutor<'a, EVM, Spec, R>
Expand Down Expand Up @@ -99,6 +101,7 @@ where
system_contracts,
_ctx,
system_caller: SystemCaller::new(spec_clone),
hook: None,
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -544,7 +558,9 @@ where
))
}

fn set_state_hook(&mut self, _hook: Option<Box<dyn OnStateHook>>) {}
fn set_state_hook(&mut self, _hook: Option<Box<dyn OnStateHook>>) {
self.hook = _hook;
}

fn evm_mut(&mut self) -> &mut Self::Evm {
&mut self.evm
Expand Down
Loading