pool: minor refactors

This commit is contained in:
emailtovamos 2024-09-26 15:18:06 +01:00
parent 31c9465eac
commit a8959fe60e
2 changed files with 10 additions and 14 deletions

@ -279,7 +279,7 @@ func New(config Config, chain BlockChain) *LegacyPool {
reorgDoneCh: make(chan chan struct{}),
reorgShutdownCh: make(chan struct{}),
initDoneCh: make(chan struct{}),
localBufferPool: NewTxPool3Heap(), // NewLRUBufferFastCache(int(config.Pool3Slots)),
localBufferPool: NewTxPool3Heap(),
}
pool.locals = newAccountSet(pool.signer)
for _, addr := range config.Locals {
@ -417,8 +417,7 @@ func (pool *LegacyPool) loop() {
if !pool.locals.contains(addr) {
continue
}
transactions := list.Flatten()
for _, tx := range transactions {
for _, tx := range list.Flatten() {
// Default ReannounceTime is 10 years, won't announce by default.
if time.Since(tx.Time()) < pool.config.ReannounceTime {
break
@ -526,7 +525,7 @@ func (pool *LegacyPool) Stats() (int, int) {
return pool.stats()
}
func (pool *LegacyPool) StatsPool3() int {
func (pool *LegacyPool) statsPool3() int {
pool.mu.RLock()
defer pool.mu.RUnlock()
@ -658,12 +657,10 @@ func (pool *LegacyPool) local() map[common.Address]types.Transactions {
txs := make(map[common.Address]types.Transactions)
for addr := range pool.locals.accounts {
if pending := pool.pending[addr]; pending != nil {
transactions := pending.Flatten()
txs[addr] = append(txs[addr], transactions...)
txs[addr] = append(txs[addr], pending.Flatten()...)
}
if queued := pool.queue[addr]; queued != nil {
transactions := queued.Flatten()
txs[addr] = append(txs[addr], transactions...)
txs[addr] = append(txs[addr], queued.Flatten()...)
}
}
return txs
@ -1753,8 +1750,7 @@ func (pool *LegacyPool) truncateQueue() {
// Drop all transactions if they are less than the overflow
if size := uint64(list.Len()); size <= drop {
transactions := list.Flatten()
for _, tx := range transactions {
for _, tx := range list.Flatten() {
pool.removeTx(tx.Hash(), true, true)
}
drop -= size

@ -2288,17 +2288,17 @@ func TestTransferTransactions(t *testing.T) {
assert.Equal(t, 0, pending, "pending transactions mismatched")
assert.Equal(t, 0, queue, "queued transactions mismatched")
assert.Equal(t, 1, pool.StatsPool3(), "pool3 size unexpected")
assert.Equal(t, 1, pool.statsPool3(), "pool3 size unexpected")
tx2 := dynamicFeeTx(0, 100000, big.NewInt(3), big.NewInt(2), keys[1])
pool.addToPool3([]*types.Transaction{tx2}, true)
assert.Equal(t, 1, pool.StatsPool3(), "pool3 size unexpected")
assert.Equal(t, 1, pool.statsPool3(), "pool3 size unexpected")
<-pool.requestPromoteExecutables(newAccountSet(pool.signer, from))
pending, queue = pool.Stats()
assert.Equal(t, 0, pending, "pending transactions mismatched")
assert.Equal(t, 1, queue, "queued transactions mismatched")
assert.Equal(t, 0, pool.StatsPool3(), "pool3 size unexpected")
assert.Equal(t, 0, pool.statsPool3(), "pool3 size unexpected")
tx3 := dynamicFeeTx(0, 100000, big.NewInt(3), big.NewInt(2), keys[2])
pool.addToPool3([]*types.Transaction{tx3}, true)
@ -2306,7 +2306,7 @@ func TestTransferTransactions(t *testing.T) {
assert.Equal(t, 1, pending, "pending transactions mismatched")
assert.Equal(t, 0, queue, "queued transactions mismatched")
assert.Equal(t, 1, pool.StatsPool3(), "pool3 size unexpected")
assert.Equal(t, 1, pool.statsPool3(), "pool3 size unexpected")
}
// Tests that the pool rejects replacement dynamic fee transactions that don't