core/tracing: Add OnClose Trace Hook (#29629)

The OnClose trace hook is being triggered on blockchain Stop, so as tracers can release any resources.
This commit is contained in:
Chris Ziogas 2024-04-24 08:54:59 +03:00 committed by GitHub
parent 882d1e22f6
commit fb08fd334a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

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

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