@@ -316,13 +316,8 @@ func (d *Downloader) Cancel() {
316
316
}
317
317
d .cancelLock .Unlock ()
318
318
319
- // Reset the queue and import statistics
319
+ // Reset the queue
320
320
d .queue .Reset ()
321
-
322
- d .importLock .Lock ()
323
- d .importQueue = nil
324
- d .importDone = 0
325
- d .importLock .Unlock ()
326
321
}
327
322
328
323
// 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 {
345
340
<- timeout .C // timeout channel should be initially empty.
346
341
347
342
getHashes := func (from common.Hash ) {
348
- active .getHashes (from )
343
+ go active .getHashes (from )
349
344
timeout .Reset (hashTTL )
350
345
}
351
346
@@ -414,9 +409,9 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error {
414
409
expire : time .Now ().Add (blockSoftTTL ),
415
410
parent : parent ,
416
411
}
417
- active .getBlocks ([]common.Hash {origin })
412
+ go active .getBlocks ([]common.Hash {origin })
418
413
419
- // Also fetch a fresh
414
+ // Also fetch a fresh batch of hashes
420
415
getHashes (head )
421
416
continue
422
417
}
@@ -720,8 +715,16 @@ func (d *Downloader) process() (err error) {
720
715
err = d .process ()
721
716
}
722
717
}()
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
+ }()
725
728
726
729
// Fetch the current cancel channel to allow termination
727
730
d .cancelLock .RLock ()
0 commit comments