aboutsummaryrefslogtreecommitdiffstats
path: root/ethminer
diff options
context:
space:
mode:
Diffstat (limited to 'ethminer')
-rw-r--r--ethminer/miner.go33
1 files changed, 17 insertions, 16 deletions
diff --git a/ethminer/miner.go b/ethminer/miner.go
index 43a6f302d..57cf0cd57 100644
--- a/ethminer/miner.go
+++ b/ethminer/miner.go
@@ -85,11 +85,7 @@ func (miner *Miner) listener() {
for {
select {
- case event, isopen := <-miner.events.Chan():
- if !isopen {
- return
- }
-
+ case event := <-miner.events.Chan():
switch event := event.(type) {
case ethchain.NewBlockEvent:
miner.stopMining()
@@ -114,16 +110,13 @@ func (miner *Miner) listener() {
}
}
miner.txs = newtxs
-
- // Setup a fresh state to mine on
- //miner.block = miner.ethereum.ChainManager().NewBlock(miner.coinbase, miner.txs)
-
} else {
if bytes.Compare(block.PrevHash, miner.ethereum.ChainManager().CurrentBlock.PrevHash) == 0 {
logger.Infoln("Adding uncle block")
miner.uncles = append(miner.uncles, block)
}
}
+ miner.startMining()
case ethchain.TxPreEvent:
miner.stopMining()
@@ -133,6 +126,8 @@ func (miner *Miner) listener() {
if found = bytes.Compare(ctx.Hash(), event.Tx.Hash()) == 0; found {
break
}
+
+ miner.startMining()
}
if found == false {
// Undo all previous commits
@@ -157,8 +152,12 @@ func (miner *Miner) startMining() {
}
func (miner *Miner) stopMining() {
- close(miner.powQuitChan)
- <-miner.powDone
+ println("stop mining")
+ _, isopen := <-miner.powQuitChan
+ if isopen {
+ close(miner.powQuitChan)
+ }
+ //<-miner.powDone
}
func (self *Miner) mineNewBlock() {
@@ -185,10 +184,9 @@ func (self *Miner) mineNewBlock() {
}
self.ethereum.TxPool().RemoveSet(erroneous)
self.txs = append(txs, unhandledTxs...)
- self.block.SetTxHash(receipts)
- // Set the transactions to the block so the new SHA3 can be calculated
- self.block.SetReceipts(receipts, txs)
+ self.block.SetReceipts(receipts)
+ self.block.SetTransactions(txs)
// Accumulate the rewards included for this block
stateManager.AccumelateRewards(self.block.State(), self.block, parent)
@@ -201,7 +199,7 @@ func (self *Miner) mineNewBlock() {
nonce := self.pow.Search(self.block, self.powQuitChan)
if nonce != nil {
self.block.Nonce = nonce
- err := self.ethereum.StateManager().Process(self.block, false)
+ err := self.ethereum.StateManager().Process(self.block)
if err != nil {
logger.Infoln(err)
} else {
@@ -210,7 +208,10 @@ func (self *Miner) mineNewBlock() {
logger.Infoln(self.block)
// Gather the new batch of transactions currently in the tx pool
self.txs = self.ethereum.TxPool().CurrentTransactions()
+ self.ethereum.EventMux().Post(ethchain.NewBlockEvent{self.block})
}
+
+ // Continue mining on the next block
+ self.startMining()
}
- self.powDone <- struct{}{}
}