add pre-transaction/post-block-finalization hooks

This commit is contained in:
Jared Wasinger 2025-10-21 17:18:02 +08:00
parent 79b6a56d3a
commit cba057f8cb
2 changed files with 15 additions and 0 deletions

View file

@ -129,6 +129,10 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
p.chain.Engine().Finalize(p.chain, header, tracingStateDB, block.Body())
if hooks := cfg.Tracer; hooks != nil && hooks.OnPreTxExecutionDone != nil {
hooks.OnPreTxExecutionDone()
}
return &ProcessResult{
Receipts: receipts,
Requests: requests,

View file

@ -161,6 +161,13 @@ type (
// beacon block root.
OnSystemCallEndHook = func()
// OnPreTxExecutionDoneHook is called immediately prior to executing the first
// transaction in the block.
OnPreTxExecutionDoneHook func()
// OnBlockFinalizationHook is called immediately after block rewards are applied
OnBlockFinalizationHook func()
/*
- State events -
*/
@ -209,6 +216,10 @@ type Hooks struct {
OnSystemCallStart OnSystemCallStartHook
OnSystemCallStartV2 OnSystemCallStartHookV2
OnSystemCallEnd OnSystemCallEndHook
OnPreTxExecutionDone OnPreTxExecutionDoneHook
OnBlockFinalization OnBlockFinalizationHook
// State events
OnBalanceChange BalanceChangeHook
OnNonceChange NonceChangeHook