Skip to content

Commit

Permalink
core, les: fix les unit tests (ethereum#19823)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan committed May 10, 2024
1 parent edaed4f commit b708614
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
6 changes: 3 additions & 3 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,13 +884,13 @@ func (pool *TxPool) AddRemotes(txs []*types.Transaction) []error {
}

// This is like AddRemotes, but waits for pool reorganization. Tests use this method.
func (pool *TxPool) addRemotesSync(txs []*types.Transaction) []error {
func (pool *TxPool) AddRemotesSync(txs []*types.Transaction) []error {
return pool.addTxs(txs, false, true)
}

// This is like AddRemotes with a single transaction, but waits for pool reorganization. Tests use this method.
func (pool *TxPool) addRemoteSync(tx *types.Transaction) error {
errs := pool.addRemotesSync([]*types.Transaction{tx})
func (pool *TxPool) AddRemoteSync(tx *types.Transaction) error {
errs := pool.AddRemotesSync([]*types.Transaction{tx})
return errs[0]
}

Expand Down
32 changes: 16 additions & 16 deletions core/tx_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestStateChangeDuringTransactionPoolReset(t *testing.T) {
t.Fatalf("Invalid nonce, want 0, got %d", nonce)
}

pool.addRemotesSync([]*types.Transaction{tx0, tx1})
pool.AddRemotesSync([]*types.Transaction{tx0, tx1})

nonce = pool.Nonce(address)
if nonce != 2 {
Expand Down Expand Up @@ -611,7 +611,7 @@ func TestTransactionPostponing(t *testing.T) {
txs = append(txs, tx)
}
}
for i, err := range pool.addRemotesSync(txs) {
for i, err := range pool.AddRemotesSync(txs) {
if err != nil {
t.Fatalf("tx %d: failed to add transactions: %v", i, err)
}
Expand Down Expand Up @@ -707,7 +707,7 @@ func TestTransactionGapFilling(t *testing.T) {
defer sub.Unsubscribe()

// Create a pending and a queued transaction with a nonce-gap in between
pool.addRemotesSync([]*types.Transaction{
pool.AddRemotesSync([]*types.Transaction{
transaction(0, 100000, key),
transaction(2, 100000, key),
})
Expand All @@ -725,7 +725,7 @@ func TestTransactionGapFilling(t *testing.T) {
t.Fatalf("pool internal state corrupted: %v", err)
}
// Fill the nonce gap and ensure all transactions become pending
if err := pool.addRemoteSync(transaction(1, 100000, key)); err != nil {
if err := pool.AddRemoteSync(transaction(1, 100000, key)); err != nil {
t.Fatalf("failed to add gapped transaction: %v", err)
}
pending, queued = pool.Stats()
Expand Down Expand Up @@ -757,7 +757,7 @@ func TestTransactionQueueAccountLimiting(t *testing.T) {
testTxPoolConfig.AccountQueue = 10
// Keep queuing up transactions and make sure all above a limit are dropped
for i := uint64(1); i <= testTxPoolConfig.AccountQueue; i++ {
if err := pool.addRemoteSync(transaction(i, 100000, key)); err != nil {
if err := pool.AddRemoteSync(transaction(i, 100000, key)); err != nil {
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
}
if len(pool.pending) != 0 {
Expand Down Expand Up @@ -826,7 +826,7 @@ func testTransactionQueueGlobalLimiting(t *testing.T, nolocals bool) {
nonces[addr]++
}
// Import the batch and verify that limits have been enforced
pool.addRemotesSync(txs)
pool.AddRemotesSync(txs)

queued := 0
for addr, list := range pool.queue {
Expand Down Expand Up @@ -963,7 +963,7 @@ func TestTransactionPendingLimiting(t *testing.T) {

// Keep queuing up transactions and make sure all above a limit are dropped
for i := uint64(0); i < testTxPoolConfig.AccountQueue; i++ {
if err := pool.addRemoteSync(transaction(i, 100000, key)); err != nil {
if err := pool.AddRemoteSync(transaction(i, 100000, key)); err != nil {
t.Fatalf("tx %d: failed to add transaction: %v", i, err)
}
if pool.pending[account].Len() != int(i)+1 {
Expand Down Expand Up @@ -1019,7 +1019,7 @@ func TestTransactionPendingGlobalLimiting(t *testing.T) {
}
}
// Import the batch and verify that limits have been enforced
pool.addRemotesSync(txs)
pool.AddRemotesSync(txs)

pending := 0
for _, list := range pool.pending {
Expand Down Expand Up @@ -1101,7 +1101,7 @@ func TestTransactionPendingMinimumAllowance(t *testing.T) {
}
}
// Import the batch and verify that limits have been enforced
pool.addRemotesSync(txs)
pool.AddRemotesSync(txs)

for addr, list := range pool.pending {
if list.Len() != int(config.AccountSlots) {
Expand Down Expand Up @@ -1158,7 +1158,7 @@ func TestTransactionPoolRepricing(t *testing.T) {
ltx := pricedTransaction(0, 100000, big.NewInt(1), keys[3])

// Import the batch and that both pending and queued transactions match up
pool.addRemotesSync(txs)
pool.AddRemotesSync(txs)
pool.AddLocal(ltx)

pending, queued := pool.Stats()
Expand Down Expand Up @@ -1442,7 +1442,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
for i := uint64(0); i < config.GlobalSlots; i++ {
txs = append(txs, pricedTransaction(i, 100000, big.NewInt(1), keys[0]))
}
pool.addRemotesSync(txs)
pool.AddRemotesSync(txs)

pending, queued := pool.Stats()
if pending != int(config.GlobalSlots) {
Expand All @@ -1458,7 +1458,7 @@ func TestTransactionPoolStableUnderpricing(t *testing.T) {
t.Fatalf("pool internal state corrupted: %v", err)
}
// Ensure that adding high priced transactions drops a cheap, but doesn't produce a gap
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(3), keys[1])); err != nil {
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(3), keys[1])); err != nil {
t.Fatalf("failed to add well priced transaction: %v", err)
}
pending, queued = pool.Stats()
Expand Down Expand Up @@ -1502,7 +1502,7 @@ func TestTransactionReplacement(t *testing.T) {
price := int64(100)
threshold := (price * (100 + int64(testTxPoolConfig.PriceBump))) / 100

if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), key)); err != nil {
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), key)); err != nil {
t.Fatalf("failed to add original cheap pending transaction: %v", err)
}
if err := pool.AddRemote(pricedTransaction(0, 100001, big.NewInt(1), key)); err != ErrReplaceUnderpriced {
Expand All @@ -1515,7 +1515,7 @@ func TestTransactionReplacement(t *testing.T) {
t.Fatalf("cheap replacement event firing failed: %v", err)
}

if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(price), key)); err != nil {
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(price), key)); err != nil {
t.Fatalf("failed to add original proper pending transaction: %v", err)
}
if err := pool.AddRemote(pricedTransaction(0, 100001, big.NewInt(threshold-1), key)); err != ErrReplaceUnderpriced {
Expand Down Expand Up @@ -1606,7 +1606,7 @@ func testTransactionJournaling(t *testing.T, nolocals bool) {
if err := pool.AddLocal(pricedTransaction(2, 100000, big.NewInt(1), local)); err != nil {
t.Fatalf("failed to add local transaction: %v", err)
}
if err := pool.addRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), remote)); err != nil {
if err := pool.AddRemoteSync(pricedTransaction(0, 100000, big.NewInt(1), remote)); err != nil {
t.Fatalf("failed to add remote transaction: %v", err)
}
pending, queued := pool.Stats()
Expand Down Expand Up @@ -1699,7 +1699,7 @@ func TestTransactionStatusCheck(t *testing.T) {
txs = append(txs, pricedTransaction(2, 100000, big.NewInt(1), keys[2])) // Queued only

// Import the transaction and ensure they are correctly added
pool.addRemotesSync(txs)
pool.AddRemotesSync(txs)

pending, queued := pool.Stats()
if pending != 2 {
Expand Down
1 change: 1 addition & 0 deletions les/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ type BlockChain interface {

type txPool interface {
AddRemotes(txs []*types.Transaction) []error
AddRemotesSync(txs []*types.Transaction) []error
Status(hashes []common.Hash) []core.TxStatus
}

Expand Down

0 comments on commit b708614

Please sign in to comment.