Skip to content

Commit 9c03c37

Browse files
committed
eth/downloader: fix import statistic reset, fetch hashes async
1 parent b240983 commit 9c03c37

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

eth/downloader/downloader.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,8 @@ func (d *Downloader) Cancel() {
316316
}
317317
d.cancelLock.Unlock()
318318

319-
// Reset the queue and import statistics
319+
// Reset the queue
320320
d.queue.Reset()
321-
322-
d.importLock.Lock()
323-
d.importQueue = nil
324-
d.importDone = 0
325-
d.importLock.Unlock()
326321
}
327322

328323
// fetchHahes starts retrieving hashes backwards from a specific peer and hash,
@@ -345,7 +340,7 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
345340
<-timeout.C // timeout channel should be initially empty.
346341

347342
getHashes := func(from common.Hash) {
348-
active.getHashes(from)
343+
go active.getHashes(from)
349344
timeout.Reset(hashTTL)
350345
}
351346

@@ -414,9 +409,9 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
414409
expire: time.Now().Add(blockSoftTTL),
415410
parent: parent,
416411
}
417-
active.getBlocks([]common.Hash{origin})
412+
go active.getBlocks([]common.Hash{origin})
418413

419-
// Also fetch a fresh
414+
// Also fetch a fresh batch of hashes
420415
getHashes(head)
421416
continue
422417
}
@@ -720,8 +715,16 @@ func (d *Downloader) process() (err error) {
720715
err = d.process()
721716
}
722717
}()
723-
// Release the lock upon exit (note, before checking for reentry!)
724-
defer atomic.StoreInt32(&d.processing, 0)
718+
// Release the lock upon exit (note, before checking for reentry!), and set
719+
// the import statistics to zero.
720+
defer func() {
721+
d.importLock.Lock()
722+
d.importQueue = nil
723+
d.importDone = 0
724+
d.importLock.Unlock()
725+
726+
atomic.StoreInt32(&d.processing, 0)
727+
}()
725728

726729
// Fetch the current cancel channel to allow termination
727730
d.cancelLock.RLock()

0 commit comments

Comments
 (0)