diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-03 22:50:30 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-03 22:50:30 +0800 |
commit | 1cbab291a9e05c107c8ad37b5436872651009886 (patch) | |
tree | 323eeddeb0c8ed17ba1a9ad382b47af418dd9539 /miner | |
parent | 8181929c9a17b23d8a2eab55b2e8f584fe9b6c50 (diff) | |
parent | 29e2fb38f8e80dfa077d139d8ff563169c644d74 (diff) | |
download | go-tangerine-1cbab291a9e05c107c8ad37b5436872651009886.tar.gz go-tangerine-1cbab291a9e05c107c8ad37b5436872651009886.tar.zst go-tangerine-1cbab291a9e05c107c8ad37b5436872651009886.zip |
Merge pull request #1389 from obscuren/txpool-issues
core, miner: miner header validation, transaction & receipt writing
Diffstat (limited to 'miner')
-rw-r--r-- | miner/worker.go | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/miner/worker.go b/miner/worker.go index 90914ddcb..a23b663f9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -79,9 +79,10 @@ type worker struct { quit chan struct{} pow pow.PoW - eth core.Backend - chain *core.ChainManager - proc *core.BlockProcessor + eth core.Backend + chain *core.ChainManager + proc *core.BlockProcessor + extraDb common.Database coinbase common.Address gasPrice *big.Int @@ -105,6 +106,7 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker { worker := &worker{ eth: eth, mux: eth.EventMux(), + extraDb: eth.ExtraDb(), recv: make(chan *types.Block), gasPrice: new(big.Int), chain: eth.ChainManager(), @@ -233,11 +235,28 @@ func (self *worker) wait() { continue } - _, err := self.chain.WriteBlock(block, false) + parent := self.chain.GetBlock(block.ParentHash()) + if parent == nil { + glog.V(logger.Error).Infoln("Invalid block found during mining") + continue + } + if err := core.ValidateHeader(self.eth.BlockProcessor().Pow, block.Header(), parent, true); err != nil { + glog.V(logger.Error).Infoln("Invalid header on mined block:", err) + continue + } + + stat, err := self.chain.WriteBlock(block, false) if err != nil { glog.V(logger.Error).Infoln("error writing block to chain", err) continue } + // check if canon block and write transactions + if stat == core.CanonStatTy { + // This puts transactions in a extra db for rpc + core.PutTransactions(self.extraDb, block, block.Transactions()) + // store the receipts + core.PutReceipts(self.extraDb, block.Hash(), self.current.receipts) + } // check staleness and display confirmation var stale, confirm string @@ -252,7 +271,13 @@ func (self *worker) wait() { glog.V(logger.Info).Infof("🔨 Mined %sblock (#%v / %x). %s", stale, block.Number(), block.Hash().Bytes()[:4], confirm) // broadcast before waiting for validation - go self.mux.Post(core.NewMinedBlockEvent{block}) + go func(block *types.Block, logs state.Logs) { + self.mux.Post(core.NewMinedBlockEvent{block}) + self.mux.Post(core.ChainEvent{block, block.Hash(), logs}) + if stat == core.CanonStatTy { + self.mux.Post(core.ChainHeadEvent{block}) + } + }(block, self.current.state.Logs()) self.commitNewWork() } |