RPC/mempool: Add "to" (end of range) field to fee histogram

Co-authored-by: Jonas Schnelli <dev@jonasschnelli.ch>
Co-authored-by: Jon Atack <jon@atack.com>

Github-Pull: #21422
Rebased-From: 0b87ba9bc3a2ada2839af0e1af868fcd5ddb9155
This commit is contained in:
Kiminuo 2021-03-06 20:30:17 +01:00 committed by Luke Dashjr
parent 64e50cbb7d
commit 521f921d83
2 changed files with 20 additions and 1 deletions

View File

@ -727,6 +727,12 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool, const std::optional<MempoolHi
info_sub.pushKV("fees", fees.at(i));
info_sub.pushKV("from", floors.at(i));
if (i == floors.size() - 1) {
info_sub.pushKV("to", NullUniValue);
} else {
info_sub.pushKV("to", floors[i + 1] - 1);
}
total_fees += fees.at(i);
groups.pushKV(ToString(floors.at(i)), info_sub);
}
@ -775,6 +781,7 @@ static RPCHelpMan getmempoolinfo()
{RPCResult::Type::NUM, "count", "Number of transactions in the fee rate group"},
{RPCResult::Type::NUM, "fees", "Cumulative fees of all transactions in the fee rate group (in " + CURRENCY_ATOM + ")"},
{RPCResult::Type::NUM, "from", "Group contains transactions with fee rates equal or greater than this value (in " + CURRENCY_ATOM + "/vB)"},
{RPCResult::Type::ANY, "to", "Group contains transactions with fee rates equal or less than this value (in " + CURRENCY_ATOM + "/vB)"},
}}}},
{RPCResult::Type::NUM, "total_fees", "Total available fees in mempool (in " + CURRENCY_ATOM + ")"},
}},

View File

@ -136,6 +136,7 @@ class MempoolFeeHistogramTest(BitcoinTestFramework):
'fee_rate_groups': dict( (
(str(n), {
'from': n,
'to': n,
'count': 0,
'fees': 0,
'size': 0,
@ -144,6 +145,7 @@ class MempoolFeeHistogramTest(BitcoinTestFramework):
'total_fees': tx1_info['fee'] + tx2_info['fee'] + tx3_info['fee'],
}
expected_frg = expected_histogram['fee_rate_groups']
expected_frg['15']['to'] = None
tx1p2p3_feerate = get_actual_fee_rate(expected_histogram['total_fees'], tx1_info['vsize'] + tx2_info['vsize'] + tx3_info['vsize'])
def inc_expected(feerate, txinfo):
this_frg = expected_frg[feerate]
@ -163,10 +165,18 @@ class MempoolFeeHistogramTest(BitcoinTestFramework):
for collapse_n in (9, 11, 13, 15):
for field in ('count', 'size', 'fees'):
expected_frg[str(collapse_n - 1)][field] += expected_frg[str(collapse_n)][field]
expected_frg[str(collapse_n - 1)]['to'] += 1
del expected_frg[str(collapse_n)]
expected_frg['14']['to'] += 1 # 16 is also skipped
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,):
assert(info['fee_histogram']['fee_rate_groups'][str(new_n)] == {
frinfo = info['fee_histogram']['fee_rate_groups'][str(new_n)]
if new_n == 10000:
assert frinfo['to'] is None
else:
assert frinfo['to'] > frinfo['from']
del frinfo['to']
assert_equal(frinfo, {
'from': new_n,
'count': 0,
'fees': 0,
@ -191,6 +201,8 @@ class MempoolFeeHistogramTest(BitcoinTestFramework):
assert_equal(bin['count'], 0)
assert_greater_than_or_equal(bin['fees'], 0)
assert_greater_than_or_equal(bin['size'], 0)
if bin['to'] is not None:
assert_greater_than_or_equal(bin['to'], bin['from'])
total_fees += bin['fees']
if bin['count'] == 0: