eth/downloader: ignore orphan blocks in the downloader.

When blocks have been sorted and are being processed, orphan blocks
should be ignored and thrown out. The protocol handler is responsible
for downloading blocks which have missing parents.
release/1.0.1
obscuren 10 years ago
parent 735b029db9
commit dfbf580354
  1. 14
      eth/downloader/downloader.go

@ -418,14 +418,16 @@ func (d *Downloader) process(peer *peer) error {
// link). We should at least check whihc queue match. This code could move // link). We should at least check whihc queue match. This code could move
// to a seperate goroutine where it periodically checks for linked pieces. // to a seperate goroutine where it periodically checks for linked pieces.
types.BlockBy(types.Number).Sort(d.queue.blocks) types.BlockBy(types.Number).Sort(d.queue.blocks)
blocks := d.queue.blocks if len(d.queue.blocks) == 0 {
if len(blocks) == 0 {
return nil return nil
} }
var (
blocks = d.queue.blocks
err error
)
glog.V(logger.Debug).Infof("Inserting chain with %d blocks (#%v - #%v)\n", len(blocks), blocks[0].Number(), blocks[len(blocks)-1].Number()) glog.V(logger.Debug).Infof("Inserting chain with %d blocks (#%v - #%v)\n", len(blocks), blocks[0].Number(), blocks[len(blocks)-1].Number())
var err error
// Loop untill we're out of blocks // Loop untill we're out of blocks
for len(blocks) != 0 { for len(blocks) != 0 {
max := int(math.Min(float64(len(blocks)), 256)) max := int(math.Min(float64(len(blocks)), 256))
@ -435,9 +437,11 @@ func (d *Downloader) process(peer *peer) error {
var i int var i int
i, err = d.insertChain(blocks[:max]) i, err = d.insertChain(blocks[:max])
if err != nil && core.IsParentErr(err) { if err != nil && core.IsParentErr(err) {
glog.V(logger.Debug).Infof("Aborting process due to missing parent (%d)\n", i) // Ignore the missing blocks. Handler should take care of anything that's missing.
glog.V(logger.Debug).Infof("Ignored block with missing parent (%d)\n", i)
blocks = blocks[i:]
break continue
} else if err != nil { } else if err != nil {
// immediatly unregister the false peer but do not disconnect // immediatly unregister the false peer but do not disconnect
d.UnregisterPeer(d.activePeer) d.UnregisterPeer(d.activePeer)

Loading…
Cancel
Save