eth: fix data race accessing peer.td

This commit is contained in:
Péter Szilágyi
2015-06-09 14:56:27 +03:00
parent 44147d057d
commit f86707713c
3 changed files with 33 additions and 14 deletions

View File

@ -356,7 +356,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
p.blockHashes.Add(hash)
p.SetHead(hash)
if td != nil {
p.td = td
p.SetTd(td)
}
// Log the block's arrival
_, chainHead, _ := pm.chainman.Status()
@ -369,7 +369,7 @@ func (pm *ProtocolManager) importBlock(p *peer, block *types.Block, td *big.Int)
})
// If the block's already known or its difficulty is lower than ours, drop
if pm.chainman.HasBlock(hash) {
p.td = pm.chainman.GetBlock(hash).Td // update the peer's TD to the real value
p.SetTd(pm.chainman.GetBlock(hash).Td) // update the peer's TD to the real value
return nil
}
if td != nil && pm.chainman.Td().Cmp(td) > 0 && new(big.Int).Add(block.Number(), big.NewInt(7)).Cmp(pm.chainman.CurrentBlock().Number()) < 0 {