diff options
author | obscuren <geffobscura@gmail.com> | 2015-02-20 05:33:22 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-02-20 05:33:22 +0800 |
commit | fa4cbad315609e41d88c59ecbce7c6c6169fc57a (patch) | |
tree | 5af4a3cfd497e682e41898059571b75f6f8e4cf9 /miner | |
parent | c14071df9da4ab3f5b372293e87184af9b91c09e (diff) | |
download | dexon-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar dexon-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.gz dexon-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.bz2 dexon-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.lz dexon-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.xz dexon-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.tar.zst dexon-fa4cbad315609e41d88c59ecbce7c6c6169fc57a.zip |
Optimisations and fixed a couple of DDOS issues in the miner
Diffstat (limited to 'miner')
-rw-r--r-- | miner/worker.go | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/miner/worker.go b/miner/worker.go index 47b462e53..1f3a52ab5 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -109,14 +109,18 @@ func (self *worker) register(agent Agent) { } func (self *worker) update() { - events := self.mux.Subscribe(core.ChainEvent{}, core.TxPreEvent{}) + events := self.mux.Subscribe(core.ChainEvent{}, core.NewMinedBlockEvent{}) out: for { select { case event := <-events.Chan(): - switch event.(type) { - case core.ChainEvent, core.TxPreEvent: + switch ev := event.(type) { + case core.ChainEvent: + if self.current.block != ev.Block { + self.commitNewWork() + } + case core.NewMinedBlockEvent: self.commitNewWork() } case <-self.quit: @@ -172,17 +176,19 @@ func (self *worker) commitNewWork() { transactions := self.eth.TxPool().GetTransactions() sort.Sort(types.TxByNonce{transactions}) + minerlogger.Infof("committing new work with %d txs\n", len(transactions)) // Keep track of transactions which return errors so they can be removed var remove types.Transactions +gasLimit: for _, tx := range transactions { err := self.commitTransaction(tx) switch { case core.IsNonceErr(err): // Remove invalid transactions remove = append(remove, tx) - case core.IsGasLimitErr(err): + case state.IsGasLimitErr(err): // Break on gas limit - break + break gasLimit } if err != nil { @@ -227,11 +233,9 @@ func (self *worker) commitUncle(uncle *types.Header) error { } func (self *worker) commitTransaction(tx *types.Transaction) error { - snapshot := self.current.state.Copy() + //fmt.Printf("proc %x %v\n", tx.Hash()[:3], tx.Nonce()) receipt, _, err := self.proc.ApplyTransaction(self.current.coinbase, self.current.state, self.current.block, tx, self.current.totalUsedGas, true) - if err != nil && (core.IsNonceErr(err) || core.IsGasLimitErr(err)) { - self.current.state.Set(snapshot) - + if err != nil && (core.IsNonceErr(err) || state.IsGasLimitErr(err)) { return err } |