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 {
|
if err := bc.triedb.Close(); err != nil {
|
||||||
log.Error("Failed to close trie database", "err", err)
|
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")
|
log.Info("Blockchain stopped")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,9 @@ type (
|
||||||
|
|
||||||
// LogHook is called when a log is emitted.
|
// LogHook is called when a log is emitted.
|
||||||
LogHook = func(log *types.Log)
|
LogHook = func(log *types.Log)
|
||||||
|
|
||||||
|
// TerminateHook is called when the tracer is terminated.
|
||||||
|
TerminateHook = func()
|
||||||
)
|
)
|
||||||
|
|
||||||
type Hooks struct {
|
type Hooks struct {
|
||||||
|
|
@ -163,6 +166,7 @@ type Hooks struct {
|
||||||
OnCodeChange CodeChangeHook
|
OnCodeChange CodeChangeHook
|
||||||
OnStorageChange StorageChangeHook
|
OnStorageChange StorageChangeHook
|
||||||
OnLog LogHook
|
OnLog LogHook
|
||||||
|
OnTerminate TerminateHook
|
||||||
}
|
}
|
||||||
|
|
||||||
// BalanceChangeReason is used to indicate the reason for a balance change, useful
|
// BalanceChangeReason is used to indicate the reason for a balance change, useful
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,10 @@ type supplyTxCallstack struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type supply struct {
|
type supply struct {
|
||||||
delta supplyInfo
|
delta supplyInfo
|
||||||
txCallstack []supplyTxCallstack // Callstack for current transaction
|
txCallstack []supplyTxCallstack // Callstack for current transaction
|
||||||
logger *log.Logger
|
loggerOutputFile *lumberjack.Logger
|
||||||
|
logger *log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
type supplyTracerConfig struct {
|
type supplyTracerConfig struct {
|
||||||
|
|
@ -70,7 +71,6 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
|
||||||
loggerOutputFile := &lumberjack.Logger{
|
loggerOutputFile := &lumberjack.Logger{
|
||||||
Filename: filepath.Join(config.Path, "supply.jsonl"),
|
Filename: filepath.Join(config.Path, "supply.jsonl"),
|
||||||
}
|
}
|
||||||
defer loggerOutputFile.Close()
|
|
||||||
|
|
||||||
if config.MaxSize > 0 {
|
if config.MaxSize > 0 {
|
||||||
loggerOutputFile.MaxSize = config.MaxSize
|
loggerOutputFile.MaxSize = config.MaxSize
|
||||||
|
|
@ -81,8 +81,9 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
|
||||||
supplyInfo := newSupplyInfo()
|
supplyInfo := newSupplyInfo()
|
||||||
|
|
||||||
t := &supply{
|
t := &supply{
|
||||||
delta: supplyInfo,
|
delta: supplyInfo,
|
||||||
logger: logger,
|
loggerOutputFile: loggerOutputFile,
|
||||||
|
logger: logger,
|
||||||
}
|
}
|
||||||
return &tracing.Hooks{
|
return &tracing.Hooks{
|
||||||
OnBlockStart: t.OnBlockStart,
|
OnBlockStart: t.OnBlockStart,
|
||||||
|
|
@ -92,6 +93,7 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
|
||||||
OnBalanceChange: t.OnBalanceChange,
|
OnBalanceChange: t.OnBalanceChange,
|
||||||
OnEnter: t.OnEnter,
|
OnEnter: t.OnEnter,
|
||||||
OnExit: t.OnExit,
|
OnExit: t.OnExit,
|
||||||
|
OnTerminate: t.OnTerminate,
|
||||||
}, nil
|
}, 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)
|
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