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

feat: purpose -1 to return all unconfirmed transactions in UnconfirmedTxs RPC #1675

Open
wants to merge 3 commits into
base: v0.34.x-celestia
Choose a base branch
from
Open
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
32 changes: 32 additions & 0 deletions rpc/client/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,38 @@ func TestUnconfirmedTxs(t *testing.T) {
mempool.Flush()
}

func TestUncappedUnconfirmedTxs(t *testing.T) {
mempool := node.Mempool()
numberOfTransactions := 120 // needs to be greater than maxPerPage const
for i := 0; i < numberOfTransactions; i++ {
_, _, tx := MakeTxKV()

ch := make(chan *abci.Response, 1)
err := mempool.CheckTx(tx, func(resp *abci.Response) { ch <- resp }, mempl.TxInfo{})
require.NoError(t, err)

// wait for tx to arrive in mempoool.
select {
case <-ch:
case <-time.After(5 * time.Second):
t.Error("Timed out waiting for CheckTx callback")
}
}

for _, c := range GetClients() {
mc := c.(client.MempoolClient)
limit := -1 // set the limit to -1 to return everything
res, err := mc.UnconfirmedTxs(context.Background(), &limit)
require.NoError(t, err)

assert.Equal(t, numberOfTransactions, res.Count)
assert.Equal(t, numberOfTransactions, res.Total)
assert.Equal(t, mempool.SizeBytes(), res.TotalBytes)
}

mempool.Flush()
}

func TestNumUnconfirmedTxs(t *testing.T) {
_, _, tx := MakeTxKV()

Expand Down
8 changes: 6 additions & 2 deletions rpc/core/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,13 @@ func BroadcastTxCommit(ctx *rpctypes.Context, tx types.Tx) (*ctypes.ResultBroadc
// UnconfirmedTxs gets unconfirmed transactions (maximum ?limit entries)
// including their number.
// More: https://docs.cometbft.com/v0.34/rpc/#/Info/unconfirmed_txs
// If limitPtr == -1, it will return all the unconfirmed transactions in the mempool.
func UnconfirmedTxs(ctx *rpctypes.Context, limitPtr *int) (*ctypes.ResultUnconfirmedTxs, error) {
// reuse per_page validator
limit := validatePerPage(limitPtr)
limit := *limitPtr
if limit != -1 {
// reuse per_page validator
limit = validatePerPage(limitPtr)
}
env := GetEnvironment()

txs := env.Mempool.ReapMaxTxs(limit)
Expand Down
2 changes: 1 addition & 1 deletion rpc/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@ paths:
parameters:
- in: query
name: limit
description: Maximum number of unconfirmed transactions to return (max 100)
description: Maximum number of unconfirmed transactions to return (max 100). If set to -1, it will return all the unconfirmed mempool transactions.
required: false
schema:
type: integer
Expand Down
Loading