Skip to content

Commit

Permalink
fixed txpool maxEnqueued issue (#1789)
Browse files Browse the repository at this point in the history
* fixed txpool maxEnqueued issue

* removed extra space
  • Loading branch information
rachit77 authored Aug 8, 2023
1 parent bd95643 commit 39f7d2b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion txpool/txpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ func (p *TxPool) addTx(origin txOrigin, tx *types.Transaction) error {

slotsFree += slotsRequired(oldTxWithSameNonce) // add old tx slots
} else {
if account.enqueued.length() == account.maxEnqueued {
if account.enqueued.length() == account.maxEnqueued && tx.Nonce != accountNonce {
return ErrMaxEnqueuedLimitReached
}

Expand Down
37 changes: 37 additions & 0 deletions txpool/txpool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,43 @@ func TestEnqueueHandler(t *testing.T) {
acc.nonceToTx.unlock()
},
)

t.Run(
"accept new tx with nextNonce when enqueued is full",
func(t *testing.T) {
t.Parallel()

pool, err := newTestPool()
assert.NoError(t, err)
pool.SetSigner(&mockSigner{})

// mock full enqueued
pool.accounts.maxEnqueuedLimit = 10

// add 10 transaction in txpool i.e. max enqueued transactions
for i := uint64(1); i <= 10; i++ {
err := pool.addTx(local, newTx(addr1, i, 1))
assert.NoError(t, err)
}

assert.Equal(t, uint64(10), pool.accounts.get(addr1).enqueued.length())
assert.Equal(t, uint64(0), pool.accounts.get(addr1).promoted.length())
assert.Equal(t, uint64(0), pool.accounts.get(addr1).getNonce())

err = pool.addTx(local, newTx(addr1, 11, 1))
assert.True(t, errors.Is(err, ErrMaxEnqueuedLimitReached))

// add the transaction with nextNonce i.e. nonce=0
err = pool.addTx(local, newTx(addr1, uint64(0), 1))
assert.NoError(t, err)

pool.handlePromoteRequest(<-pool.promoteReqCh)

assert.Equal(t, uint64(0), pool.accounts.get(addr1).enqueued.length())
assert.Equal(t, uint64(11), pool.accounts.get(addr1).promoted.length())
assert.Equal(t, uint64(11), pool.accounts.get(addr1).getNonce())
},
)
}

func TestAddTx(t *testing.T) {
Expand Down

0 comments on commit 39f7d2b

Please sign in to comment.