Skip to content

Commit 5dd56bb

Browse files
committed
geth: admin download status
1 parent 2c1a6a3 commit 5dd56bb

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎cmd/geth/admin.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func (js *jsre) adminBindings() {
3434
admin.Set("export", js.exportChain)
3535
admin.Set("verbosity", js.verbosity)
3636
admin.Set("backtrace", js.backtrace)
37+
admin.Set("progress", js.downloadProgress)
3738

3839
admin.Set("miner", struct{}{})
3940
t, _ = admin.Get("miner")
@@ -51,6 +52,12 @@ func (js *jsre) adminBindings() {
5152
debug.Set("getBlockRlp", js.getBlockRlp)
5253
}
5354

55+
func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
56+
current, max := js.ethereum.Downloader().Stats()
57+
58+
return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
59+
}
60+
5461
func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
5562
var block *types.Block
5663
if len(call.ArgumentList) > 0 {

‎eth/downloader/downloader.go‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ type chainInsertFn func(types.Blocks) error
4141
type hashIterFn func() (common.Hash, error)
4242
type currentTdFn func() *big.Int
4343

44+
type blockPack struct {
45+
peerId string
46+
blocks []*types.Block
47+
}
48+
49+
type syncPack struct {
50+
peer *peer
51+
hash common.Hash
52+
ignoreInitial bool
53+
}
54+
4455
type Downloader struct {
4556
mu sync.RWMutex
4657
queue *queue
@@ -65,17 +76,6 @@ type Downloader struct {
6576
quit chan struct{}
6677
}
6778

68-
type blockPack struct {
69-
peerId string
70-
blocks []*types.Block
71-
}
72-
73-
type syncPack struct {
74-
peer *peer
75-
hash common.Hash
76-
ignoreInitial bool
77-
}
78-
7979
func New(hasBlock hashCheckFn, insertChain chainInsertFn, currentTd currentTdFn) *Downloader {
8080
downloader := &Downloader{
8181
queue: newqueue(),
@@ -95,6 +95,10 @@ func New(hasBlock hashCheckFn, insertChain chainInsertFn, currentTd currentTdFn)
9595
return downloader
9696
}
9797

98+
func (d *Downloader) Stats() (current int, max int) {
99+
return d.queue.blockHashes.Size(), d.queue.fetchPool.Size() + d.queue.hashPool.Size()
100+
}
101+
98102
func (d *Downloader) RegisterPeer(id string, td *big.Int, hash common.Hash, getHashes hashFetcherFn, getBlocks blockFetcherFn) error {
99103
d.mu.Lock()
100104
defer d.mu.Unlock()

0 commit comments

Comments
 (0)