From 31bcd52d4b63dbb54465604526a88d6abbb85f44 Mon Sep 17 00:00:00 2001 From: rjl493456442 Date: Thu, 26 Apr 2018 16:56:33 +0800 Subject: [PATCH] consensus, internal: add getHashrate API for ethash --- consensus/ethash/api.go | 5 +++++ consensus/ethash/sealer.go | 2 +- internal/web3ext/web3ext.go | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/consensus/ethash/api.go b/consensus/ethash/api.go index 2e5c2c8f2d..1d648b82e2 100644 --- a/consensus/ethash/api.go +++ b/consensus/ethash/api.go @@ -97,3 +97,8 @@ func (api *API) SubmitHashRate(rate hexutil.Uint64, id common.Hash) bool { return true } + +// GetHashrate returns the current hashrate for local CPU miner and remote miner. +func (api *API) GetHashrate() uint64 { + return uint64(api.ethash.Hashrate()) +} diff --git a/consensus/ethash/sealer.go b/consensus/ethash/sealer.go index a843fab672..539e783a6c 100644 --- a/consensus/ethash/sealer.go +++ b/consensus/ethash/sealer.go @@ -33,7 +33,7 @@ import ( ) var ( - errNoMiningWork = errors.New("no mining work available yet, don't panic") + errNoMiningWork = errors.New("no mining work available yet") errInvalidSealResult = errors.New("invalid or stale proof-of-work solution") ) diff --git a/internal/web3ext/web3ext.go b/internal/web3ext/web3ext.go index 3364f41eb7..c2e0cd3f5d 100644 --- a/internal/web3ext/web3ext.go +++ b/internal/web3ext/web3ext.go @@ -119,6 +119,11 @@ web3._extend({ call: 'ethash_getWork', params: 0 }), + new web3._extend.Method({ + name: 'getHashrate', + call: 'ethash_getHashrate', + params: 0 + }), new web3._extend.Method({ name: 'submitWork', call: 'ethash_submitWork',