Skip to content

Commit

Permalink
Merge pull request #2793 from karalabe/blockchain-import-mine-datarace
Browse files Browse the repository at this point in the history
core: solve a remote-import/local-mine data race
  • Loading branch information
karalabe authored Jul 12, 2016
2 parents e76c55a + f5a29ea commit 2b7aff2
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b7aff2

Please sign in to comment.