Optimisations and fixed a couple of DDOS issues in the miner

This commit is contained in:
obscuren
2015-02-19 22:33:22 +01:00
parent c14071df9d
commit fa4cbad315
15 changed files with 156 additions and 104 deletions

View File

@ -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
}