diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-09-11 18:13:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-11 18:13:05 +0800 |
commit | 10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223 (patch) | |
tree | 8da6f95a93dcd2774cede13be54aa3079ced7cab /miner | |
parent | 5596b664c4ca5be199bb93f87155fa2c1fa7eab2 (diff) | |
download | dexon-10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223.tar dexon-10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223.tar.gz dexon-10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223.tar.bz2 dexon-10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223.tar.lz dexon-10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223.tar.xz dexon-10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223.tar.zst dexon-10b3f97c9dcc6f3711aa2d3b1bb43e67eb921223.zip |
core: only fire one chain head per batch (#15123)
* core: only fire one chain head per batch
* miner: announce chan events synchronously
Diffstat (limited to 'miner')
-rw-r--r-- | miner/worker.go | 75 |
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()) |