core: moved check for max queue to checkQueue

Moved the queue to check to the checkQueue method so no undeeded loops
need to be initiated or sorting needs to happen twice.
This commit is contained in:
obscuren 2015-06-15 16:46:45 +02:00
parent 21fa29111b
commit e79cc42dfe
2 changed files with 12 additions and 26 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io" "io"
"math/big" "math/big"
"os"
"runtime" "runtime"
"sync" "sync"
"sync/atomic" "sync/atomic"
@ -235,15 +234,8 @@ func (bc *ChainManager) setLastState() {
if block != nil { if block != nil {
bc.currentBlock = block bc.currentBlock = block
bc.lastBlockHash = block.Hash() bc.lastBlockHash = block.Hash()
} else { // TODO CLEAN THIS UP TMP CODE } else {
block = bc.GetBlockByNumber(400000) glog.Fatalf("Fatal. LastBlock not found. Please run removedb and resync")
if block == nil {
fmt.Println("Fatal. LastBlock not found. Report this issue")
os.Exit(1)
}
bc.currentBlock = block
bc.lastBlockHash = block.Hash()
bc.insert(block)
} }
} else { } else {
bc.Reset() bc.Reset()

View File

@ -228,21 +228,6 @@ func (self *TxPool) queueTx(hash common.Hash, tx *types.Transaction) {
self.queue[from] = make(map[common.Hash]*types.Transaction) self.queue[from] = make(map[common.Hash]*types.Transaction)
} }
self.queue[from][hash] = tx self.queue[from][hash] = tx
if len(self.queue[from]) > maxQueued {
var (
worstHash common.Hash
worstNonce uint64
)
for hash, tx := range self.queue[from] {
if tx.Nonce() > worstNonce {
worstNonce = tx.Nonce()
worstHash = hash
}
}
glog.V(logger.Debug).Infof("Queued tx limit exceeded for %x. Removed worst nonce tx: %x\n", common.PP(from[:]), common.PP(worstHash[:]))
delete(self.queue[from], worstHash)
}
} }
// addTx will add a transaction to the pending (processable queue) list of transactions // addTx will add a transaction to the pending (processable queue) list of transactions
@ -367,7 +352,16 @@ func (pool *TxPool) checkQueue() {
// Find the next consecutive nonce range starting at the // Find the next consecutive nonce range starting at the
// current account nonce. // current account nonce.
sort.Sort(addq) sort.Sort(addq)
for _, e := range addq { for i, e := range addq {
// start deleting the transactions from the queue if they exceed the limit
if i > maxQueued {
if glog.V(logger.Debug) {
glog.Infof("Queued tx limit exceeded for %s. Tx %s removed\n", common.PP(address[:]), common.PP(e.hash[:]))
}
delete(pool.queue[address], e.hash)
continue
}
if e.AccountNonce > guessedNonce { if e.AccountNonce > guessedNonce {
break break
} }