pool: edit tests and remove remaining pool2 logic
This commit is contained in:
parent
6a6e09c849
commit
355dee9000
@ -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
|
||||
}
|
||||
@ -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
|
||||
@ -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
|
||||
}
|
||||
@ -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)
|
||||
@ -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)
|
||||
@ -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())
|
||||
@ -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) {
|
||||
@ -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)))
|
||||
}
|
||||
|
@ -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))
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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 {
|
||||
@ -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()
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user