diff --git a/core/blockchain.go b/core/blockchain.go index 2166f858e3..3e9d91f4bb 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -613,6 +613,7 @@ func (bc *BlockChain) SetFinalized(header *types.Header) { if header != nil { rawdb.WriteFinalizedBlockHash(bc.db, header.Hash()) headFinalizedBlockGauge.Update(int64(header.Number.Uint64())) + exex.TriggerFinalHook(header) } else { rawdb.WriteFinalizedBlockHash(bc.db, common.Hash{}) headFinalizedBlockGauge.Update(0) diff --git a/core/exex/exex.go b/core/exex/exex.go index 23ec81af3a..ea3b4bc2df 100644 --- a/core/exex/exex.go +++ b/core/exex/exex.go @@ -48,4 +48,5 @@ type PluginV1 struct { OnClose CloseHook // Called when the chain gets torn down within Geth OnHead HeadHook // Called when the chain head block is updated in Geth OnReorg ReorgHook // Called wnen the chain reorgs to a sidechain within Geth + OnFinal FinalHook // Called when the chain finalizes a block within Geth } diff --git a/core/exex/exex/registry.go b/core/exex/exex/registry.go index 75767f80cf..1f3a42b7f3 100644 --- a/core/exex/exex/registry.go +++ b/core/exex/exex/registry.go @@ -39,6 +39,7 @@ type registry interface { TriggerCloseHook() TriggerHeadHook(head *types.Header) TriggerReorgHook(headers []*types.Header, revert bool) + TriggerFinalHook(header *types.Header) } // Plugins returns a list of all registered plugins to generate CLI flags. @@ -70,3 +71,8 @@ func TriggerHeadHook(head *types.Header) { func TriggerReorgHook(headers []*types.Header, revert bool) { globalRegistry.TriggerReorgHook(headers, revert) } + +// TriggerFinalHook triggers the OnFinal hook in exex plugins. +func TriggerFinalHook(header *types.Header) { + globalRegistry.TriggerFinalHook(header) +} diff --git a/core/exex/hooks.go b/core/exex/hooks.go index 68589dab23..3ba585b182 100644 --- a/core/exex/hooks.go +++ b/core/exex/hooks.go @@ -51,3 +51,6 @@ type HeadHook = func(head *types.Header) // to pass in both the reverted and applied headers at the same time, but that // would require chain accessorts to support sidechains, which complicate APIs. type ReorgHook = func(headers []*types.Header, revert bool) + +// FinalHook is called when the chain finalizes a past block. +type FinalHook = func(header *types.Header) diff --git a/core/exex/registry_internal.go b/core/exex/registry_internal.go index c35b3754ea..d29e637b84 100644 --- a/core/exex/registry_internal.go +++ b/core/exex/registry_internal.go @@ -87,3 +87,12 @@ func (reg *registry) TriggerReorgHook(headers []*types.Header, revert bool) { } } } + +// TriggerFinalHook triggers the OnFinal hook in exex plugins. +func (reg *registry) TriggerFinalHook(header *types.Header) { + for _, plugin := range globalRegistry.pluginsV1 { + if plugin.OnFinal != nil { + plugin.OnFinal(header) + } + } +}