diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-06-15 18:05:01 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-06-15 18:05:01 +0800 |
commit | 9c03c374e32541c905adb9a3b8783cd721117030 (patch) | |
tree | 72b0f11700cce918a933405d542113177312a665 /eth/downloader/downloader.go | |
parent | b240983e2bafcde1c5902ce3a196b22475412f16 (diff) | |
download | go-tangerine-9c03c374e32541c905adb9a3b8783cd721117030.tar.gz go-tangerine-9c03c374e32541c905adb9a3b8783cd721117030.tar.zst go-tangerine-9c03c374e32541c905adb9a3b8783cd721117030.zip |
eth/downloader: fix import statistic reset, fetch hashes async
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r-- | eth/downloader/downloader.go | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 1bbba11ed..7f8ef12ee 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -316,13 +316,8 @@ func (d *Downloader) Cancel() { } d.cancelLock.Unlock() - // Reset the queue and import statistics + // Reset the queue d.queue.Reset() - - d.importLock.Lock() - d.importQueue = nil - d.importDone = 0 - d.importLock.Unlock() } // 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 { <-timeout.C // timeout channel should be initially empty. getHashes := func(from common.Hash) { - active.getHashes(from) + go active.getHashes(from) timeout.Reset(hashTTL) } @@ -414,9 +409,9 @@ func (d *Downloader) fetchHashes(p *peer, h common.Hash) error { expire: time.Now().Add(blockSoftTTL), parent: parent, } - active.getBlocks([]common.Hash{origin}) + go active.getBlocks([]common.Hash{origin}) - // Also fetch a fresh + // Also fetch a fresh batch of hashes getHashes(head) continue } @@ -720,8 +715,16 @@ func (d *Downloader) process() (err error) { err = d.process() } }() - // Release the lock upon exit (note, before checking for reentry!) - defer atomic.StoreInt32(&d.processing, 0) + // Release the lock upon exit (note, before checking for reentry!), and set + // the import statistics to zero. + defer func() { + d.importLock.Lock() + d.importQueue = nil + d.importDone = 0 + d.importLock.Unlock() + + atomic.StoreInt32(&d.processing, 0) + }() // Fetch the current cancel channel to allow termination d.cancelLock.RLock() |