aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorbojie <bojie@dexon.org>2019-01-17 20:17:18 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commitcd0d64a6deba5e1fef2b71e341afa67e09c1b639 (patch)
tree9aaa3d35c57fd43ee0878e9787178e015cdb2c88 /core
parent5d8993b8c01668589713e30d4431f404339cacf4 (diff)
downloaddexon-cd0d64a6deba5e1fef2b71e341afa67e09c1b639.tar.gz
dexon-cd0d64a6deba5e1fef2b71e341afa67e09c1b639.tar.zst
dexon-cd0d64a6deba5e1fef2b71e341afa67e09c1b639.zip
blockchain: add mutex lock to prevent fork (#159)
Diffstat (limited to 'core')
-rw-r--r--core/blockchain.go7
1 files changed, 6 insertions, 1 deletions
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()