Skip to content

Commit

Permalink
pool: minor refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
emailtovamos committed Sep 26, 2024
1 parent 31c9465 commit a8959fe
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
16 changes: 6 additions & 10 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2288,25 +2288,25 @@ 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)
pending, queue = pool.Stats()

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
Expand Down

0 comments on commit a8959fe

Please sign in to comment.