aboutsummaryrefslogtreecommitdiffstats
path: root/eth/api.go
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2018-08-03 16:33:37 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-03 16:33:37 +0800
commit51db5975cc5fb88db6a0dba1826b534fd4df29d7 (patch)
tree930f5a66d52c9bdcecd5596d7630fb48b0982cfd /eth/api.go
parent70176cda0eedbb4ec9cde867e8f6cde63efa5a12 (diff)
downloadgo-tangerine-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar
go-tangerine-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar.gz
go-tangerine-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar.bz2
go-tangerine-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar.lz
go-tangerine-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar.xz
go-tangerine-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar.zst
go-tangerine-51db5975cc5fb88db6a0dba1826b534fd4df29d7.zip
consensus/ethash: move remote agent logic to ethash internal (#15853)
* consensus/ethash: start remote ggoroutine to handle remote mining * consensus/ethash: expose remote miner api * consensus/ethash: expose submitHashrate api * miner, ethash: push empty block to sealer without waiting execution * consensus, internal: add getHashrate API for ethash * consensus: add three method for consensus interface * miner: expose consensus engine running status to miner * eth, miner: specify etherbase when miner created * miner: commit new work when consensus engine is started * consensus, miner: fix some logics * all: delete useless interfaces * consensus: polish a bit
Diffstat (limited to 'eth/api.go')
-rw-r--r--eth/api.go46
1 files changed, 5 insertions, 41 deletions
diff --git a/eth/api.go b/eth/api.go
index 0b6da456f..c1fbcb6d4 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -34,7 +34,6 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log"
- "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
@@ -70,16 +69,12 @@ func (api *PublicEthereumAPI) Hashrate() hexutil.Uint64 {
// PublicMinerAPI provides an API to control the miner.
// It offers only methods that operate on data that pose no security risk when it is publicly accessible.
type PublicMinerAPI struct {
- e *Ethereum
- agent *miner.RemoteAgent
+ e *Ethereum
}
// NewPublicMinerAPI create a new PublicMinerAPI instance.
func NewPublicMinerAPI(e *Ethereum) *PublicMinerAPI {
- agent := miner.NewRemoteAgent(e.BlockChain(), e.Engine())
- e.Miner().Register(agent)
-
- return &PublicMinerAPI{e, agent}
+ return &PublicMinerAPI{e}
}
// Mining returns an indication if this node is currently mining.
@@ -87,37 +82,6 @@ func (api *PublicMinerAPI) Mining() bool {
return api.e.IsMining()
}
-// SubmitWork can be used by external miner to submit their POW solution. It returns an indication if the work was
-// accepted. Note, this is not an indication if the provided work was valid!
-func (api *PublicMinerAPI) SubmitWork(nonce types.BlockNonce, solution, digest common.Hash) bool {
- return api.agent.SubmitWork(nonce, digest, solution)
-}
-
-// GetWork returns a work package for external miner. The work package consists of 3 strings
-// result[0], 32 bytes hex encoded current block header pow-hash
-// result[1], 32 bytes hex encoded seed hash used for DAG
-// result[2], 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
-func (api *PublicMinerAPI) GetWork() ([3]string, error) {
- if !api.e.IsMining() {
- if err := api.e.StartMining(false); err != nil {
- return [3]string{}, err
- }
- }
- work, err := api.agent.GetWork()
- if err != nil {
- return work, fmt.Errorf("mining not ready: %v", err)
- }
- return work, nil
-}
-
-// SubmitHashrate can be used for remote miners to submit their hash rate. This enables the node to report the combined
-// hash rate of all miners which submit work through this node. It accepts the miner hash rate and an identifier which
-// must be unique between nodes.
-func (api *PublicMinerAPI) SubmitHashrate(hashrate hexutil.Uint64, id common.Hash) bool {
- api.agent.SubmitHashrate(id, uint64(hashrate))
- return true
-}
-
// PrivateMinerAPI provides private RPC methods to control the miner.
// These methods can be abused by external users and must be considered insecure for use by untrusted users.
type PrivateMinerAPI struct {
@@ -132,7 +96,8 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI {
// Start the miner with the given number of threads. If threads is nil the number
// of workers started is equal to the number of logical CPUs that are usable by
// this process. If mining is already running, this method adjust the number of
-// threads allowed to use.
+// threads allowed to use and updates the minimum price required by the transaction
+// pool.
func (api *PrivateMinerAPI) Start(threads *int) error {
// Set the number of threads if the seal engine supports it
if threads == nil {
@@ -153,7 +118,6 @@ func (api *PrivateMinerAPI) Start(threads *int) error {
api.e.lock.RLock()
price := api.e.gasPrice
api.e.lock.RUnlock()
-
api.e.txPool.SetGasPrice(price)
return api.e.StartMining(true)
}
@@ -198,7 +162,7 @@ func (api *PrivateMinerAPI) SetEtherbase(etherbase common.Address) bool {
// GetHashrate returns the current hashrate of the miner.
func (api *PrivateMinerAPI) GetHashrate() uint64 {
- return uint64(api.e.miner.HashRate())
+ return api.e.miner.HashRate()
}
// PrivateAdminAPI is the collection of Ethereum full node-related APIs