Removed wg. (#4098)

Co-authored-by: Konstantin <k.potapov@softpro.com>
pull/4112/head
Frozen 3 years ago committed by GitHub
parent 34c42349e2
commit 0dbf490477
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      core/blockchain.go

@ -178,8 +178,7 @@ type BlockChain struct {
running int32 // running must be called atomically
blockchainPruner *blockchainPruner // use to prune beacon chain
// procInterrupt must be atomically called
procInterrupt int32 // interrupt signaler for block processing
wg sync.WaitGroup // chain processing wait group for shutting down
procInterrupt int32 // interrupt signaler for block processing
engine consensus_engine.Engine
processor Processor // block processor interface
@ -873,6 +872,9 @@ func (bc *BlockChain) Stop() {
return
}
bc.chainmu.Lock()
defer bc.chainmu.Unlock()
if err := bc.SavePendingCrossLinks(); err != nil {
utils.Logger().Error().Err(err).Msg("Failed to save pending cross links")
}
@ -882,8 +884,6 @@ func (bc *BlockChain) Stop() {
close(bc.quit)
atomic.StoreInt32(&bc.procInterrupt, 1)
bc.wg.Wait()
// Ensure the state of a recent block is also stored to disk before exiting.
// We're writing three different states to catch different restart scenarios:
// - HEAD: So we don't need to reprocess any blocks in the general case
@ -1058,9 +1058,6 @@ func SetReceiptsData(config *params.ChainConfig, block *types.Block, receipts ty
// InsertReceiptChain attempts to complete an already existing header chain with
// transaction and receipt data.
func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain []types.Receipts) (int, error) {
bc.wg.Add(1)
defer bc.wg.Done()
// Do a sanity check that the provided chain is actually ordered and linked
for i := 1; i < len(blockChain); i++ {
if blockChain[i].NumberU64() != blockChain[i-1].NumberU64()+1 || blockChain[i].ParentHash() != blockChain[i-1].Hash() {
@ -1076,6 +1073,9 @@ func (bc *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain [
}
}
bc.chainmu.Lock()
defer bc.chainmu.Unlock()
var (
stats = struct{ processed, ignored int32 }{}
start = time.Now()
@ -1164,8 +1164,8 @@ var lastWrite uint64
// but does not write any state. This is used to construct competing side forks
// up to the point where they exceed the canonical total difficulty.
func (bc *BlockChain) WriteBlockWithoutState(block *types.Block, td *big.Int) (err error) {
bc.wg.Add(1)
defer bc.wg.Done()
bc.chainmu.Lock()
defer bc.chainmu.Unlock()
if err := bc.hc.WriteTd(block.Hash(), block.NumberU64(), td); err != nil {
return err
@ -1185,9 +1185,6 @@ func (bc *BlockChain) WriteBlockWithState(
paid reward.Reader,
state *state.DB,
) (status WriteStatus, err error) {
bc.wg.Add(1)
defer bc.wg.Done()
// Make sure no inconsistent state is leaked during insertion
bc.mu.Lock()
defer bc.mu.Unlock()
@ -1365,9 +1362,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifyHeaders bool) (int,
chain[i-1].Hash().Bytes()[:4], i, chain[i].NumberU64(), chain[i].Hash().Bytes()[:4], chain[i].ParentHash().Bytes()[:4])
}
}
// Pre-checks passed, start the full block imports
bc.wg.Add(1)
defer bc.wg.Done()
bc.chainmu.Lock()
defer bc.chainmu.Unlock()
@ -1771,9 +1765,6 @@ func (bc *BlockChain) InsertHeaderChain(chain []*block.Header, checkFreq int) (i
bc.chainmu.Lock()
defer bc.chainmu.Unlock()
bc.wg.Add(1)
defer bc.wg.Done()
whFunc := func(header *block.Header) error {
bc.mu.Lock()
defer bc.mu.Unlock()

Loading…
Cancel
Save