mirror of https://github.com/poanetwork/quorum.git
Locking WriteBlockAndState for Istanbul Consensus
This commit is contained in:
parent
8c9ed51fa0
commit
2991562244
|
@ -92,6 +92,7 @@ type BlockChain struct {
|
|||
mu sync.RWMutex // global mutex for locking chain operations
|
||||
chainmu sync.RWMutex // blockchain insertion lock
|
||||
procmu sync.RWMutex // block processor lock
|
||||
insertmu sync.Mutex // block and state insert lock
|
||||
|
||||
checkpoint int // checkpoint counts towards the new checkpoint
|
||||
currentBlock *types.Block // Current head of the block chain
|
||||
|
@ -813,6 +814,16 @@ func (bc *BlockChain) WriteBlockAndState(block *types.Block, receipts []*types.R
|
|||
bc.wg.Add(1)
|
||||
defer bc.wg.Done()
|
||||
|
||||
bc.insertmu.Lock()
|
||||
defer bc.insertmu.Unlock()
|
||||
|
||||
if bc.config.IsQuorum && bc.config.Istanbul != nil {
|
||||
if bc.GetBlockByHash(block.Hash()) != nil {
|
||||
log.Warn("Block already inserted", "number", block.NumberU64(), "hash", block.Hash())
|
||||
return CanonStatTy, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the total difficulty of the block
|
||||
ptd := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
|
||||
if ptd == nil {
|
||||
|
|
Loading…
Reference in New Issue