Skip to content

Commit b9b320c

Browse files
committed
RPC/blockchain: getmempoolinfo: Enable specifying with_fee_histogram as a boolean to use a sensible default set of fee rate levels
1 parent eb93c8b commit b9b320c

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

src/rpc/client.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
251251
{ "pruneblockchain", 0, "height" },
252252
{ "keypoolrefill", 0, "newsize" },
253253
{ "getmempoolinfo", 0, "fee_histogram" },
254+
{ "getmempoolinfo", 0, "with_fee_histogram" },
254255
{ "getrawmempool", 0, "verbose" },
255256
{ "getrawmempool", 1, "mempool_sequence" },
256257
{ "estimatesmartfee", 0, "conf_target" },

src/rpc/mempool.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ static RPCHelpMan getmempoolinfo()
745745
return RPCHelpMan{"getmempoolinfo",
746746
"Returns details on the active state of the TX memory pool.\n",
747747
{
748-
{"fee_histogram", RPCArg::Type::ARR, RPCArg::Optional::OMITTED, "Fee statistics grouped by fee rate ranges",
748+
{"fee_histogram|with_fee_histogram", {RPCArg::Type::ARR, RPCArg::Type::BOOL}, RPCArg::Optional::OMITTED, "Fee statistics grouped by fee rate ranges",
749749
{
750750
{"fee_rate", RPCArg::Type::NUM, RPCArg::Optional::NO, "Fee rate (in " + CURRENCY_ATOM + "/vB) to group the fees by"},
751751
},
@@ -790,7 +790,11 @@ static RPCHelpMan getmempoolinfo()
790790
MempoolHistogramFeeRates histogram_floors;
791791
std::optional<MempoolHistogramFeeRates> histogram_floors_opt = std::nullopt;
792792

793-
if (!request.params[0].isNull()) {
793+
if (request.params[0].isBool()) {
794+
if (request.params[0].isTrue()) {
795+
histogram_floors_opt = MempoolInfoToJSON_const_histogram_floors;
796+
}
797+
} else if (!request.params[0].isNull()) {
794798
const UniValue histogram_floors_univalue = request.params[0].get_array();
795799

796800
if (histogram_floors_univalue.empty()) {

src/rpc/mempool.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ class UniValue;
1515

1616
typedef std::vector<CAmount> MempoolHistogramFeeRates;
1717

18+
/* TODO: define log scale formular for dynamically creating the
19+
* feelimits but with the property of not constantly changing
20+
* (and thus screw up client implementations) */
21+
static const MempoolHistogramFeeRates MempoolInfoToJSON_const_histogram_floors{
22+
1, 2, 3, 4, 5, 6, 7, 8, 10,
23+
12, 14, 17, 20, 25, 30, 40, 50, 60, 70, 80, 100,
24+
120, 140, 170, 200, 250, 300, 400, 500, 600, 700, 800, 1000,
25+
1200, 1400, 1700, 2000, 2500, 3000, 4000, 5000, 6000, 7000, 8000, 10000};
26+
1827
/** Mempool information to JSON */
1928
UniValue MempoolInfoToJSON(const CTxMemPool& pool, const std::optional<MempoolHistogramFeeRates>& histogram_floors);
2029

test/functional/mempool_fee_histogram.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ def inc_expected(feerate, txinfo):
156156

157157
assert_equal(expected_histogram, info['fee_histogram'])
158158

159+
self.log.info("Test fee rate histogram with default groups")
160+
info = node.getmempoolinfo(with_fee_histogram=True)
161+
162+
# Verify that the 6 sat/vB fee rate group has one transaction, and the 8-9 sat/vB fee rate group has two
163+
for collapse_n in (9, 11, 13, 15):
164+
for field in ('count', 'size', 'fees'):
165+
expected_frg[str(collapse_n - 1)][field] += expected_frg[str(collapse_n)][field]
166+
del expected_frg[str(collapse_n)]
167+
168+
for new_n in (17, 20, 25) + tuple(range(30, 90, 10)) + (100, 120, 140, 170, 200, 250) + tuple(range(300, 900, 100)) + (1000, 1200, 1400, 1700, 2000, 2500) + tuple(range(3000, 9000, 1000)) + (10000,):
169+
assert(info['fee_histogram']['fee_rate_groups'][str(new_n)] == {
170+
'from': new_n,
171+
'count': 0,
172+
'fees': 0,
173+
'size': 0,
174+
})
175+
del info['fee_histogram']['fee_rate_groups'][str(new_n)]
176+
assert_equal(expected_histogram, info['fee_histogram'])
177+
178+
self.log.info("Test getmempoolinfo(with_fee_histogram=False) does not return fee histogram")
179+
assert('fee_histogram' not in node.getmempoolinfo(with_fee_histogram=False))
180+
159181
def histogram_stats(self, histogram):
160182
total_fees = 0
161183
empty_count = 0

0 commit comments

Comments
 (0)