diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-10 00:06:39 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-07-10 00:06:39 +0800 |
commit | 98f4c936f25de27dbc90f36f2c1ffd1f23b114e9 (patch) | |
tree | 07f8b038c7421e1a9af0fd54e7b78e0002c4591e /eth/handler.go | |
parent | 423c2f499c2350ae54d02a3151686ebd39fc8c94 (diff) | |
parent | 344277d026001d8e114ebfad92f1c385dcd3d3da (diff) | |
download | go-tangerine-007c2df55aba4c7524e2d2253c679f6a27257e53.tar go-tangerine-007c2df55aba4c7524e2d2253c679f6a27257e53.tar.gz go-tangerine-007c2df55aba4c7524e2d2253c679f6a27257e53.tar.bz2 go-tangerine-007c2df55aba4c7524e2d2253c679f6a27257e53.tar.lz go-tangerine-007c2df55aba4c7524e2d2253c679f6a27257e53.tar.xz go-tangerine-007c2df55aba4c7524e2d2253c679f6a27257e53.tar.zst go-tangerine-007c2df55aba4c7524e2d2253c679f6a27257e53.zip |
Merge branch 'release/0.9.38'v0.9.38
Diffstat (limited to 'eth/handler.go')
-rw-r--r-- | eth/handler.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/eth/handler.go b/eth/handler.go index bbb251812..50e2ac99b 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -19,6 +19,7 @@ package eth import ( "fmt" "math" + "math/big" "sync" "time" @@ -412,8 +413,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { pm.fetcher.Enqueue(p.id, request.Block) // TODO: Schedule a sync to cover potential gaps (this needs proto update) - p.SetTd(request.TD) - go pm.synchronise(p) + if request.TD.Cmp(p.Td()) > 0 { + p.SetTd(request.TD) + go pm.synchronise(p) + } case TxMsg: // Transactions arrived, parse all of them and deliver to the pool @@ -452,9 +455,18 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) { // If propagation is requested, send to a subset of the peer if propagate { + // Calculate the TD of the block (it's not imported yet, so block.Td is not valid) + var td *big.Int + if parent := pm.chainman.GetBlock(block.ParentHash()); parent != nil { + td = new(big.Int).Add(parent.Td, block.Difficulty()) + } else { + glog.V(logger.Error).Infof("propagating dangling block #%d [%x]", block.NumberU64(), hash[:4]) + return + } + // Send the block to a subset of our peers transfer := peers[:int(math.Sqrt(float64(len(peers))))] for _, peer := range transfer { - peer.SendNewBlock(block) + peer.SendNewBlock(block, td) } glog.V(logger.Detail).Infof("propagated block %x to %d peers in %v", hash[:4], len(transfer), time.Since(block.ReceivedAt)) } |