expose mempool's txs_total_bytes via RPC

This commit is contained in:
Anton Kaliaev
2019-02-05 21:22:18 +04:00
parent b2a47d1269
commit d20b508c2b
4 changed files with 37 additions and 21 deletions
+3
View File
@@ -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
+3 -1
View File
@@ -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()
+27 -18
View File
@@ -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
}
+4 -2
View File
@@ -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