Skip to content

Commit 9aa0b20

Browse files
Kbhat1udpatil
authored andcommitted
Pending Txs Update Condition (#214)
1 parent e2af783 commit 9aa0b20

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

internal/mempool/tx.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func (p *PendingTxs) Insert(tx *WrappedTx, resCheckTx *abci.ResponseCheckTxV2, t
377377
p.mtx.Lock()
378378
defer p.mtx.Unlock()
379379

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

internal/mempool/tx_test.go

+58
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/stretchr/testify/require"
1111

12+
abci "github.com/tendermint/tendermint/abci/types"
1213
"github.com/tendermint/tendermint/config"
1314
"github.com/tendermint/tendermint/types"
1415
)
@@ -304,3 +305,60 @@ func TestPendingTxsPopTxsBad(t *testing.T) {
304305
// duplicate
305306
require.Panics(t, func() { pendingTxs.popTxsAtIndices([]int{2, 2}) })
306307
}
308+
309+
func TestPendingTxs_InsertCondition(t *testing.T) {
310+
mempoolCfg := config.TestMempoolConfig()
311+
312+
// First test exceeding number of txs
313+
mempoolCfg.PendingSize = 2
314+
315+
pendingTxs := NewPendingTxs(mempoolCfg)
316+
317+
// Transaction setup
318+
tx1 := &WrappedTx{
319+
tx: types.Tx("tx1_data"),
320+
priority: 1,
321+
}
322+
tx1Size := tx1.Size()
323+
324+
tx2 := &WrappedTx{
325+
tx: types.Tx("tx2_data"),
326+
priority: 2,
327+
}
328+
tx2Size := tx2.Size()
329+
330+
err := pendingTxs.Insert(tx1, &abci.ResponseCheckTxV2{}, TxInfo{})
331+
require.Nil(t, err)
332+
333+
err = pendingTxs.Insert(tx2, &abci.ResponseCheckTxV2{}, TxInfo{})
334+
require.Nil(t, err)
335+
336+
// Should fail due to pending store size limit
337+
tx3 := &WrappedTx{
338+
tx: types.Tx("tx3_data_exceeding_pending_size"),
339+
priority: 3,
340+
}
341+
342+
err = pendingTxs.Insert(tx3, &abci.ResponseCheckTxV2{}, TxInfo{})
343+
require.NotNil(t, err)
344+
345+
// Second test exceeding byte size condition
346+
mempoolCfg.PendingSize = 5
347+
pendingTxs = NewPendingTxs(mempoolCfg)
348+
mempoolCfg.MaxPendingTxsBytes = int64(tx1Size + tx2Size)
349+
350+
err = pendingTxs.Insert(tx1, &abci.ResponseCheckTxV2{}, TxInfo{})
351+
require.Nil(t, err)
352+
353+
err = pendingTxs.Insert(tx2, &abci.ResponseCheckTxV2{}, TxInfo{})
354+
require.Nil(t, err)
355+
356+
// Should fail due to exceeding max pending transaction bytes
357+
tx3 = &WrappedTx{
358+
tx: types.Tx("tx3_small_but_exceeds_byte_limit"),
359+
priority: 3,
360+
}
361+
362+
err = pendingTxs.Insert(tx3, &abci.ResponseCheckTxV2{}, TxInfo{})
363+
require.NotNil(t, err)
364+
}

0 commit comments

Comments
 (0)