aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/downloader.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-10 23:01:05 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-10 23:01:05 +0800
commit271fb20ecb48944692bdb4e7f91be9b90506981b (patch)
tree4acc7ee481a231bf2532b19f7f05f1f7b10c9bcc /eth/downloader/downloader.go
parentb3d5ce7d48426bbe9269f3ea89029187cf939398 (diff)
downloaddexon-271fb20ecb48944692bdb4e7f91be9b90506981b.tar
dexon-271fb20ecb48944692bdb4e7f91be9b90506981b.tar.gz
dexon-271fb20ecb48944692bdb4e7f91be9b90506981b.tar.bz2
dexon-271fb20ecb48944692bdb4e7f91be9b90506981b.tar.lz
dexon-271fb20ecb48944692bdb4e7f91be9b90506981b.tar.xz
dexon-271fb20ecb48944692bdb4e7f91be9b90506981b.tar.zst
dexon-271fb20ecb48944692bdb4e7f91be9b90506981b.zip
cmd/geth, eth/downloader: rough guess at the import eta
Diffstat (limited to 'eth/downloader/downloader.go')
-rw-r--r--eth/downloader/downloader.go15
1 files changed, 13 insertions, 2 deletions
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index efb94e5e3..c3234ecb1 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -79,7 +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
importLock sync.Mutex
// Callbacks
@@ -126,19 +128,25 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloa
}
// Stats retrieves the current status of the downloader.
-func (d *Downloader) Stats() (pending int, cached int, importing int) {
+func (d *Downloader) Stats() (pending int, cached int, importing int, estimate time.Duration) {
// Fetch the download status
pending, cached = d.queue.Size()
- // Generate the import status
+ // Figure out the import progress
d.importLock.Lock()
defer d.importLock.Unlock()
for len(d.importQueue) > 0 && d.hasBlock(d.importQueue[0]) {
d.importQueue = d.importQueue[1:]
+ d.importDone++
}
importing = len(d.importQueue)
+ // Make an estimate on the total sync
+ estimate = 0
+ if d.importDone > 0 {
+ estimate = time.Since(d.importStart) / time.Duration(d.importDone) * time.Duration(pending+cached+importing)
+ }
return
}
@@ -226,7 +234,9 @@ func (d *Downloader) TakeBlocks() []*Block {
hashes[i] = block.RawBlock.Hash()
}
d.importLock.Lock()
+ d.importStart = time.Now()
d.importQueue = hashes
+ d.importDone = 0
d.importLock.Unlock()
}
return blocks
@@ -287,6 +297,7 @@ func (d *Downloader) Cancel() bool {
d.importLock.Lock()
d.importQueue = nil
+ d.importDone = 0
d.importLock.Unlock()
return true