From e86282408dabe5f48f186d5320e376d2757b5c9e Mon Sep 17 00:00:00 2001 From: peekpi <894646171@qq.com> Date: Fri, 2 Jul 2021 14:40:58 +0800 Subject: [PATCH] [tracer] fix bug of nil reference --- api/service/explorer/storage.go | 4 +++- core/blockchain.go | 6 ++++-- core/events.go | 1 - hmy/tracers/block_tracer.go | 6 ++++-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/api/service/explorer/storage.go b/api/service/explorer/storage.go index fa13b97d8..42a82db3b 100644 --- a/api/service/explorer/storage.go +++ b/api/service/explorer/storage.go @@ -305,7 +305,9 @@ LOOP: } traceResult.btc = bc.db.NewBatch() traceResult.data.ToDB(func(key, value []byte) { - _ = writeTraceResult(traceResult.btc, key, value) + if exist, err := isTraceResultInDB(bc.db, key); !exist && err == nil { + _ = writeTraceResult(traceResult.btc, key, value) + } }) select { case bc.resultT <- traceResult: diff --git a/core/blockchain.go b/core/blockchain.go index ddd4df89d..4c261ea70 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1453,8 +1453,10 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifyHeaders bool) (int, vmConfig := bc.vmConfig if bc.trace { ev := TraceEvent{ - Block: block, - Tracer: &tracers.ParityBlockTracer{}, + Tracer: &tracers.ParityBlockTracer{ + Hash: block.Hash(), + Number: block.NumberU64(), + }, } vmConfig = vm.Config{ Debug: true, diff --git a/core/events.go b/core/events.go index 19a43b82c..6f7db7c75 100644 --- a/core/events.go +++ b/core/events.go @@ -44,7 +44,6 @@ type ChainEvent struct { } type TraceEvent struct { - Block *types.Block Tracer *tracers.ParityBlockTracer } diff --git a/hmy/tracers/block_tracer.go b/hmy/tracers/block_tracer.go index e080fe51d..3bd4b5611 100644 --- a/hmy/tracers/block_tracer.go +++ b/hmy/tracers/block_tracer.go @@ -203,6 +203,8 @@ type ParityTxTracer struct { action } type ParityBlockTracer struct { + Hash common.Hash + Number uint64 cur *ParityTxTracer tracers []*ParityTxTracer } @@ -401,8 +403,8 @@ func (jst *ParityBlockTracer) CaptureEnd(output []byte, gasUsed uint64, t time.D func (jst *ParityBlockTracer) GetStorage() *TraceBlockStorage { blockStorage := &TraceBlockStorage{ - Hash: jst.cur.blockHash, - Number: jst.cur.blockNumber, + Hash: jst.Hash, + Number: jst.Number, addressIndex: make(map[common.Address]int), dataIndex: make(map[common.Hash]int), }