diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index d9fdacda8..12138335c 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -7,6 +7,7 @@ Special thanks to external contributors on this release: ### BREAKING CHANGES: * CLI/RPC/Config + - [rpc] \#3113 rename n_txs to count in `/num_unconfirmed_txs` and `/unconfirmed_txs` * Apps @@ -19,6 +20,8 @@ Special thanks to external contributors on this release: ### FEATURES: - [mempool] \#3079 bound mempool memory usage (`mempool.max_txs_total_bytes` is set to 1GB by default; see config.toml) + mempool's current `txs_total_bytes` is exposed via `total_bytes` field in + `/num_unconfirmed_txs` and `/unconfirmed_txs` RPC endpoints. ### IMPROVEMENTS: - [tools] add go-deadlock tool to help detect deadlocks diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index 8ae88f43b..6926f8e44 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -311,7 +311,9 @@ func TestNumUnconfirmedTxs(t *testing.T) { res, err := mc.NumUnconfirmedTxs() require.Nil(t, err, "%d: %+v", i, err) - assert.Equal(t, mempoolSize, res.N) + assert.Equal(t, mempoolSize, res.Count) + assert.Equal(t, mempoolSize, res.Total) + assert.Equal(t, mempool.TxsTotalBytes(), res.TotalBytes) } mempool.Flush() diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index ff6b029cf..f0934c708 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -255,27 +255,32 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { // // ```json // { -// "error": "", -// "result": { -// "txs": [], -// "n_txs": "0" -// }, -// "id": "", -// "jsonrpc": "2.0" -// } +// "result" : { +// "txs" : [], +// "total_bytes" : "0", +// "count" : "0", +// "total" : "0" +// }, +// "jsonrpc" : "2.0", +// "id" : "" +// } +// ``` // // ### Query Parameters // // | Parameter | Type | Default | Required | Description | // |-----------+------+---------+----------+--------------------------------------| // | limit | int | 30 | false | Maximum number of entries (max: 100) | -// ``` func UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error) { // reuse per_page validator limit = validatePerPage(limit) txs := mempool.ReapMaxTxs(limit) - return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil + return &ctypes.ResultUnconfirmedTxs{ + Count: len(txs), + Total: mempool.Size(), + TotalBytes: mempool.TxsTotalBytes(), + Txs: txs}, nil } // Get number of unconfirmed transactions. @@ -298,15 +303,19 @@ func UnconfirmedTxs(limit int) (*ctypes.ResultUnconfirmedTxs, error) { // // ```json // { -// "error": "", -// "result": { -// "txs": null, -// "n_txs": "0" -// }, -// "id": "", -// "jsonrpc": "2.0" +// "jsonrpc" : "2.0", +// "id" : "", +// "result" : { +// "count" : "0", +// "total_bytes" : "0", +// "txs" : null, +// "total" : "0" +// } // } // ``` func NumUnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) { - return &ctypes.ResultUnconfirmedTxs{N: mempool.Size()}, nil + return &ctypes.ResultUnconfirmedTxs{ + Count: mempool.Size(), + Total: mempool.Size(), + TotalBytes: mempool.TxsTotalBytes()}, nil } diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 62be1cafd..b1e586b5b 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -179,8 +179,10 @@ type ResultTxSearch struct { // List of mempool txs type ResultUnconfirmedTxs struct { - N int `json:"n_txs"` - Txs []types.Tx `json:"txs"` + Count int `json:"count"` + Total int `json:"total"` + TotalBytes int64 `json:"total_bytes"` + Txs []types.Tx `json:"txs"` } // Info abci msg