mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
add OnTerminate in Hooks which triggered on blockchain Stop
This commit is contained in:
parent
4708a19319
commit
00ef42b541
3 changed files with 20 additions and 6 deletions
|
|
@ -1171,6 +1171,10 @@ func (bc *BlockChain) Stop() {
|
|||
if err := bc.triedb.Close(); err != nil {
|
||||
log.Error("Failed to close trie database", "err", err)
|
||||
}
|
||||
// Call OnTerminate hook on Tracers if it is set.
|
||||
if bc.vmConfig.Tracer != nil && bc.vmConfig.Tracer.OnTerminate != nil {
|
||||
bc.vmConfig.Tracer.OnTerminate()
|
||||
}
|
||||
log.Info("Blockchain stopped")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -140,6 +140,9 @@ type (
|
|||
|
||||
// LogHook is called when a log is emitted.
|
||||
LogHook = func(log *types.Log)
|
||||
|
||||
// TerminateHook is called when the tracer is terminated.
|
||||
TerminateHook = func()
|
||||
)
|
||||
|
||||
type Hooks struct {
|
||||
|
|
@ -163,6 +166,7 @@ type Hooks struct {
|
|||
OnCodeChange CodeChangeHook
|
||||
OnStorageChange StorageChangeHook
|
||||
OnLog LogHook
|
||||
OnTerminate TerminateHook
|
||||
}
|
||||
|
||||
// BalanceChangeReason is used to indicate the reason for a balance change, useful
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ type supplyTxCallstack struct {
|
|||
type supply struct {
|
||||
delta supplyInfo
|
||||
txCallstack []supplyTxCallstack // Callstack for current transaction
|
||||
loggerOutputFile *lumberjack.Logger
|
||||
logger *log.Logger
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +71,6 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
|
|||
loggerOutputFile := &lumberjack.Logger{
|
||||
Filename: filepath.Join(config.Path, "supply.jsonl"),
|
||||
}
|
||||
defer loggerOutputFile.Close()
|
||||
|
||||
if config.MaxSize > 0 {
|
||||
loggerOutputFile.MaxSize = config.MaxSize
|
||||
|
|
@ -82,6 +82,7 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
|
|||
|
||||
t := &supply{
|
||||
delta: supplyInfo,
|
||||
loggerOutputFile: loggerOutputFile,
|
||||
logger: logger,
|
||||
}
|
||||
return &tracing.Hooks{
|
||||
|
|
@ -92,6 +93,7 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
|
|||
OnBalanceChange: t.OnBalanceChange,
|
||||
OnEnter: t.OnEnter,
|
||||
OnExit: t.OnExit,
|
||||
OnTerminate: t.OnTerminate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
|
@ -238,3 +240,7 @@ func (s *supply) OnExit(depth int, output []byte, gasUsed uint64, err error, rev
|
|||
}
|
||||
s.txCallstack[size-1].calls = append(s.txCallstack[size-1].calls, call)
|
||||
}
|
||||
|
||||
func (s *supply) OnTerminate() {
|
||||
s.loggerOutputFile.Close()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue