From 2e556416342201e782067a65d5c7df74e3e8ed67 Mon Sep 17 00:00:00 2001 From: j75689 Date: Sat, 7 May 2022 02:21:55 +0800 Subject: [PATCH] fix WaitGroup is reused before previous Wait has returned issue --- core/blockchain.go | 14 +++++++++----- core/state_processor_test.go | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 6ad9128716..811391ee10 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -481,11 +481,14 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par } // Need persist and prune diff layer if bc.db.DiffStore() != nil { + bc.wg.Add(1) go bc.trustedDiffLayerLoop() } + bc.wg.Add(1) go bc.untrustedDiffLayerPruneLoop() if bc.pipeCommit { // check current block and rewind invalid one + bc.wg.Add(1) go bc.rewindInvalidHeaderBlockLoop() } return bc, nil @@ -2408,7 +2411,10 @@ func (bc *BlockChain) updateFutureBlocks() { func (bc *BlockChain) rewindInvalidHeaderBlockLoop() { recheck := time.NewTicker(rewindBadBlockInterval) - defer recheck.Stop() + defer func() { + recheck.Stop() + bc.wg.Done() + }() for { select { case <-recheck.C: @@ -2421,10 +2427,9 @@ func (bc *BlockChain) rewindInvalidHeaderBlockLoop() { func (bc *BlockChain) trustedDiffLayerLoop() { recheck := time.NewTicker(diffLayerFreezerRecheckInterval) - bc.wg.Add(1) defer func() { - bc.wg.Done() recheck.Stop() + bc.wg.Done() }() for { select { @@ -2554,10 +2559,9 @@ func (bc *BlockChain) removeDiffLayers(diffHash common.Hash) { func (bc *BlockChain) untrustedDiffLayerPruneLoop() { recheck := time.NewTicker(diffLayerPruneRecheckInterval) - bc.wg.Add(1) defer func() { - bc.wg.Done() recheck.Stop() + bc.wg.Done() }() for { select { diff --git a/core/state_processor_test.go b/core/state_processor_test.go index 3f7ffdd696..a914970c79 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -54,6 +54,7 @@ func TestStateProcessorErrors(t *testing.T) { MuirGlacierBlock: big.NewInt(0), MirrorSyncBlock: big.NewInt(0), BrunoBlock: big.NewInt(0), + EulerBlock: big.NewInt(0), BerlinBlock: big.NewInt(0), LondonBlock: big.NewInt(0), Ethash: new(params.EthashConfig),