Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed txpool maxEnqueued issue #1789

Merged
merged 2 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Stefan-Ethernal marked this conversation as resolved.
Show resolved Hide resolved
}

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
Loading