diff --git a/core/blockchain.go b/core/blockchain.go index 8c97740752bc..b45cd92e523d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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) diff --git a/core/tracing/hooks.go b/core/tracing/hooks.go index 48cb4d20275c..9ca6ee39fbe7 100644 --- a/core/tracing/hooks.go +++ b/core/tracing/hooks.go @@ -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