From dfbf580354711af3b542b8c6f5608852d7b90ce3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 29 Apr 2015 14:49:37 +0200 Subject: [PATCH] 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. --- eth/downloader/downloader.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index a7e83a532..81808b4f8 100644 --- a/eth/downloader/downloader.go +++ b/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 // to a seperate goroutine where it periodically checks for linked pieces. types.BlockBy(types.Number).Sort(d.queue.blocks) - blocks := d.queue.blocks - if len(blocks) == 0 { + if len(d.queue.blocks) == 0 { 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()) - var err error // Loop untill we're out of blocks for len(blocks) != 0 { max := int(math.Min(float64(len(blocks)), 256)) @@ -435,9 +437,11 @@ func (d *Downloader) process(peer *peer) error { var i int i, err = d.insertChain(blocks[:max]) 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 { // immediatly unregister the false peer but do not disconnect d.UnregisterPeer(d.activePeer)