diff options
author | obscuren <geffobscura@gmail.com> | 2015-04-21 17:26:04 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-04-21 17:26:04 +0800 |
commit | 1d6d42919e3bd3e24cd9ff2f1534efb41cb5a216 (patch) | |
tree | 1b0cd902e8c338d294af4c486ea8c7a3235bd69b /miner | |
parent | 79bef9eb164a1040a254be5e8a8844eeb37daf8e (diff) | |
download | dexon-1d6d42919e3bd3e24cd9ff2f1534efb41cb5a216.tar.gz dexon-1d6d42919e3bd3e24cd9ff2f1534efb41cb5a216.tar.zst dexon-1d6d42919e3bd3e24cd9ff2f1534efb41cb5a216.zip |
miner: ignore a tx's transactor after a gas limit has been returned
When worker encounters a gas limit error, subsequent txs should be
ignored from that particular account. This will prevent:
1. Nonce errors been thrown all around
2. The "Known tx" error. Closes #719
3. Repeated contract address. Closes #731
Diffstat (limited to 'miner')
-rw-r--r-- | miner/worker.go | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/miner/worker.go b/miner/worker.go index 63645cd54..d5ffb398a 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -253,11 +253,23 @@ func (self *worker) commitNewWork() { // Keep track of transactions which return errors so they can be removed var ( - remove = set.New() - tcount = 0 + remove = set.New() + tcount = 0 + ignoredTransactors = set.New() ) //gasLimit: for _, tx := range transactions { + // We can skip err. It has already been validated in the tx pool + from, _ := tx.From() + // Move on to the next transaction when the transactor is in ignored transactions set + // This may occur when a transaction hits the gas limit. When a gas limit is hit and + // the transaction is processed (that could potentially be included in the block) it + // will throw a nonce error because the previous transaction hasn't been processed. + // Therefor we need to ignore any transaction after the ignored one. + if ignoredTransactors.Has(from) { + continue + } + self.current.state.StartRecord(tx.Hash(), common.Hash{}, 0) err := self.commitTransaction(tx) @@ -265,14 +277,18 @@ func (self *worker) commitNewWork() { case core.IsNonceErr(err) || core.IsInvalidTxErr(err): // Remove invalid transactions from, _ := tx.From() + self.chain.TxState().RemoveNonce(from, tx.Nonce()) remove.Add(tx.Hash()) if glog.V(logger.Detail) { glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err) - //glog.Infoln(tx) } case state.IsGasLimitErr(err): + from, _ := tx.From() + // ignore the transactor so no nonce errors will be thrown for this account + // next time the worker is run, they'll be picked up again. + ignoredTransactors.Add(from) //glog.V(logger.Debug).Infof("Gas limit reached for block. %d TXs included in this block\n", i) //break gasLimit default: |