diff --git a/core/blockchain.go b/core/blockchain.go index b7838a7719..2e67c2f3c1 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1546,18 +1546,20 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. } } // Garbage collect anything below our required write retention + wg2 := sync.WaitGroup{} for !bc.triegc.Empty() { root, number := bc.triegc.Pop() if uint64(-number) > chosen { bc.triegc.Push(root, number) break } - wg.Add(1) + wg2.Add(1) go func() { triedb.Dereference(root.(common.Hash)) - wg.Done() + wg2.Done() }() } + wg2.Wait() } } return nil