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-08 21:59:19 +0800 |
commit | f5a29eab5ce6ada8fef2378b96384cc81586b6ce (patch) | |
tree | 5fbbe57cac1cdd0b5db0dbb9c8eae37d15145d63 /core | |
parent | 2b94d7fc7fa93ecfd5ab6ddaa0c7bf4d2224d2be (diff) | |
download | dexon-f5a29eab5ce6ada8fef2378b96384cc81586b6ce.tar.gz dexon-f5a29eab5ce6ada8fef2378b96384cc81586b6ce.tar.zst dexon-f5a29eab5ce6ada8fef2378b96384cc81586b6ce.zip |
core: solve a remote-import/local-mine data race
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 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 |