aboutsummaryrefslogtreecommitdiffstats
path: root/miner
diff options
context:
space:
mode:
Diffstat (limited to 'miner')
-rw-r--r--miner/worker.go75
1 files changed, 30 insertions, 45 deletions
diff --git a/miner/worker.go b/miner/worker.go
index b48db2a30..bf24970f5 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -125,8 +125,6 @@ type worker struct {
// atomic status counters
mining int32
atWork int32
-
- fullValidation bool
}
func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase common.Address, eth Backend, mux *event.TypeMux) *worker {
@@ -146,7 +144,6 @@ func newWorker(config *params.ChainConfig, engine consensus.Engine, coinbase com
coinbase: coinbase,
agents: make(map[Agent]struct{}),
unconfirmed: newUnconfirmedBlocks(eth.BlockChain(), miningLogAtDepth),
- fullValidation: false,
}
// Subscribe TxPreEvent for tx pool
worker.txSub = eth.TxPool().SubscribeTxPreEvent(worker.txCh)
@@ -297,50 +294,38 @@ func (self *worker) wait() {
block := result.Block
work := result.Work
- if self.fullValidation {
- if _, err := self.chain.InsertChain(types.Blocks{block}); err != nil {
- log.Error("Mined invalid block", "err", err)
- continue
- }
- go self.mux.Post(core.NewMinedBlockEvent{Block: block})
- } else {
- // Update the block hash in all logs since it is now available and not when the
- // receipt/log of individual transactions were created.
- for _, r := range work.receipts {
- for _, l := range r.Logs {
- l.BlockHash = block.Hash()
- }
- }
- for _, log := range work.state.Logs() {
- log.BlockHash = block.Hash()
- }
- stat, err := self.chain.WriteBlockAndState(block, work.receipts, work.state)
- if err != nil {
- log.Error("Failed writing block to chain", "err", err)
- continue
- }
-
- // check if canon block and write transactions
- if stat == core.CanonStatTy {
- // implicit by posting ChainHeadEvent
- mustCommitNewWork = false
+ // Update the block hash in all logs since it is now available and not when the
+ // receipt/log of individual transactions were created.
+ for _, r := range work.receipts {
+ for _, l := range r.Logs {
+ l.BlockHash = block.Hash()
}
- // broadcast before waiting for validation
- go func(block *types.Block, logs []*types.Log, receipts []*types.Receipt) {
- self.mux.Post(core.NewMinedBlockEvent{Block: block})
- var (
- events []interface{}
- coalescedLogs []*types.Log
- )
- events = append(events, core.ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})
- if stat == core.CanonStatTy {
- events = append(events, core.ChainHeadEvent{Block: block})
- coalescedLogs = logs
- }
- // post blockchain events
- self.chain.PostChainEvents(events, coalescedLogs)
- }(block, work.state.Logs(), work.receipts)
}
+ for _, log := range work.state.Logs() {
+ log.BlockHash = block.Hash()
+ }
+ stat, err := self.chain.WriteBlockAndState(block, work.receipts, work.state)
+ if err != nil {
+ log.Error("Failed writing block to chain", "err", err)
+ continue
+ }
+ // check if canon block and write transactions
+ if stat == core.CanonStatTy {
+ // implicit by posting ChainHeadEvent
+ mustCommitNewWork = false
+ }
+ // Broadcast the block and announce chain insertion event
+ self.mux.Post(core.NewMinedBlockEvent{Block: block})
+ var (
+ events []interface{}
+ logs = work.state.Logs()
+ )
+ events = append(events, core.ChainEvent{Block: block, Hash: block.Hash(), Logs: logs})
+ if stat == core.CanonStatTy {
+ events = append(events, core.ChainHeadEvent{Block: block})
+ }
+ self.chain.PostChainEvents(events, logs)
+
// Insert the block into the set of pending ones to wait for confirmations
self.unconfirmed.Insert(block.NumberU64(), block.Hash())