diff options
author | gary rong <garyrong0905@gmail.com> | 2018-08-03 16:33:37 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2018-08-03 16:33:37 +0800 |
commit | 51db5975cc5fb88db6a0dba1826b534fd4df29d7 (patch) | |
tree | 930f5a66d52c9bdcecd5596d7630fb48b0982cfd /miner/agent.go | |
parent | 70176cda0eedbb4ec9cde867e8f6cde63efa5a12 (diff) | |
download | dexon-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar.gz dexon-51db5975cc5fb88db6a0dba1826b534fd4df29d7.tar.zst dexon-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 'miner/agent.go')
-rw-r--r-- | miner/agent.go | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/miner/agent.go b/miner/agent.go index e3cebbd2e..95d835bd7 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -18,7 +18,6 @@ package miner import ( "sync" - "sync/atomic" "github.com/ethereum/go-ethereum/consensus" @@ -36,24 +35,31 @@ type CpuAgent struct { chain consensus.ChainReader engine consensus.Engine - isMining int32 // isMining indicates whether the agent is currently mining + started int32 // started indicates whether the agent is currently started } func NewCpuAgent(chain consensus.ChainReader, engine consensus.Engine) *CpuAgent { - miner := &CpuAgent{ + agent := &CpuAgent{ chain: chain, engine: engine, stop: make(chan struct{}, 1), workCh: make(chan *Work, 1), } - return miner + return agent } func (self *CpuAgent) Work() chan<- *Work { return self.workCh } func (self *CpuAgent) SetReturnCh(ch chan<- *Result) { self.returnCh = ch } +func (self *CpuAgent) Start() { + if !atomic.CompareAndSwapInt32(&self.started, 0, 1) { + return // agent already started + } + go self.update() +} + func (self *CpuAgent) Stop() { - if !atomic.CompareAndSwapInt32(&self.isMining, 1, 0) { + if !atomic.CompareAndSwapInt32(&self.started, 1, 0) { return // agent already stopped } self.stop <- struct{}{} @@ -68,13 +74,6 @@ done: } } -func (self *CpuAgent) Start() { - if !atomic.CompareAndSwapInt32(&self.isMining, 0, 1) { - return // agent already started - } - go self.update() -} - func (self *CpuAgent) update() { out: for { @@ -110,10 +109,3 @@ func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) { self.returnCh <- nil } } - -func (self *CpuAgent) GetHashRate() int64 { - if pow, ok := self.engine.(consensus.PoW); ok { - return int64(pow.Hashrate()) - } - return 0 -} |