aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-07-12 20:16:11 +0800
committerGitHub <noreply@github.com>2016-07-12 20:16:11 +0800
commit2b7aff202a84e8c8a8f461df3219c5618221ef3f (patch)
treea2456fe3ba9ad457e2e81640954c4a3e49d198eb
parente76c55a9b800c44dc2c0d275fdf1818ec1a3b1cf (diff)
parentf5a29eab5ce6ada8fef2378b96384cc81586b6ce (diff)
downloadgo-tangerine-2b7aff202a84e8c8a8f461df3219c5618221ef3f.tar.gz
go-tangerine-2b7aff202a84e8c8a8f461df3219c5618221ef3f.tar.zst
go-tangerine-2b7aff202a84e8c8a8f461df3219c5618221ef3f.zip
Merge pull request #2793 from karalabe/blockchain-import-mine-datarace
core: solve a remote-import/local-mine data race
-rw-r--r--core/blockchain.go7
1 files changed, 3 insertions, 4 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index 95bada5ee..950804d40 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -771,14 +771,13 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err
if ptd == nil {
return NonStatTy, ParentError(block.ParentHash())
}
-
- localTd := self.GetTd(self.currentBlock.Hash(), self.currentBlock.NumberU64())
- externTd := new(big.Int).Add(block.Difficulty(), ptd)
-
// Make sure no inconsistent state is leaked during insertion
self.mu.Lock()
defer self.mu.Unlock()
+ localTd := self.GetTd(self.currentBlock.Hash(), self.currentBlock.NumberU64())
+ externTd := new(big.Int).Add(block.Difficulty(), ptd)
+
// If the total difficulty is higher than our known, add it to the canonical chain
// Second clause in the if statement reduces the vulnerability to selfish mining.
// Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf