mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
core: support finality event on exec
This commit is contained in:
parent
f6cbab924b
commit
062209fff8
5 changed files with 20 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue