Skip to content

Commit 521f921

Browse files
kiminuoluke-jr
authored andcommitted
RPC/mempool: Add "to" (end of range) field to fee histogram
Co-authored-by: Jonas Schnelli <[email protected]> Co-authored-by: Jon Atack <[email protected]> Github-Pull: bitcoin#21422 Rebased-From: 0b87ba9
1 parent 64e50cb commit 521f921

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/rpc/mempool.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,12 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool, const std::optional<MempoolHi
727727
info_sub.pushKV("fees", fees.at(i));
728728
info_sub.pushKV("from", floors.at(i));
729729

730+
if (i == floors.size() - 1) {
731+
info_sub.pushKV("to", NullUniValue);
732+
} else {
733+
info_sub.pushKV("to", floors[i + 1] - 1);
734+
}
735+
730736
total_fees += fees.at(i);
731737
groups.pushKV(ToString(floors.at(i)), info_sub);
732738
}
@@ -775,6 +781,7 @@ static RPCHelpMan getmempoolinfo()
775781
{RPCResult::Type::NUM, "count", "Number of transactions in the fee rate group"},
776782
{RPCResult::Type::NUM, "fees", "Cumulative fees of all transactions in the fee rate group (in " + CURRENCY_ATOM + ")"},
777783
{RPCResult::Type::NUM, "from", "Group contains transactions with fee rates equal or greater than this value (in " + CURRENCY_ATOM + "/vB)"},
784+
{RPCResult::Type::ANY, "to", "Group contains transactions with fee rates equal or less than this value (in " + CURRENCY_ATOM + "/vB)"},
778785
}}}},
779786
{RPCResult::Type::NUM, "total_fees", "Total available fees in mempool (in " + CURRENCY_ATOM + ")"},
780787
}},

test/functional/mempool_fee_histogram.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ def run_test(self):
136136
'fee_rate_groups': dict( (
137137
(str(n), {
138138
'from': n,
139+
'to': n,
139140
'count': 0,
140141
'fees': 0,
141142
'size': 0,
@@ -144,6 +145,7 @@ def run_test(self):
144145
'total_fees': tx1_info['fee'] + tx2_info['fee'] + tx3_info['fee'],
145146
}
146147
expected_frg = expected_histogram['fee_rate_groups']
148+
expected_frg['15']['to'] = None
147149
tx1p2p3_feerate = get_actual_fee_rate(expected_histogram['total_fees'], tx1_info['vsize'] + tx2_info['vsize'] + tx3_info['vsize'])
148150
def inc_expected(feerate, txinfo):
149151
this_frg = expected_frg[feerate]
@@ -163,10 +165,18 @@ def inc_expected(feerate, txinfo):
163165
for collapse_n in (9, 11, 13, 15):
164166
for field in ('count', 'size', 'fees'):
165167
expected_frg[str(collapse_n - 1)][field] += expected_frg[str(collapse_n)][field]
168+
expected_frg[str(collapse_n - 1)]['to'] += 1
166169
del expected_frg[str(collapse_n)]
170+
expected_frg['14']['to'] += 1 # 16 is also skipped
167171

168172
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)] == {
173+
frinfo = info['fee_histogram']['fee_rate_groups'][str(new_n)]
174+
if new_n == 10000:
175+
assert frinfo['to'] is None
176+
else:
177+
assert frinfo['to'] > frinfo['from']
178+
del frinfo['to']
179+
assert_equal(frinfo, {
170180
'from': new_n,
171181
'count': 0,
172182
'fees': 0,
@@ -191,6 +201,8 @@ def histogram_stats(self, histogram):
191201
assert_equal(bin['count'], 0)
192202
assert_greater_than_or_equal(bin['fees'], 0)
193203
assert_greater_than_or_equal(bin['size'], 0)
204+
if bin['to'] is not None:
205+
assert_greater_than_or_equal(bin['to'], bin['from'])
194206
total_fees += bin['fees']
195207

196208
if bin['count'] == 0:

0 commit comments

Comments
 (0)