Skip to content

Commit e79cc42

Browse files
committed
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.
1 parent 21fa291 commit e79cc42

File tree

2 files changed

+12
-26
lines changed

2 files changed

+12
-26
lines changed

core/chain_manager.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66
"io"
77
"math/big"
8-
"os"
98
"runtime"
109
"sync"
1110
"sync/atomic"
@@ -235,15 +234,8 @@ func (bc *ChainManager) setLastState() {
235234
if block != nil {
236235
bc.currentBlock = block
237236
bc.lastBlockHash = block.Hash()
238-
} else { // TODO CLEAN THIS UP TMP CODE
239-
block = bc.GetBlockByNumber(400000)
240-
if block == nil {
241-
fmt.Println("Fatal. LastBlock not found. Report this issue")
242-
os.Exit(1)
243-
}
244-
bc.currentBlock = block
245-
bc.lastBlockHash = block.Hash()
246-
bc.insert(block)
237+
} else {
238+
glog.Fatalf("Fatal. LastBlock not found. Please run removedb and resync")
247239
}
248240
} else {
249241
bc.Reset()

core/transaction_pool.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,21 +228,6 @@ func (self *TxPool) queueTx(hash common.Hash, tx *types.Transaction) {
228228
self.queue[from] = make(map[common.Hash]*types.Transaction)
229229
}
230230
self.queue[from][hash] = tx
231-
232-
if len(self.queue[from]) > maxQueued {
233-
var (
234-
worstHash common.Hash
235-
worstNonce uint64
236-
)
237-
for hash, tx := range self.queue[from] {
238-
if tx.Nonce() > worstNonce {
239-
worstNonce = tx.Nonce()
240-
worstHash = hash
241-
}
242-
}
243-
glog.V(logger.Debug).Infof("Queued tx limit exceeded for %x. Removed worst nonce tx: %x\n", common.PP(from[:]), common.PP(worstHash[:]))
244-
delete(self.queue[from], worstHash)
245-
}
246231
}
247232

248233
// addTx will add a transaction to the pending (processable queue) list of transactions
@@ -367,7 +352,16 @@ func (pool *TxPool) checkQueue() {
367352
// Find the next consecutive nonce range starting at the
368353
// current account nonce.
369354
sort.Sort(addq)
370-
for _, e := range addq {
355+
for i, e := range addq {
356+
// start deleting the transactions from the queue if they exceed the limit
357+
if i > maxQueued {
358+
if glog.V(logger.Debug) {
359+
glog.Infof("Queued tx limit exceeded for %s. Tx %s removed\n", common.PP(address[:]), common.PP(e.hash[:]))
360+
}
361+
delete(pool.queue[address], e.hash)
362+
continue
363+
}
364+
371365
if e.AccountNonce > guessedNonce {
372366
break
373367
}

0 commit comments

Comments
 (0)