aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbojie <bojie@dexon.org>2019-01-17 20:17:18 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 13:50:01 +0800
commitd761e5cbdb58db48c0294a823953cee89f8e1c4e (patch)
tree312e9709a2d8aa4bd7d30ca2f2c52d81c7819a68
parentbc54f0f039f2844e9da001a868f25825781a4e9e (diff)
downloaddexon-d761e5cbdb58db48c0294a823953cee89f8e1c4e.tar
dexon-d761e5cbdb58db48c0294a823953cee89f8e1c4e.tar.gz
dexon-d761e5cbdb58db48c0294a823953cee89f8e1c4e.tar.bz2
dexon-d761e5cbdb58db48c0294a823953cee89f8e1c4e.tar.lz
dexon-d761e5cbdb58db48c0294a823953cee89f8e1c4e.tar.xz
dexon-d761e5cbdb58db48c0294a823953cee89f8e1c4e.tar.zst
dexon-d761e5cbdb58db48c0294a823953cee89f8e1c4e.zip
blockchain: add mutex lock to prevent fork (#159)
-rw-r--r--core/blockchain.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index e6d7cdc76..99f99b64d 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()