提交 5dd56bb4 编写于 作者: O obscuren

geth: admin download status

上级 2c1a6a34
......@@ -34,6 +34,7 @@ func (js *jsre) adminBindings() {
admin.Set("export", js.exportChain)
admin.Set("verbosity", js.verbosity)
admin.Set("backtrace", js.backtrace)
admin.Set("progress", js.downloadProgress)
admin.Set("miner", struct{}{})
t, _ = admin.Get("miner")
......@@ -51,6 +52,12 @@ func (js *jsre) adminBindings() {
debug.Set("getBlockRlp", js.getBlockRlp)
}
func (js *jsre) downloadProgress(call otto.FunctionCall) otto.Value {
current, max := js.ethereum.Downloader().Stats()
return js.re.ToVal(fmt.Sprintf("%d/%d", current, max))
}
func (js *jsre) getBlockRlp(call otto.FunctionCall) otto.Value {
var block *types.Block
if len(call.ArgumentList) > 0 {
......
......@@ -41,6 +41,17 @@ type chainInsertFn func(types.Blocks) error
type hashIterFn func() (common.Hash, error)
type currentTdFn func() *big.Int
type blockPack struct {
peerId string
blocks []*types.Block
}
type syncPack struct {
peer *peer
hash common.Hash
ignoreInitial bool
}
type Downloader struct {
mu sync.RWMutex
queue *queue
......@@ -65,17 +76,6 @@ type Downloader struct {
quit chan struct{}
}
type blockPack struct {
peerId string
blocks []*types.Block
}
type syncPack struct {
peer *peer
hash common.Hash
ignoreInitial bool
}
func New(hasBlock hashCheckFn, insertChain chainInsertFn, currentTd currentTdFn) *Downloader {
downloader := &Downloader{
queue: newqueue(),
......@@ -95,6 +95,10 @@ func New(hasBlock hashCheckFn, insertChain chainInsertFn, currentTd currentTdFn)
return downloader
}
func (d *Downloader) Stats() (current int, max int) {
return d.queue.blockHashes.Size(), d.queue.fetchPool.Size() + d.queue.hashPool.Size()
}
func (d *Downloader) RegisterPeer(id string, td *big.Int, hash common.Hash, getHashes hashFetcherFn, getBlocks blockFetcherFn) error {
d.mu.Lock()
defer d.mu.Unlock()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册