Skip to content

Commit

Permalink
core/tracing: Add OnClose Trace Hook (ethereum#29629)
Browse files Browse the repository at this point in the history
The OnClose trace hook is being triggered on blockchain Stop, so as tracers can release any resources.
  • Loading branch information
ziogaschr authored and stwiname committed Sep 9, 2024
1 parent f15a0ab commit 6176cae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions core/tracing/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -153,6 +156,7 @@ type Hooks struct {
OnGasChange GasChangeHook
// Chain events
OnBlockchainInit BlockchainInitHook
OnClose CloseHook
OnBlockStart BlockStartHook
OnBlockEnd BlockEndHook
OnSkippedBlock SkippedBlockHook
Expand Down

0 comments on commit 6176cae

Please sign in to comment.