diff --git a/core/blockchain.go b/core/blockchain.go index 43d899d77e..771a722ccd 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1535,6 +1535,7 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. // If we're running an archive node, always flush if bc.cacheConfig.TrieDirtyDisabled { err := triedb.Commit(block.Root(), false, nil) + wg.Done() if err != nil { return err } @@ -1584,18 +1585,21 @@ 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) + wg.Done() break } - wg.Add(1) + wg2.Add(1) go func() { triedb.Dereference(root.(common.Hash)) - wg.Done() + wg2.Done() }() } + wg2.Wait() } } return nil