aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-06-10 06:20:35 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-06-10 06:20:35 +0800
commitb3d5ce7d48426bbe9269f3ea89029187cf939398 (patch)
treecc01bd95826bfc833a68951cb1447198612a5940
parente972a116acb8755d9d70ad271cae2918869dcc3b (diff)
downloaddexon-b3d5ce7d48426bbe9269f3ea89029187cf939398.tar.gz
dexon-b3d5ce7d48426bbe9269f3ea89029187cf939398.tar.zst
dexon-b3d5ce7d48426bbe9269f3ea89029187cf939398.zip
cmd/geth, eth/downloader: collect and report import progress too
-rw-r--r--cmd/geth/admin.go8
-rw-r--r--eth/downloader/downloader.go39
2 files changed, 39 insertions, 8 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go
index 13d10de32..ea8a70923 100644
--- a/cmd/geth/admin.go
+++ b/cmd/geth/admin.go
@@ -51,7 +51,7 @@ func (js *jsre) adminBindings() {
admin.Set("import", js.importChain)
admin.Set("export", js.exportChain)
admin.Set("verbosity", js.verbosity)
- admin.Set("progress", js.downloadProgress)
+ admin.Set("progress", js.syncProgress)
admin.Set("setSolc", js.setSolc)
admin.Set("contractInfo", struct{}{})
@@ -324,9 +324,9 @@ func (js *jsre) setHead(call otto.FunctionCall) otto.Value {
return otto.UndefinedValue()
}
-func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
- pending, cached := js.ethereum.Downloader().Stats()
- v, _ := call.Otto.ToValue(map[string]interface{}{"pending": pending, "cached": cached})
+func (js *jsre) syncProgress(call otto.FunctionCall) otto.Value {
+ pending, cached, importing := js.ethereum.Downloader().Stats()
+ v, _ := call.Otto.ToValue(map[string]interface{}{"pending": pending, "cached": cached, "importing": importing})
return v
}
diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go
index 29b627771..efb94e5e3 100644
--- a/eth/downloader/downloader.go
+++ b/eth/downloader/downloader.go
@@ -78,6 +78,10 @@ type Downloader struct {
checks map[common.Hash]*crossCheck // Pending cross checks to verify a hash chain
banned *set.Set // Set of hashes we've received and banned
+ // Statistics
+ importQueue []common.Hash // Hashes of the previously taken blocks to check import progress
+ importLock sync.Mutex
+
// Callbacks
hasBlock hashCheckFn
getBlock getBlockFn
@@ -121,8 +125,21 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloa
return downloader
}
-func (d *Downloader) Stats() (current int, max int) {
- return d.queue.Size()
+// Stats retrieves the current status of the downloader.
+func (d *Downloader) Stats() (pending int, cached int, importing int) {
+ // Fetch the download status
+ pending, cached = d.queue.Size()
+
+ // Generate the import status
+ d.importLock.Lock()
+ defer d.importLock.Unlock()
+
+ for len(d.importQueue) > 0 && d.hasBlock(d.importQueue[0]) {
+ d.importQueue = d.importQueue[1:]
+ }
+ importing = len(d.importQueue)
+
+ return
}
// Synchronising returns the state of the downloader
@@ -202,7 +219,17 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
// TakeBlocks takes blocks from the queue and yields them to the caller.
func (d *Downloader) TakeBlocks() []*Block {
- return d.queue.TakeBlocks()
+ 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.importQueue = hashes
+ d.importLock.Unlock()
+ }
+ return blocks
}
// Has checks if the downloader knows about a particular hash, meaning that its
@@ -255,9 +282,13 @@ func (d *Downloader) Cancel() bool {
}
d.cancelLock.Unlock()
- // reset the queue
+ // Reset the queue and import statistics
d.queue.Reset()
+ d.importLock.Lock()
+ d.importQueue = nil
+ d.importLock.Unlock()
+
return true
}