add OnClose Hook which triggered on blockchain Stop

This commit is contained in:
Chris Ziogas 2024-04-23 16:11:46 +03:00
parent 256d4b099c
commit 1e84d87a45
No known key found for this signature in database
GPG key ID: 2329CF479E36E2DA
2 changed files with 8 additions and 0 deletions

View file

@ -1157,6 +1157,10 @@ func (bc *BlockChain) Stop() {
if err := bc.triedb.Close(); err != nil {
log.Error("Failed to close trie database", "err", err)
}
// Allow tracers to clean-up and release resources.
if bc.logger != nil && bc.logger.OnClose != nil {
bc.logger.OnClose()
}
log.Info("Blockchain stopped")
}

View file

@ -107,6 +107,9 @@ type (
// BlockchainInitHook is called when the blockchain is initialized.
BlockchainInitHook = func(chainConfig *params.ChainConfig)
// CloseHook is called when the blockchain closes.
CloseHook = func()
// BlockStartHook is called before executing `block`.
// `td` is the total difficulty prior to `block`.
BlockStartHook = func(event BlockEvent)
@ -153,6 +156,7 @@ type Hooks struct {
OnGasChange GasChangeHook
// Chain events
OnBlockchainInit BlockchainInitHook
OnClose CloseHook
OnBlockStart BlockStartHook
OnBlockEnd BlockEndHook
OnSkippedBlock SkippedBlockHook