From cba057f8cb3e500c6b1699418121ea2113f1c080 Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 21 Oct 2025 17:18:02 +0800 Subject: [PATCH 1/2] 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 b66046f50178..3ecadefbc4f1 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 8e50dc3d8f3e..a383495792e3 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 From 56388262c549442bac065149dca99ca3c640c45f Mon Sep 17 00:00:00 2001 From: Jared Wasinger Date: Tue, 21 Oct 2025 17:25:48 +0800 Subject: [PATCH 2/2] fix last commit --- core/state_processor.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/core/state_processor.go b/core/state_processor.go index 3ecadefbc4f1..db6125eecd10 100644 --- a/core/state_processor.go +++ b/core/state_processor.go @@ -92,6 +92,9 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg if config.IsPrague(block.Number(), block.Time()) || config.IsVerkle(block.Number(), block.Time()) { ProcessParentBlockHash(block.ParentHash(), evm) } + if hooks := cfg.Tracer; hooks != nil && hooks.OnPreTxExecutionDone != nil { + hooks.OnPreTxExecutionDone() + } // Iterate over and process the individual transactions for i, tx := range block.Transactions() { @@ -129,8 +132,8 @@ 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() + if hooks := cfg.Tracer; hooks != nil && hooks.OnBlockFinalization != nil { + hooks.OnBlockFinalization() } return &ProcessResult{