Skip to content

Commit 2b7aff2

Browse files
authored
Merge pull request #2793 from karalabe/blockchain-import-mine-datarace
core: solve a remote-import/local-mine data race
2 parents e76c55a + f5a29ea commit 2b7aff2

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

core/blockchain.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,14 +771,13 @@ func (self *BlockChain) WriteBlock(block *types.Block) (status WriteStatus, err
771771
if ptd == nil {
772772
return NonStatTy, ParentError(block.ParentHash())
773773
}
774-
775-
localTd := self.GetTd(self.currentBlock.Hash(), self.currentBlock.NumberU64())
776-
externTd := new(big.Int).Add(block.Difficulty(), ptd)
777-
778774
// Make sure no inconsistent state is leaked during insertion
779775
self.mu.Lock()
780776
defer self.mu.Unlock()
781777

778+
localTd := self.GetTd(self.currentBlock.Hash(), self.currentBlock.NumberU64())
779+
externTd := new(big.Int).Add(block.Difficulty(), ptd)
780+
782781
// If the total difficulty is higher than our known, add it to the canonical chain
783782
// Second clause in the if statement reduces the vulnerability to selfish mining.
784783
// Please refer to http://www.cs.cornell.edu/~ie53/publications/btcProcFC.pdf

0 commit comments

Comments
 (0)