cmd/geth, eth/downloader: rough guess at the import eta
This commit is contained in:
parent
b3d5ce7d48
commit
271fb20ecb
@ -325,8 +325,13 @@ func (js *jsre) setHead(call otto.FunctionCall) otto.Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (js *jsre) syncProgress(call otto.FunctionCall) otto.Value {
|
func (js *jsre) syncProgress(call otto.FunctionCall) otto.Value {
|
||||||
pending, cached, importing := js.ethereum.Downloader().Stats()
|
pending, cached, importing, eta := js.ethereum.Downloader().Stats()
|
||||||
v, _ := call.Otto.ToValue(map[string]interface{}{"pending": pending, "cached": cached, "importing": importing})
|
v, _ := call.Otto.ToValue(map[string]interface{}{
|
||||||
|
"pending": pending,
|
||||||
|
"cached": cached,
|
||||||
|
"importing": importing,
|
||||||
|
"estimate": eta.String(),
|
||||||
|
})
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +79,9 @@ type Downloader struct {
|
|||||||
banned *set.Set // Set of hashes we've received and banned
|
banned *set.Set // Set of hashes we've received and banned
|
||||||
|
|
||||||
// Statistics
|
// 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
|
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
|
importLock sync.Mutex
|
||||||
|
|
||||||
// Callbacks
|
// Callbacks
|
||||||
@ -126,19 +128,25 @@ func New(mux *event.TypeMux, hasBlock hashCheckFn, getBlock getBlockFn) *Downloa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stats retrieves the current status of the downloader.
|
// 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
|
// Fetch the download status
|
||||||
pending, cached = d.queue.Size()
|
pending, cached = d.queue.Size()
|
||||||
|
|
||||||
// Generate the import status
|
// Figure out the import progress
|
||||||
d.importLock.Lock()
|
d.importLock.Lock()
|
||||||
defer d.importLock.Unlock()
|
defer d.importLock.Unlock()
|
||||||
|
|
||||||
for len(d.importQueue) > 0 && d.hasBlock(d.importQueue[0]) {
|
for len(d.importQueue) > 0 && d.hasBlock(d.importQueue[0]) {
|
||||||
d.importQueue = d.importQueue[1:]
|
d.importQueue = d.importQueue[1:]
|
||||||
|
d.importDone++
|
||||||
}
|
}
|
||||||
importing = len(d.importQueue)
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +234,9 @@ func (d *Downloader) TakeBlocks() []*Block {
|
|||||||
hashes[i] = block.RawBlock.Hash()
|
hashes[i] = block.RawBlock.Hash()
|
||||||
}
|
}
|
||||||
d.importLock.Lock()
|
d.importLock.Lock()
|
||||||
|
d.importStart = time.Now()
|
||||||
d.importQueue = hashes
|
d.importQueue = hashes
|
||||||
|
d.importDone = 0
|
||||||
d.importLock.Unlock()
|
d.importLock.Unlock()
|
||||||
}
|
}
|
||||||
return blocks
|
return blocks
|
||||||
@ -287,6 +297,7 @@ func (d *Downloader) Cancel() bool {
|
|||||||
|
|
||||||
d.importLock.Lock()
|
d.importLock.Lock()
|
||||||
d.importQueue = nil
|
d.importQueue = nil
|
||||||
|
d.importDone = 0
|
||||||
d.importLock.Unlock()
|
d.importLock.Unlock()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user