From cba057f8cb3e500c6b1699418121ea2113f1c080 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 21 Oct 2025 17:18:02 +0800 Subject: [PATCH] add pre-transaction/post-block-finalization hooks --- core/state_processor.go | 4 ++++ core/tracing/hooks.go | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/core/state_processor.go b/core/state_processor.go index b66046f501..3ecadefbc4 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -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, diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 8e50dc3d8f..a383495792 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -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