aboutsummaryrefslogtreecommitdiffstats
path: root/miner/agent.go
diff options
context:
space:
mode:
authorgary rong <garyrong0905@gmail.com>2018-08-06 17:55:44 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-06 17:55:44 +0800
commit941018b570aef77f1a47197a88e7a0b533b718f7 (patch)
tree1155be1b294b115d49dc4e04865caa338802ccf9 /miner/agent.go
parenta72ba5a55be3abb1be85126838ee0b4a9c475be4 (diff)
downloadgo-tangerine-941018b570aef77f1a47197a88e7a0b533b718f7.tar
go-tangerine-941018b570aef77f1a47197a88e7a0b533b718f7.tar.gz
go-tangerine-941018b570aef77f1a47197a88e7a0b533b718f7.tar.bz2
go-tangerine-941018b570aef77f1a47197a88e7a0b533b718f7.tar.lz
go-tangerine-941018b570aef77f1a47197a88e7a0b533b718f7.tar.xz
go-tangerine-941018b570aef77f1a47197a88e7a0b533b718f7.tar.zst
go-tangerine-941018b570aef77f1a47197a88e7a0b533b718f7.zip
miner: seperate state, receipts for different mining work (#17323)
Diffstat (limited to 'miner/agent.go')
-rw-r--r--miner/agent.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/miner/agent.go b/miner/agent.go
index 95d835bd7..e922ea153 100644
--- a/miner/agent.go
+++ b/miner/agent.go
@@ -27,10 +27,10 @@ import (
type CpuAgent struct {
mu sync.Mutex
- workCh chan *Work
+ taskCh chan *Package
+ returnCh chan<- *Package
stop chan struct{}
quitCurrentOp chan struct{}
- returnCh chan<- *Result
chain consensus.ChainReader
engine consensus.Engine
@@ -43,13 +43,17 @@ func NewCpuAgent(chain consensus.ChainReader, engine consensus.Engine) *CpuAgent
chain: chain,
engine: engine,
stop: make(chan struct{}, 1),
- workCh: make(chan *Work, 1),
+ taskCh: make(chan *Package, 1),
}
return agent
}
-func (self *CpuAgent) Work() chan<- *Work { return self.workCh }
-func (self *CpuAgent) SetReturnCh(ch chan<- *Result) { self.returnCh = ch }
+func (self *CpuAgent) AssignTask(p *Package) {
+ if atomic.LoadInt32(&self.started) == 1 {
+ self.taskCh <- p
+ }
+}
+func (self *CpuAgent) DeliverTo(ch chan<- *Package) { self.returnCh = ch }
func (self *CpuAgent) Start() {
if !atomic.CompareAndSwapInt32(&self.started, 0, 1) {
@@ -67,7 +71,7 @@ done:
// Empty work channel
for {
select {
- case <-self.workCh:
+ case <-self.taskCh:
default:
break done
}
@@ -78,13 +82,13 @@ func (self *CpuAgent) update() {
out:
for {
select {
- case work := <-self.workCh:
+ case p := <-self.taskCh:
self.mu.Lock()
if self.quitCurrentOp != nil {
close(self.quitCurrentOp)
}
self.quitCurrentOp = make(chan struct{})
- go self.mine(work, self.quitCurrentOp)
+ go self.mine(p, self.quitCurrentOp)
self.mu.Unlock()
case <-self.stop:
self.mu.Lock()
@@ -98,10 +102,11 @@ out:
}
}
-func (self *CpuAgent) mine(work *Work, stop <-chan struct{}) {
- if result, err := self.engine.Seal(self.chain, work.Block, stop); result != nil {
- log.Info("Successfully sealed new block", "number", result.Number(), "hash", result.Hash())
- self.returnCh <- &Result{work, result}
+func (self *CpuAgent) mine(p *Package, stop <-chan struct{}) {
+ var err error
+ if p.Block, err = self.engine.Seal(self.chain, p.Block, stop); p.Block != nil {
+ log.Info("Successfully sealed new block", "number", p.Block.Number(), "hash", p.Block.Hash())
+ self.returnCh <- p
} else {
if err != nil {
log.Warn("Block sealing failed", "err", err)