mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
remove addSync/addAsync
This commit is contained in:
parent
db59a6d988
commit
e6bc2f5c08
3 changed files with 30 additions and 40 deletions
|
|
@ -907,21 +907,11 @@ func (pool *LegacyPool) promoteTx(addr common.Address, hash common.Hash, tx *typ
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// addAsync is a convenience wrapper around Add. Tests use this method.
|
|
||||||
func (pool *LegacyPool) addAsync(txs []*types.Transaction) []error {
|
|
||||||
return pool.Add(txs, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// addTxAsync is a convenience wrapper around Add. Tests use this method.
|
// addTxAsync is a convenience wrapper around Add. Tests use this method.
|
||||||
func (pool *LegacyPool) addTxAsync(tx *types.Transaction) error {
|
func (pool *LegacyPool) addTxAsync(tx *types.Transaction) error {
|
||||||
return pool.Add([]*types.Transaction{tx}, false)[0]
|
return pool.Add([]*types.Transaction{tx}, false)[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// addSync is a convenience wrapper around Add. Tests use this method.
|
|
||||||
func (pool *LegacyPool) addSync(txs []*types.Transaction) []error {
|
|
||||||
return pool.Add(txs, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// addTxSync is a convenience wrapper around Add. Tests use this method.
|
// addTxSync is a convenience wrapper around Add. Tests use this method.
|
||||||
func (pool *LegacyPool) addTxSync(tx *types.Transaction) error {
|
func (pool *LegacyPool) addTxSync(tx *types.Transaction) error {
|
||||||
return pool.Add([]*types.Transaction{tx}, true)[0]
|
return pool.Add([]*types.Transaction{tx}, true)[0]
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,8 @@ func fillPool(t testing.TB, pool *LegacyPool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addSync(executableTxs)
|
pool.Add(executableTxs, true)
|
||||||
pool.addSync(nonExecutableTxs)
|
pool.Add(nonExecutableTxs, true)
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
slots := pool.all.Slots()
|
slots := pool.all.Slots()
|
||||||
// sanity-check that the test prerequisites are ok (pending full)
|
// sanity-check that the test prerequisites are ok (pending full)
|
||||||
|
|
@ -101,7 +101,7 @@ func TestTransactionFutureAttack(t *testing.T) {
|
||||||
futureTxs = append(futureTxs, pricedTransaction(1000+uint64(j), 100000, big.NewInt(500), key))
|
futureTxs = append(futureTxs, pricedTransaction(1000+uint64(j), 100000, big.NewInt(500), key))
|
||||||
}
|
}
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
pool.addSync(futureTxs)
|
pool.Add(futureTxs, true)
|
||||||
newPending, newQueued := count(t, pool)
|
newPending, newQueued := count(t, pool)
|
||||||
t.Logf("pending: %d queued: %d, all: %d\n", newPending, newQueued, pool.all.Slots())
|
t.Logf("pending: %d queued: %d, all: %d\n", newPending, newQueued, pool.all.Slots())
|
||||||
}
|
}
|
||||||
|
|
@ -137,7 +137,7 @@ func TestTransactionFuture1559(t *testing.T) {
|
||||||
for j := 0; j < int(pool.config.GlobalSlots+pool.config.GlobalQueue); j++ {
|
for j := 0; j < int(pool.config.GlobalSlots+pool.config.GlobalQueue); j++ {
|
||||||
futureTxs = append(futureTxs, dynamicFeeTx(1000+uint64(j), 100000, big.NewInt(200), big.NewInt(101), key))
|
futureTxs = append(futureTxs, dynamicFeeTx(1000+uint64(j), 100000, big.NewInt(200), big.NewInt(101), key))
|
||||||
}
|
}
|
||||||
pool.addSync(futureTxs)
|
pool.Add(futureTxs, true)
|
||||||
}
|
}
|
||||||
newPending, _ := pool.Stats()
|
newPending, _ := pool.Stats()
|
||||||
// Pending should not have been touched
|
// Pending should not have been touched
|
||||||
|
|
@ -190,7 +190,7 @@ func TestTransactionZAttack(t *testing.T) {
|
||||||
key, _ := crypto.GenerateKey()
|
key, _ := crypto.GenerateKey()
|
||||||
pool.currentState.AddBalance(crypto.PubkeyToAddress(key.PublicKey), uint256.NewInt(100000000000), tracing.BalanceChangeUnspecified)
|
pool.currentState.AddBalance(crypto.PubkeyToAddress(key.PublicKey), uint256.NewInt(100000000000), tracing.BalanceChangeUnspecified)
|
||||||
futureTxs = append(futureTxs, pricedTransaction(1000+uint64(j), 21000, big.NewInt(500), key))
|
futureTxs = append(futureTxs, pricedTransaction(1000+uint64(j), 21000, big.NewInt(500), key))
|
||||||
pool.addSync(futureTxs)
|
pool.Add(futureTxs, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
overDraftTxs := types.Transactions{}
|
overDraftTxs := types.Transactions{}
|
||||||
|
|
@ -201,11 +201,11 @@ func TestTransactionZAttack(t *testing.T) {
|
||||||
overDraftTxs = append(overDraftTxs, pricedValuedTransaction(uint64(j), 600000000000, 21000, big.NewInt(500), key))
|
overDraftTxs = append(overDraftTxs, pricedValuedTransaction(uint64(j), 600000000000, 21000, big.NewInt(500), key))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pool.addSync(overDraftTxs)
|
pool.Add(overDraftTxs, true)
|
||||||
pool.addSync(overDraftTxs)
|
pool.Add(overDraftTxs, true)
|
||||||
pool.addSync(overDraftTxs)
|
pool.Add(overDraftTxs, true)
|
||||||
pool.addSync(overDraftTxs)
|
pool.Add(overDraftTxs, true)
|
||||||
pool.addSync(overDraftTxs)
|
pool.Add(overDraftTxs, true)
|
||||||
|
|
||||||
newPending, newQueued := count(t, pool)
|
newPending, newQueued := count(t, pool)
|
||||||
newIvPending := countInvalidPending()
|
newIvPending := countInvalidPending()
|
||||||
|
|
@ -241,6 +241,6 @@ func BenchmarkFutureAttack(b *testing.B) {
|
||||||
}
|
}
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
pool.addSync(futureTxs)
|
pool.Add(futureTxs, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -354,7 +354,7 @@ func TestStateChangeDuringReset(t *testing.T) {
|
||||||
t.Fatalf("Invalid nonce, want 0, got %d", nonce)
|
t.Fatalf("Invalid nonce, want 0, got %d", nonce)
|
||||||
}
|
}
|
||||||
|
|
||||||
pool.addSync([]*types.Transaction{tx0, tx1})
|
pool.Add([]*types.Transaction{tx0, tx1}, true)
|
||||||
|
|
||||||
nonce = pool.Nonce(address)
|
nonce = pool.Nonce(address)
|
||||||
if nonce != 2 {
|
if nonce != 2 {
|
||||||
|
|
@ -789,7 +789,7 @@ func TestPostponing(t *testing.T) {
|
||||||
txs = append(txs, tx)
|
txs = append(txs, tx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, err := range pool.addSync(txs) {
|
for i, err := range pool.Add(txs, true) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("tx %d: failed to add transactions: %v", i, err)
|
t.Fatalf("tx %d: failed to add transactions: %v", i, err)
|
||||||
}
|
}
|
||||||
|
|
@ -885,10 +885,10 @@ func TestGapFilling(t *testing.T) {
|
||||||
defer sub.Unsubscribe()
|
defer sub.Unsubscribe()
|
||||||
|
|
||||||
// Create a pending and a queued transaction with a nonce-gap in between
|
// Create a pending and a queued transaction with a nonce-gap in between
|
||||||
pool.addSync([]*types.Transaction{
|
pool.Add([]*types.Transaction{
|
||||||
transaction(0, 100000, key),
|
transaction(0, 100000, key),
|
||||||
transaction(2, 100000, key),
|
transaction(2, 100000, key),
|
||||||
})
|
}, true)
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != 1 {
|
if pending != 1 {
|
||||||
t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 1)
|
t.Fatalf("pending transactions mismatched: have %d, want %d", pending, 1)
|
||||||
|
|
@ -995,7 +995,7 @@ func TestQueueGlobalLimiting(t *testing.T) {
|
||||||
nonces[addr]++
|
nonces[addr]++
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
queued := 0
|
queued := 0
|
||||||
for addr, list := range pool.queue {
|
for addr, list := range pool.queue {
|
||||||
|
|
@ -1207,7 +1207,7 @@ func TestPendingGlobalLimiting(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
pending := 0
|
pending := 0
|
||||||
for _, list := range pool.pending {
|
for _, list := range pool.pending {
|
||||||
|
|
@ -1298,7 +1298,7 @@ func TestCapClearsFromAll(t *testing.T) {
|
||||||
txs = append(txs, transaction(uint64(j), 100000, key))
|
txs = append(txs, transaction(uint64(j), 100000, key))
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addAsync(txs)
|
pool.Add(txs, false)
|
||||||
if err := validatePoolInternals(pool); err != nil {
|
if err := validatePoolInternals(pool); err != nil {
|
||||||
t.Fatalf("pool internal state corrupted: %v", err)
|
t.Fatalf("pool internal state corrupted: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -1339,7 +1339,7 @@ func TestPendingMinimumAllowance(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Import the batch and verify that limits have been enforced
|
// Import the batch and verify that limits have been enforced
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
for addr, list := range pool.pending {
|
for addr, list := range pool.pending {
|
||||||
if list.Len() != int(config.AccountSlots) {
|
if list.Len() != int(config.AccountSlots) {
|
||||||
|
|
@ -1392,7 +1392,7 @@ func TestRepricing(t *testing.T) {
|
||||||
txs = append(txs, pricedTransaction(3, 100000, big.NewInt(2), keys[2]))
|
txs = append(txs, pricedTransaction(3, 100000, big.NewInt(2), keys[2]))
|
||||||
|
|
||||||
// Import the batch and that both pending and queued transactions match up
|
// Import the batch and that both pending and queued transactions match up
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != 6 {
|
if pending != 6 {
|
||||||
|
|
@ -1527,7 +1527,7 @@ func TestRepricingDynamicFee(t *testing.T) {
|
||||||
txs = append(txs, dynamicFeeTx(3, 100000, big.NewInt(2), big.NewInt(2), keys[2]))
|
txs = append(txs, dynamicFeeTx(3, 100000, big.NewInt(2), big.NewInt(2), keys[2]))
|
||||||
|
|
||||||
// Import the batch and that both pending and queued transactions match up
|
// Import the batch and that both pending and queued transactions match up
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != 6 {
|
if pending != 6 {
|
||||||
|
|
@ -1639,7 +1639,7 @@ func TestUnderpricing(t *testing.T) {
|
||||||
|
|
||||||
txs = append(txs, pricedTransaction(1, 100000, big.NewInt(1), keys[1])) // queued
|
txs = append(txs, pricedTransaction(1, 100000, big.NewInt(1), keys[1])) // queued
|
||||||
// Import the batch and that both pending and queued transactions match up
|
// Import the batch and that both pending and queued transactions match up
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != 3 {
|
if pending != 3 {
|
||||||
|
|
@ -1725,7 +1725,7 @@ func TestStableUnderpricing(t *testing.T) {
|
||||||
for i := uint64(0); i < config.GlobalSlots; i++ {
|
for i := uint64(0); i < config.GlobalSlots; i++ {
|
||||||
txs = append(txs, pricedTransaction(i, 100000, big.NewInt(1), keys[0]))
|
txs = append(txs, pricedTransaction(i, 100000, big.NewInt(1), keys[0]))
|
||||||
}
|
}
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != int(config.GlobalSlots) {
|
if pending != int(config.GlobalSlots) {
|
||||||
|
|
@ -1792,7 +1792,7 @@ func TestUnderpricingDynamicFee(t *testing.T) {
|
||||||
txs = append(txs, dynamicFeeTx(0, 100000, big.NewInt(2), big.NewInt(1), keys[2])) // pending
|
txs = append(txs, dynamicFeeTx(0, 100000, big.NewInt(2), big.NewInt(1), keys[2])) // pending
|
||||||
|
|
||||||
// Import the batch and check that both pending and queued transactions match up
|
// Import the batch and check that both pending and queued transactions match up
|
||||||
pool.addSync(txs) // Pend K0:0, K0:1; Que K1:1
|
pool.Add(txs, true) // Pend K0:0, K0:1; Que K1:1
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != 3 {
|
if pending != 3 {
|
||||||
|
|
@ -1878,7 +1878,7 @@ func TestDualHeapEviction(t *testing.T) {
|
||||||
tx = dynamicFeeTx(0, 100000, big.NewInt(int64(baseFee+200+i)), big.NewInt(1), key)
|
tx = dynamicFeeTx(0, 100000, big.NewInt(int64(baseFee+200+i)), big.NewInt(1), key)
|
||||||
highCap = tx
|
highCap = tx
|
||||||
}
|
}
|
||||||
pool.addSync([]*types.Transaction{tx})
|
pool.Add([]*types.Transaction{tx}, true)
|
||||||
}
|
}
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending+queued != 20 {
|
if pending+queued != 20 {
|
||||||
|
|
@ -1925,7 +1925,7 @@ func TestDeduplication(t *testing.T) {
|
||||||
for i := 0; i < len(txs); i += 2 {
|
for i := 0; i < len(txs); i += 2 {
|
||||||
firsts = append(firsts, txs[i])
|
firsts = append(firsts, txs[i])
|
||||||
}
|
}
|
||||||
errs := pool.addSync(firsts)
|
errs := pool.Add(firsts, true)
|
||||||
if len(errs) != len(firsts) {
|
if len(errs) != len(firsts) {
|
||||||
t.Fatalf("first add mismatching result count: have %d, want %d", len(errs), len(firsts))
|
t.Fatalf("first add mismatching result count: have %d, want %d", len(errs), len(firsts))
|
||||||
}
|
}
|
||||||
|
|
@ -1942,7 +1942,7 @@ func TestDeduplication(t *testing.T) {
|
||||||
t.Fatalf("queued transactions mismatched: have %d, want %d", queued, len(txs)/2-1)
|
t.Fatalf("queued transactions mismatched: have %d, want %d", queued, len(txs)/2-1)
|
||||||
}
|
}
|
||||||
// Try to add all of them now and ensure previous ones error out as knowns
|
// Try to add all of them now and ensure previous ones error out as knowns
|
||||||
errs = pool.addSync(txs)
|
errs = pool.Add(txs, true)
|
||||||
if len(errs) != len(txs) {
|
if len(errs) != len(txs) {
|
||||||
t.Fatalf("all add mismatching result count: have %d, want %d", len(errs), len(txs))
|
t.Fatalf("all add mismatching result count: have %d, want %d", len(errs), len(txs))
|
||||||
}
|
}
|
||||||
|
|
@ -2186,7 +2186,7 @@ func TestStatusCheck(t *testing.T) {
|
||||||
txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) // Queued only
|
txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) // Queued only
|
||||||
|
|
||||||
// Import the transaction and ensure they are correctly added
|
// Import the transaction and ensure they are correctly added
|
||||||
pool.addSync(txs)
|
pool.Add(txs, true)
|
||||||
|
|
||||||
pending, queued := pool.Stats()
|
pending, queued := pool.Stats()
|
||||||
if pending != 2 {
|
if pending != 2 {
|
||||||
|
|
@ -2663,7 +2663,7 @@ func benchmarkBatchInsert(b *testing.B, size int) {
|
||||||
// Benchmark importing the transactions into the queue
|
// Benchmark importing the transactions into the queue
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for _, batch := range batches {
|
for _, batch := range batches {
|
||||||
pool.addAsync(batch)
|
pool.Add(batch, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2684,6 +2684,6 @@ func BenchmarkMultiAccountBatchInsert(b *testing.B) {
|
||||||
// Benchmark importing the transactions into the queue
|
// Benchmark importing the transactions into the queue
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for _, tx := range batches {
|
for _, tx := range batches {
|
||||||
pool.addSync([]*types.Transaction{tx})
|
pool.Add([]*types.Transaction{tx}, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue