forked from cerc-io/plugeth
Fixed a few issues in the miner and updated hash rate title
* Sometimes old nonces were set by "old" agents * Added the hash rate to the miner
This commit is contained in:
parent
8305d409d2
commit
8a0f23915e
@ -289,6 +289,7 @@ ApplicationWindow {
|
|||||||
styleColor: "#797979"
|
styleColor: "#797979"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
Label {
|
Label {
|
||||||
//y: 6
|
//y: 6
|
||||||
objectName: "miningLabel"
|
objectName: "miningLabel"
|
||||||
@ -307,6 +308,7 @@ ApplicationWindow {
|
|||||||
anchors.right: peerGroup.left
|
anchors.right: peerGroup.left
|
||||||
anchors.rightMargin: 5
|
anchors.rightMargin: 5
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
ProgressBar {
|
ProgressBar {
|
||||||
visible: false
|
visible: false
|
||||||
@ -1101,4 +1103,4 @@ ApplicationWindow {
|
|||||||
addrField.focus = true
|
addrField.focus = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,30 @@ Rectangle {
|
|||||||
|
|
||||||
color: "#00000000"
|
color: "#00000000"
|
||||||
|
|
||||||
|
Label {
|
||||||
|
visible: false
|
||||||
|
id: lastBlockLabel
|
||||||
|
objectName: "lastBlockLabel"
|
||||||
|
text: "---"
|
||||||
|
font.pixelSize: 10
|
||||||
|
anchors.right: peerGroup.left
|
||||||
|
anchors.rightMargin: 5
|
||||||
|
onTextChanged: {
|
||||||
|
//menuItem.secondaryTitle = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Label {
|
||||||
|
objectName: "miningLabel"
|
||||||
|
visible: false
|
||||||
|
font.pixelSize: 10
|
||||||
|
anchors.right: lastBlockLabel.left
|
||||||
|
anchors.rightMargin: 5
|
||||||
|
onTextChanged: {
|
||||||
|
menuItem.secondaryTitle = text
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
spacing: 10
|
spacing: 10
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
@ -9,7 +9,7 @@ type CpuMiner struct {
|
|||||||
c chan *types.Block
|
c chan *types.Block
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
quitCurrentOp chan struct{}
|
quitCurrentOp chan struct{}
|
||||||
returnCh chan<- []byte
|
returnCh chan<- Work
|
||||||
|
|
||||||
index int
|
index int
|
||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
@ -28,9 +28,9 @@ func NewCpuMiner(index int, pow pow.PoW) *CpuMiner {
|
|||||||
return miner
|
return miner
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *CpuMiner) Work() chan<- *types.Block { return self.c }
|
func (self *CpuMiner) Work() chan<- *types.Block { return self.c }
|
||||||
func (self *CpuMiner) Pow() pow.PoW { return self.pow }
|
func (self *CpuMiner) Pow() pow.PoW { return self.pow }
|
||||||
func (self *CpuMiner) SetNonceCh(ch chan<- []byte) { self.returnCh = ch }
|
func (self *CpuMiner) SetNonceCh(ch chan<- Work) { self.returnCh = ch }
|
||||||
|
|
||||||
func (self *CpuMiner) Stop() {
|
func (self *CpuMiner) Stop() {
|
||||||
close(self.quit)
|
close(self.quit)
|
||||||
@ -42,7 +42,6 @@ out:
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case block := <-self.c:
|
case block := <-self.c:
|
||||||
minerlogger.Infof("miner[%d] got block\n", self.index)
|
|
||||||
// make sure it's open
|
// make sure it's open
|
||||||
self.quitCurrentOp <- struct{}{}
|
self.quitCurrentOp <- struct{}{}
|
||||||
|
|
||||||
@ -66,9 +65,9 @@ done:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *CpuMiner) mine(block *types.Block) {
|
func (self *CpuMiner) mine(block *types.Block) {
|
||||||
minerlogger.Infof("started agent[%d]. mining...\n", self.index)
|
minerlogger.Infof("(re)started agent[%d]. mining...\n", self.index)
|
||||||
nonce := self.pow.Search(block, self.quitCurrentOp)
|
nonce := self.pow.Search(block, self.quitCurrentOp)
|
||||||
if nonce != nil {
|
if nonce != nil {
|
||||||
self.returnCh <- nonce
|
self.returnCh <- Work{block.Number().Uint64(), nonce}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,22 +38,16 @@ func (self *Miner) Mining() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) Start() {
|
func (self *Miner) Start() {
|
||||||
|
self.mining = true
|
||||||
|
|
||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
|
||||||
self.worker.commitNewWork()
|
self.worker.commitNewWork()
|
||||||
|
|
||||||
/*
|
|
||||||
timer := time.NewTicker(time.Second)
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case <-timer.C:
|
|
||||||
fmt.Printf("%d workers. %d/Khash\n", len(self.worker.agents), self.HashRate())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Miner) Stop() {
|
func (self *Miner) Stop() {
|
||||||
|
self.mining = false
|
||||||
|
|
||||||
self.worker.stop()
|
self.worker.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,16 +41,21 @@ func env(block *types.Block, eth *eth.Ethereum) *environment {
|
|||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Work struct {
|
||||||
|
Number uint64
|
||||||
|
Nonce []byte
|
||||||
|
}
|
||||||
|
|
||||||
type Agent interface {
|
type Agent interface {
|
||||||
Work() chan<- *types.Block
|
Work() chan<- *types.Block
|
||||||
SetNonceCh(chan<- []byte)
|
SetNonceCh(chan<- Work)
|
||||||
Stop()
|
Stop()
|
||||||
Pow() pow.PoW
|
Pow() pow.PoW
|
||||||
}
|
}
|
||||||
|
|
||||||
type worker struct {
|
type worker struct {
|
||||||
agents []Agent
|
agents []Agent
|
||||||
recv chan []byte
|
recv chan Work
|
||||||
mux *event.TypeMux
|
mux *event.TypeMux
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
pow pow.PoW
|
pow pow.PoW
|
||||||
@ -61,13 +66,15 @@ type worker struct {
|
|||||||
coinbase []byte
|
coinbase []byte
|
||||||
|
|
||||||
current *environment
|
current *environment
|
||||||
|
|
||||||
|
mining bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func newWorker(coinbase []byte, eth *eth.Ethereum) *worker {
|
func newWorker(coinbase []byte, eth *eth.Ethereum) *worker {
|
||||||
return &worker{
|
return &worker{
|
||||||
eth: eth,
|
eth: eth,
|
||||||
mux: eth.EventMux(),
|
mux: eth.EventMux(),
|
||||||
recv: make(chan []byte),
|
recv: make(chan Work),
|
||||||
chain: eth.ChainManager(),
|
chain: eth.ChainManager(),
|
||||||
proc: eth.BlockProcessor(),
|
proc: eth.BlockProcessor(),
|
||||||
coinbase: coinbase,
|
coinbase: coinbase,
|
||||||
@ -75,11 +82,17 @@ func newWorker(coinbase []byte, eth *eth.Ethereum) *worker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) start() {
|
func (self *worker) start() {
|
||||||
|
self.mining = true
|
||||||
|
|
||||||
|
self.quit = make(chan struct{})
|
||||||
|
|
||||||
go self.update()
|
go self.update()
|
||||||
go self.wait()
|
go self.wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) stop() {
|
func (self *worker) stop() {
|
||||||
|
self.mining = false
|
||||||
|
|
||||||
close(self.quit)
|
close(self.quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,26 +120,31 @@ out:
|
|||||||
break out
|
break out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
events.Unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) wait() {
|
func (self *worker) wait() {
|
||||||
for {
|
for {
|
||||||
for nonce := range self.recv {
|
for work := range self.recv {
|
||||||
self.current.block.Header().Nonce = nonce
|
if self.current.block.Number().Uint64() == work.Number {
|
||||||
fmt.Println(self.current.block)
|
self.current.block.Header().Nonce = work.Nonce
|
||||||
|
|
||||||
self.chain.InsertChain(types.Blocks{self.current.block})
|
self.chain.InsertChain(types.Blocks{self.current.block})
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *worker) push() {
|
func (self *worker) push() {
|
||||||
self.current.state.Update(ethutil.Big0)
|
if self.mining {
|
||||||
self.current.block.SetRoot(self.current.state.Root())
|
self.current.state.Update(ethutil.Big0)
|
||||||
|
self.current.block.SetRoot(self.current.state.Root())
|
||||||
|
|
||||||
for _, agent := range self.agents {
|
for _, agent := range self.agents {
|
||||||
agent.Work() <- self.current.block
|
agent.Work() <- self.current.block
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user