From cd0d64a6deba5e1fef2b71e341afa67e09c1b639 Mon Sep 17 00:00:00 2001 From: bojie Date: Thu, 17 Jan 2019 20:17:18 +0800 Subject: blockchain: add mutex lock to prevent fork (#159) --- core/blockchain.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/blockchain.go b/core/blockchain.go index fe7ad3dd8..80d11becd 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1818,7 +1818,6 @@ func (bc *BlockChain) ProcessBlock(block *types.Block, witness *coreTypes.Witnes func (bc *BlockChain) processBlock( block *types.Block, witness *coreTypes.Witness) (*common.Hash, []interface{}, []*types.Log, error) { - // Pre-checks passed, start the full block imports bc.wg.Add(1) defer bc.wg.Done() @@ -1941,6 +1940,12 @@ func (bc *BlockChain) processBlock( } func (bc *BlockChain) ProcessEmptyBlock(block *types.Block) (*common.Hash, error) { + bc.wg.Add(1) + defer bc.wg.Done() + + bc.chainmu.Lock() + defer bc.chainmu.Unlock() + bstart := time.Now() var stats = insertStats{startTime: mclock.Now()} var header = block.Header() -- cgit