diff options
-rw-r--r-- | cmd/geth/admin.go | 7 | ||||
-rw-r--r-- | eth/downloader/downloader.go | 26 | ||||
-rw-r--r-- | miner/miner.go | 12 | ||||
-rw-r--r-- | miner/worker.go | 12 |
4 files changed, 30 insertions, 27 deletions
diff --git a/cmd/geth/admin.go b/cmd/geth/admin.go index 2ac155e33..c42e91615 100644 --- a/cmd/geth/admin.go +++ b/cmd/geth/admin.go @@ -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 { diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index c4af5e17b..addcbcc44 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -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() diff --git a/miner/miner.go b/miner/miner.go index a14a195d2..883956370 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -16,9 +16,10 @@ type Miner struct { MinAcceptedGasPrice *big.Int - mining bool - eth core.Backend - pow pow.PoW + threads int + mining bool + eth core.Backend + pow pow.PoW } func New(eth core.Backend, pow pow.PoW, minerThreads int) *Miner { @@ -28,6 +29,7 @@ func New(eth core.Backend, pow pow.PoW, minerThreads int) *Miner { for i := 0; i < minerThreads; i++ { miner.worker.register(NewCpuMiner(i, pow)) } + miner.threads = minerThreads return miner } @@ -40,7 +42,9 @@ func (self *Miner) Start(coinbase common.Address) { self.mining = true self.worker.coinbase = coinbase - self.pow.(*ethash.Ethash).UpdateDAG() + if self.threads > 0 { + self.pow.(*ethash.Ethash).UpdateDAG() + } self.worker.start() diff --git a/miner/worker.go b/miner/worker.go index daabd3db5..63645cd54 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -6,7 +6,6 @@ import ( "sort" "sync" "sync/atomic" - "time" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" @@ -151,8 +150,6 @@ func (self *worker) register(agent Agent) { func (self *worker) update() { events := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{}) - timer := time.NewTicker(2 * time.Second) - out: for { select { @@ -171,15 +168,6 @@ out: } case <-self.quit: break out - case <-timer.C: - if glog.V(logger.Detail) && atomic.LoadInt64(&self.mining) == 1 { - glog.Infoln("Hash rate:", self.HashRate(), "Khash") - } - - // XXX In case all mined a possible uncle - if atomic.LoadInt64(&self.atWork) == 0 && atomic.LoadInt64(&self.mining) == 1 { - self.commitNewWork() - } } } |