Skip to content

Commit

Permalink
pool: edit tests and remove remaining pool2 logic
Browse files Browse the repository at this point in the history
  • Loading branch information
emailtovamos committed Sep 26, 2024
1 parent 6a6e09c commit 355dee9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
21 changes: 8 additions & 13 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,6 @@ type LegacyPool struct {
changesSinceReorg int // A counter for how many drops we've performed in-between reorg.
}

type QueueTxEventCh struct {
tx *types.Transaction
static bool
}

type txpoolResetRequest struct {
oldHead, newHead *types.Header
}
Expand Down Expand Up @@ -883,7 +878,7 @@ func (pool *LegacyPool) add(tx *types.Transaction, local bool) (replaced bool, e
// Try to replace an existing transaction in the pending pool
if list := pool.pending[from]; list != nil && list.Contains(tx.Nonce()) {
// Nonce already pending, check if required price bump is met
inserted, old := list.Add(tx, pool.config.PriceBump, false)
inserted, old := list.Add(tx, pool.config.PriceBump)
if !inserted {
pendingDiscardMeter.Mark(1)
return false, txpool.ErrReplaceUnderpriced
Expand All @@ -906,7 +901,7 @@ func (pool *LegacyPool) add(tx *types.Transaction, local bool) (replaced bool, e
}

// New transaction isn't replacing a pending one, push into queue
replaced, err = pool.enqueueTx(hash, tx, isLocal, true, true)
replaced, err = pool.enqueueTx(hash, tx, isLocal, true)
if err != nil {
return false, err
}
Expand Down Expand Up @@ -976,13 +971,13 @@ func (pool *LegacyPool) isGapped(from common.Address, tx *types.Transaction) boo
// enqueueTx inserts a new transaction into the non-executable transaction queue.
//
// Note, this method assumes the pool lock is held!
func (pool *LegacyPool) enqueueTx(hash common.Hash, tx *types.Transaction, local bool, addAll bool, static bool) (bool, error) {
func (pool *LegacyPool) enqueueTx(hash common.Hash, tx *types.Transaction, local bool, addAll bool) (bool, error) {
// Try to insert the transaction into the future queue
from, _ := types.Sender(pool.signer, tx) // already validated
if pool.queue[from] == nil {
pool.queue[from] = newList(false)
}
inserted, old := pool.queue[from].Add(tx, pool.config.PriceBump, static)
inserted, old := pool.queue[from].Add(tx, pool.config.PriceBump)
if !inserted {
// An older transaction was better, discard this
queuedDiscardMeter.Mark(1)
Expand Down Expand Up @@ -1036,7 +1031,7 @@ func (pool *LegacyPool) promoteTx(addr common.Address, hash common.Hash, tx *typ
}
list := pool.pending[addr]

inserted, old := list.Add(tx, pool.config.PriceBump, false) // todo check and confirm
inserted, old := list.Add(tx, pool.config.PriceBump)
if !inserted {
// An older transaction was better, discard this
pool.all.Remove(hash)
Expand Down Expand Up @@ -1265,7 +1260,7 @@ func (pool *LegacyPool) removeTx(hash common.Hash, outofbound bool, unreserve bo
// Postpone any invalidated transactions
for _, tx := range invalids {
// Internal shuffle shouldn't touch the lookup set.
pool.enqueueTx(tx.Hash(), tx, false, false, false)
pool.enqueueTx(tx.Hash(), tx, false, false)
}
// Update the account nonce if needed
pool.pendingNonces.setIfLower(addr, tx.Nonce())
Expand Down Expand Up @@ -1815,7 +1810,7 @@ func (pool *LegacyPool) demoteUnexecutables() {
log.Trace("Demoting pending transaction", "hash", hash)

// Internal shuffle shouldn't touch the lookup set.
pool.enqueueTx(hash, tx, false, false, false)
pool.enqueueTx(hash, tx, false, false)
}
pendingGauge.Dec(int64(len(olds) + len(drops) + len(invalids)))
if pool.locals.contains(addr) {
Expand All @@ -1829,7 +1824,7 @@ func (pool *LegacyPool) demoteUnexecutables() {
log.Error("Demoting invalidated transaction", "hash", hash)

// Internal shuffle shouldn't touch the lookup set.
pool.enqueueTx(hash, tx, false, false, false)
pool.enqueueTx(hash, tx, false, false)
}
pendingGauge.Dec(int64(len(gapped)))
}
Expand Down
18 changes: 9 additions & 9 deletions core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ func TestQueue(t *testing.T) {
testAddBalance(pool, from, big.NewInt(1000))
<-pool.requestReset(nil, nil)

pool.enqueueTx(tx.Hash(), tx, false, true, false)
pool.enqueueTx(tx.Hash(), tx, false, true)
<-pool.requestPromoteExecutables(newAccountSet(pool.signer, from))
if len(pool.pending) != 1 {
t.Error("expected valid txs to be 1 is", len(pool.pending))
Expand All @@ -376,7 +376,7 @@ func TestQueue(t *testing.T) {
tx = transaction(1, 100, key)
from, _ = deriveSender(tx)
testSetNonce(pool, from, 2)
pool.enqueueTx(tx.Hash(), tx, false, true, false)
pool.enqueueTx(tx.Hash(), tx, false, true)

<-pool.requestPromoteExecutables(newAccountSet(pool.signer, from))
if _, ok := pool.pending[from].txs.items[tx.Nonce()]; ok {
Expand All @@ -400,9 +400,9 @@ func TestQueue2(t *testing.T) {
testAddBalance(pool, from, big.NewInt(1000))
pool.reset(nil, nil)

pool.enqueueTx(tx1.Hash(), tx1, false, true, false)
pool.enqueueTx(tx2.Hash(), tx2, false, true, false)
pool.enqueueTx(tx3.Hash(), tx3, false, true, false)
pool.enqueueTx(tx1.Hash(), tx1, false, true)
pool.enqueueTx(tx2.Hash(), tx2, false, true)
pool.enqueueTx(tx3.Hash(), tx3, false, true)

pool.promoteExecutables([]common.Address{from})
if len(pool.pending) != 1 {
Expand Down Expand Up @@ -620,9 +620,9 @@ func TestDropping(t *testing.T) {
pool.priced.Put(tx2, false)
pool.promoteTx(account, tx2.Hash(), tx2)

pool.enqueueTx(tx10.Hash(), tx10, false, true, false)
pool.enqueueTx(tx11.Hash(), tx11, false, true, false)
pool.enqueueTx(tx12.Hash(), tx12, false, true, false)
pool.enqueueTx(tx10.Hash(), tx10, false, true)
pool.enqueueTx(tx11.Hash(), tx11, false, true)
pool.enqueueTx(tx12.Hash(), tx12, false, true)

// Check that pre and post validations leave the pool as is
if pool.pending[account].Len() != 3 {
Expand Down Expand Up @@ -2691,7 +2691,7 @@ func benchmarkFuturePromotion(b *testing.B, size int) {

for i := 0; i < size; i++ {
tx := transaction(uint64(1+i), 100000, key)
pool.enqueueTx(tx.Hash(), tx, false, true, false)
pool.enqueueTx(tx.Hash(), tx, false, true)
}
// Benchmark the speed of pool validation
b.ResetTimer()
Expand Down
2 changes: 1 addition & 1 deletion core/txpool/legacypool/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (l *list) Contains(nonce uint64) bool {
//
// If the new transaction is accepted into the list, the lists' cost and gas
// thresholds are also potentially updated.
func (l *list) Add(tx *types.Transaction, priceBump uint64, static bool) (bool, *types.Transaction) {
func (l *list) Add(tx *types.Transaction, priceBump uint64) (bool, *types.Transaction) {
// If there's an older better transaction, abort
old := l.txs.Get(tx.Nonce())
if old != nil {
Expand Down
8 changes: 4 additions & 4 deletions core/txpool/legacypool/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestStrictListAdd(t *testing.T) {
// Insert the transactions in a random order
list := newList(true)
for _, v := range rand.Perm(len(txs)) {
list.Add(txs[v], DefaultConfig.PriceBump, false)
list.Add(txs[v], DefaultConfig.PriceBump)
}
// Verify internal state
if len(list.txs.items) != len(txs) {
Expand All @@ -64,7 +64,7 @@ func TestListAddVeryExpensive(t *testing.T) {
gaslimit := uint64(i)
tx, _ := types.SignTx(types.NewTransaction(uint64(i), common.Address{}, value, gaslimit, gasprice, nil), types.HomesteadSigner{}, key)
t.Logf("cost: %x bitlen: %d\n", tx.Cost(), tx.Cost().BitLen())
list.Add(tx, DefaultConfig.PriceBump, false)
list.Add(tx, DefaultConfig.PriceBump)
}
}

Expand All @@ -82,7 +82,7 @@ func BenchmarkListAdd(b *testing.B) {
for i := 0; i < b.N; i++ {
list := newList(true)
for _, v := range rand.Perm(len(txs)) {
list.Add(txs[v], DefaultConfig.PriceBump, false)
list.Add(txs[v], DefaultConfig.PriceBump)
list.Filter(priceLimit, DefaultConfig.PriceBump)
}
}
Expand All @@ -102,7 +102,7 @@ func BenchmarkListCapOneTx(b *testing.B) {
list := newList(true)
// Insert the transactions in a random order
for _, v := range rand.Perm(len(txs)) {
list.Add(txs[v], DefaultConfig.PriceBump, false)
list.Add(txs[v], DefaultConfig.PriceBump)
}
b.StartTimer()
list.Cap(list.Len() - 1)
Expand Down

0 comments on commit 355dee9

Please sign in to comment.