diff options
author | Péter Szilágyi <peterke@gmail.com> | 2016-07-08 21:59:19 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-07-16 19:29:41 +0800 |
commit | da776556d0c9f74f0d2dd285150f55470b5039ff (patch) | |
tree | e9fa2763f6461188344f170fdde44eee548bcfe8 /core | |
parent | f2e8759d1051a5317cfcfa61bbb70122b3b7e06e (diff) | |
download | go-tangerine-da776556d0c9f74f0d2dd285150f55470b5039ff.tar go-tangerine-da776556d0c9f74f0d2dd285150f55470b5039ff.tar.gz go-tangerine-da776556d0c9f74f0d2dd285150f55470b5039ff.tar.bz2 go-tangerine-da776556d0c9f74f0d2dd285150f55470b5039ff.tar.lz go-tangerine-da776556d0c9f74f0d2dd285150f55470b5039ff.tar.xz go-tangerine-da776556d0c9f74f0d2dd285150f55470b5039ff.tar.zst go-tangerine-da776556d0c9f74f0d2dd285150f55470b5039ff.zip |
[release/1.4.10] core: solve a remote-import/local-mine data race
(cherry picked from commit f5a29eab5ce6ada8fef2378b96384cc81586b6ce)
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index bd84adfe9..3fbb117d3 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -763,14 +763,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()) - 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()) + 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 |