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

Pending Txs Update Insert Condition #214

Merged
merged 1 commit into from
Mar 22, 2024
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 internal/mempool/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (p *PendingTxs) Insert(tx *WrappedTx, resCheckTx *abci.ResponseCheckTxV2, t
p.mtx.Lock()
defer p.mtx.Unlock()

if len(p.txs) >= p.config.PendingSize && uint64(tx.Size())+p.sizeBytes > uint64(p.config.MaxPendingTxsBytes) {
if len(p.txs) >= p.config.PendingSize || uint64(tx.Size())+p.sizeBytes > uint64(p.config.MaxPendingTxsBytes) {
return errors.New("pending store is full")
}

Expand Down
58 changes: 58 additions & 0 deletions internal/mempool/tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/types"
)
Expand Down Expand Up @@ -304,3 +305,60 @@ func TestPendingTxsPopTxsBad(t *testing.T) {
// duplicate
require.Panics(t, func() { pendingTxs.popTxsAtIndices([]int{2, 2}) })
}

func TestPendingTxs_InsertCondition(t *testing.T) {
mempoolCfg := config.TestMempoolConfig()

// First test exceeding number of txs
mempoolCfg.PendingSize = 2

pendingTxs := NewPendingTxs(mempoolCfg)

// Transaction setup
tx1 := &WrappedTx{
tx: types.Tx("tx1_data"),
priority: 1,
}
tx1Size := tx1.Size()

tx2 := &WrappedTx{
tx: types.Tx("tx2_data"),
priority: 2,
}
tx2Size := tx2.Size()

err := pendingTxs.Insert(tx1, &abci.ResponseCheckTxV2{}, TxInfo{})
require.Nil(t, err)

err = pendingTxs.Insert(tx2, &abci.ResponseCheckTxV2{}, TxInfo{})
require.Nil(t, err)

// Should fail due to pending store size limit
tx3 := &WrappedTx{
tx: types.Tx("tx3_data_exceeding_pending_size"),
priority: 3,
}

err = pendingTxs.Insert(tx3, &abci.ResponseCheckTxV2{}, TxInfo{})
require.NotNil(t, err)

// Second test exceeding byte size condition
mempoolCfg.PendingSize = 5
pendingTxs = NewPendingTxs(mempoolCfg)
mempoolCfg.MaxPendingTxsBytes = int64(tx1Size + tx2Size)

err = pendingTxs.Insert(tx1, &abci.ResponseCheckTxV2{}, TxInfo{})
require.Nil(t, err)

err = pendingTxs.Insert(tx2, &abci.ResponseCheckTxV2{}, TxInfo{})
require.Nil(t, err)

// Should fail due to exceeding max pending transaction bytes
tx3 = &WrappedTx{
tx: types.Tx("tx3_small_but_exceeds_byte_limit"),
priority: 3,
}

err = pendingTxs.Insert(tx3, &abci.ResponseCheckTxV2{}, TxInfo{})
require.NotNil(t, err)
}
Loading