Skip to content

Commit fb08fd3

Browse files
authored
core/tracing: Add OnClose Trace Hook (#29629)
The OnClose trace hook is being triggered on blockchain Stop, so as tracers can release any resources.
1 parent 882d1e2 commit fb08fd3

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

core/blockchain.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,10 @@ func (bc *BlockChain) Stop() {
11531153
}
11541154
}
11551155
}
1156+
// Allow tracers to clean-up and release resources.
1157+
if bc.logger != nil && bc.logger.OnClose != nil {
1158+
bc.logger.OnClose()
1159+
}
11561160
// Close the trie database, release all the held resources as the last step.
11571161
if err := bc.triedb.Close(); err != nil {
11581162
log.Error("Failed to close trie database", "err", err)

core/tracing/hooks.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ type (
107107
// BlockchainInitHook is called when the blockchain is initialized.
108108
BlockchainInitHook = func(chainConfig *params.ChainConfig)
109109

110+
// CloseHook is called when the blockchain closes.
111+
CloseHook = func()
112+
110113
// BlockStartHook is called before executing `block`.
111114
// `td` is the total difficulty prior to `block`.
112115
BlockStartHook = func(event BlockEvent)
@@ -153,6 +156,7 @@ type Hooks struct {
153156
OnGasChange GasChangeHook
154157
// Chain events
155158
OnBlockchainInit BlockchainInitHook
159+
OnClose CloseHook
156160
OnBlockStart BlockStartHook
157161
OnBlockEnd BlockEndHook
158162
OnSkippedBlock SkippedBlockHook

0 commit comments

Comments
 (0)