core/tracing: add hook for reverted out blocks

This commit is contained in:
Sina Mahmoodi 2024-08-26 21:32:08 +02:00
parent f670a7fd93
commit cf873c3767
2 changed files with 8 additions and 0 deletions

View File

@ -2375,6 +2375,10 @@ func (bc *BlockChain) reorg(oldHead *types.Header, newHead *types.Block) error {
if len(rebirthLogs) > 0 { if len(rebirthLogs) > 0 {
bc.logsFeed.Send(rebirthLogs) bc.logsFeed.Send(rebirthLogs)
} }
if bc.logger != nil && bc.logger.OnReorg != nil {
bc.logger.OnReorg(oldChain)
}
return nil return nil
} }

View File

@ -134,6 +134,9 @@ type (
// GenesisBlockHook is called when the genesis block is being processed. // GenesisBlockHook is called when the genesis block is being processed.
GenesisBlockHook = func(genesis *types.Block, alloc types.GenesisAlloc) GenesisBlockHook = func(genesis *types.Block, alloc types.GenesisAlloc)
// ReorgHook is called when a segment of the chain is reverted.
ReorgHook = func(reverted []*types.Block)
// OnSystemCallStartHook is called when a system call is about to be executed. Today, // OnSystemCallStartHook is called when a system call is about to be executed. Today,
// this hook is invoked when the EIP-4788 system call is about to be executed to set the // this hook is invoked when the EIP-4788 system call is about to be executed to set the
// beacon block root. // beacon block root.
@ -186,6 +189,7 @@ type Hooks struct {
OnBlockEnd BlockEndHook OnBlockEnd BlockEndHook
OnSkippedBlock SkippedBlockHook OnSkippedBlock SkippedBlockHook
OnGenesisBlock GenesisBlockHook OnGenesisBlock GenesisBlockHook
OnReorg ReorgHook
OnSystemCallStart OnSystemCallStartHook OnSystemCallStart OnSystemCallStartHook
OnSystemCallEnd OnSystemCallEndHook OnSystemCallEnd OnSystemCallEndHook
// State events // State events