aboutsummaryrefslogtreecommitdiffstats
path: root/miner
diff options
context:
space:
mode:
Diffstat (limited to 'miner')
-rw-r--r--miner/miner.go2
-rw-r--r--miner/worker.go31
2 files changed, 19 insertions, 14 deletions
diff --git a/miner/miner.go b/miner/miner.go
index b550ed6d6..769db79d1 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -66,7 +66,7 @@ func (self *Miner) update() {
events := self.mux.Subscribe(downloader.StartEvent{}, downloader.DoneEvent{}, downloader.FailedEvent{})
out:
for ev := range events.Chan() {
- switch ev.(type) {
+ switch ev.Data.(type) {
case downloader.StartEvent:
atomic.StoreInt32(&self.canStart, 0)
if self.Mining() {
diff --git a/miner/worker.go b/miner/worker.go
index 22d0b9b6e..43f6f9909 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
+ "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger"
@@ -99,7 +100,7 @@ type worker struct {
pow pow.PoW
eth core.Backend
- chain *core.ChainManager
+ chain *core.BlockChain
proc *core.BlockProcessor
chainDb ethdb.Database
@@ -130,7 +131,7 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker {
chainDb: eth.ChainDb(),
recv: make(chan *Result, resultQueueSize),
gasPrice: new(big.Int),
- chain: eth.ChainManager(),
+ chain: eth.BlockChain(),
proc: eth.BlockProcessor(),
possibleUncles: make(map[common.Hash]*types.Block),
coinbase: coinbase,
@@ -214,13 +215,20 @@ func (self *worker) register(agent Agent) {
}
func (self *worker) update() {
- events := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
+ eventSub := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
+ defer eventSub.Unsubscribe()
-out:
+ eventCh := eventSub.Chan()
for {
select {
- case event := <-events.Chan():
- switch ev := event.(type) {
+ case event, ok := <-eventCh:
+ if !ok {
+ // Event subscription closed, set the channel to nil to stop spinning
+ eventCh = nil
+ continue
+ }
+ // A real event arrived, process interesting content
+ switch ev := event.Data.(type) {
case core.ChainHeadEvent:
self.commitNewWork()
case core.ChainSideEvent:
@@ -236,11 +244,9 @@ out:
}
}
case <-self.quit:
- break out
+ return
}
}
-
- events.Unsubscribe()
}
func newLocalMinedBlock(blockNumber uint64, prevMinedBlocks *uint64RingBuffer) (minedBlocks *uint64RingBuffer) {
@@ -266,7 +272,6 @@ func (self *worker) wait() {
block := result.Block
work := result.Work
- work.state.Sync()
if self.fullValidation {
if _, err := self.chain.InsertChain(types.Blocks{block}); err != nil {
glog.V(logger.Error).Infoln("mining err", err)
@@ -274,6 +279,7 @@ func (self *worker) wait() {
}
go self.mux.Post(core.NewMinedBlockEvent{block})
} else {
+ work.state.Commit()
parent := self.chain.GetBlock(block.ParentHash())
if parent == nil {
glog.V(logger.Error).Infoln("Invalid block found during mining")
@@ -298,7 +304,7 @@ func (self *worker) wait() {
}
// broadcast before waiting for validation
- go func(block *types.Block, logs state.Logs, receipts []*types.Receipt) {
+ go func(block *types.Block, logs vm.Logs, receipts []*types.Receipt) {
self.mux.Post(core.NewMinedBlockEvent{block})
self.mux.Post(core.ChainEvent{block, block.Hash(), logs})
if stat == core.CanonStatTy {
@@ -528,8 +534,7 @@ func (self *worker) commitNewWork() {
if atomic.LoadInt32(&self.mining) == 1 {
// commit state root after all state transitions.
core.AccumulateRewards(work.state, header, uncles)
- work.state.SyncObjects()
- header.Root = work.state.Root()
+ header.Root = work.state.IntermediateRoot()
}
// create the new block whose nonce will be mined.