Skip to content

Commit 9ebe860

Browse files
committed
Bugfix: RPC/blockchain: Actually round feerates down for getmempoolinfo fee histograms
1 parent d10e35a commit 9ebe860

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/rpc/mempool.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -697,12 +697,14 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool, const std::optional<MempoolHi
697697
const CAmount afees{e.GetModFeesWithAncestors()}, dfees{e.GetModFeesWithDescendants()};
698698
const uint32_t asize{uint32_t(e.GetSizeWithAncestors())}, dsize{uint32_t(e.GetSizeWithDescendants())};
699699

700-
const CAmount fpb{CFeeRate{fee, size}.GetFee(1)}; // Fee rate per byte
701-
const CAmount afpb{CFeeRate{afees, asize}.GetFee(1)}; // Fee rate per byte including ancestors
702-
const CAmount dfpb{CFeeRate{dfees, dsize}.GetFee(1)}; // Fee rate per byte including descendants
700+
// Do not use CFeeRate here, since it rounds up, and this should be rounding down
701+
const CAmount fpb{fee / size}; // Fee rate per byte
702+
const CAmount afpb{afees / asize}; // Fee rate per byte including ancestors
703+
const CAmount dfpb{dfees / dsize}; // Fee rate per byte including descendants
703704

704705
// Fee rate per byte including ancestors & descendants
705-
const CAmount tfpb{CFeeRate{afees + dfees - fee, asize + dsize - size}.GetFee(1)};
706+
// (fee/size are included in both, so subtracted to avoid double-counting)
707+
const CAmount tfpb{(afees + dfees - fee) / (asize + dsize - size)};
706708

707709
const CAmount fee_rate{std::max(std::min(dfpb, tfpb), std::min(fpb, afpb))};
708710

test/functional/mempool_fee_histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def run_test(self):
110110
self.log.info(f"Test fee rate histogram when mempool contains 2 transactions (tx1: {tx1_info['feerate']} sat/vB, tx2: {tx2_info['feerate']} sat/vB)")
111111
info = node.getmempoolinfo([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
112112

113-
# Verify that both tx1 and tx2 are reported in 9 sat/vB fee rate group
113+
# Verify that both tx1 and tx2 are reported in 8 sat/vB fee rate group
114114
(non_empty_groups, empty_groups, total_fees) = self.histogram_stats(info['fee_histogram'])
115115
tx1p2_feerate = get_actual_fee_rate(tx1_info['fee'] + tx2_info['fee'], tx1_info['vsize'] + tx2_info['vsize'])
116116
assert_equal(1, non_empty_groups)

0 commit comments

Comments
 (0)