aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-11 01:12:22 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-11 01:12:22 +0800
commit3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f (patch)
tree8484dba53a48dbaf1b0d98084885ab56dcc1badc /eth
parentc4af70d0cc213b5fd906a385cdb2895268525ef7 (diff)
downloadgo-tangerine-3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f.tar
go-tangerine-3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f.tar.gz
go-tangerine-3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f.tar.bz2
go-tangerine-3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f.tar.lz
go-tangerine-3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f.tar.xz
go-tangerine-3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f.tar.zst
go-tangerine-3c1cccc801ec7c546a0d840fe3a08dbf9a302d2f.zip
eth/downloader: fetch the block hashes on the fly, when needed
Diffstat (limited to 'eth')
-rw-r--r--eth/downloader/downloader.go14
1 files changed, 5 insertions, 9 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index c3234ecb1..f0a515d12 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -79,9 +79,9 @@ type Downloader struct {
banned *set.Set // Set of hashes we've received and banned
// Statistics
- importStart time.Time // Instance when the last blocks were taken from the cache
- importQueue []common.Hash // Hashes of the previously taken blocks to check import progress
- importDone int // Number of taken blocks already imported from the last batch
+ importStart time.Time // Instance when the last blocks were taken from the cache
+ importQueue []*Block // Previously taken blocks to check import progress
+ importDone int // Number of taken blocks already imported from the last batch
importLock sync.Mutex
// Callbacks
@@ -136,7 +136,7 @@ func (d *Downloader) Stats() (pending int, cached int, importing int, estimate t
d.importLock.Lock()
defer d.importLock.Unlock()
- for len(d.importQueue) > 0 && d.hasBlock(d.importQueue[0]) {
+ for len(d.importQueue) > 0 && d.hasBlock(d.importQueue[0].RawBlock.Hash()) {
d.importQueue = d.importQueue[1:]
d.importDone++
}
@@ -229,13 +229,9 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
func (d *Downloader) TakeBlocks() []*Block {
blocks := d.queue.TakeBlocks()
if len(blocks) > 0 {
- hashes := make([]common.Hash, len(blocks))
- for i, block := range blocks {
- hashes[i] = block.RawBlock.Hash()
- }
d.importLock.Lock()
d.importStart = time.Now()
- d.importQueue = hashes
+ d.importQueue = blocks
d.importDone = 0
d.importLock.Unlock()
}