Skip to content

Commit ecd567a

Browse files
jonasschnellipromagjonatack
authored andcommitted
RPC/blockchain: Consider ancestor, descendant, and combined fee rates for histogram in getmempoolinfo
Test changes from: bitcoin@0b6ba66 Co-authored-by: João Barbosa <[email protected]> Co-authored-by: Jon Atack <[email protected]>
1 parent 1d566c0 commit ecd567a

File tree

2 files changed

+31
-21
lines changed

2 files changed

+31
-21
lines changed

src/rpc/mempool.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,18 @@ UniValue MempoolInfoToJSON(const CTxMemPool& pool, const std::optional<MempoolHi
693693
for (const CTxMemPoolEntry& e : pool.mapTx) {
694694
const CAmount fee{e.GetFee()};
695695
const uint32_t size{uint32_t(e.GetTxSize())};
696-
const CAmount fee_rate{CFeeRate{fee, size}.GetFee(1)};
696+
697+
const CAmount afees{e.GetModFeesWithAncestors()}, dfees{e.GetModFeesWithDescendants()};
698+
const uint32_t asize{uint32_t(e.GetSizeWithAncestors())}, dsize{uint32_t(e.GetSizeWithDescendants())};
699+
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
703+
704+
// Fee rate per byte including ancestors & descendants
705+
const CAmount tfpb{CFeeRate{afees + dfees - fee, asize + dsize - size}.GetFee(1)};
706+
707+
const CAmount fee_rate{std::max(std::min(dfpb, tfpb), std::min(fpb, afpb))};
697708

698709
// Distribute fee rates
699710
for (size_t i = floors.size(); i-- > 0;) {

test/functional/mempool_fee_histogram.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,11 @@ def run_test(self):
9393
self.log.info("Test fee rate histogram when mempool contains 2 transactions (tx1: 5 sat/vB, tx2: 14 sat/vB)")
9494
info = node.getmempoolinfo([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
9595

96-
# Verify that tx1 and tx2 are reported in 5 sat/vB and 14 sat/vB in fee rate groups respectively
96+
# Verify that both tx1 and tx2 are reported in 8 sat/vB fee rate group
9797
(non_empty_groups, empty_groups, total_fees) = self.histogram_stats(info['fee_histogram'])
98-
assert_equal(2, non_empty_groups)
99-
assert_equal(13, empty_groups)
100-
assert_equal(1, info['fee_histogram']['fee_rate_groups']['5']['count'])
101-
assert_equal(1, info['fee_histogram']['fee_rate_groups']['14']['count'])
98+
assert_equal(1, non_empty_groups)
99+
assert_equal(14, empty_groups)
100+
assert_equal(2, info['fee_histogram']['fee_rate_groups']['8']['count'])
102101
assert_equal(total_fees, info['fee_histogram']['total_fees'])
103102

104103
# Unlock the second UTXO which we locked
@@ -110,31 +109,31 @@ def run_test(self):
110109
self.log.info("Test fee rate histogram when mempool contains 3 transactions (tx1: 5 sat/vB, tx2: 14 sat/vB, tx3: 6 sat/vB)")
111110
info = node.getmempoolinfo([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
112111

113-
# Verify that each of 5, 6 and 14 sat/vB fee rate groups contain one transaction
112+
# Verify that each of 6, 7 and 8 sat/vB fee rate groups contain one transaction
114113
(non_empty_groups, empty_groups, total_fees) = self.histogram_stats(info['fee_histogram'])
115114
assert_equal(3, non_empty_groups)
116115
assert_equal(12, empty_groups)
117116

118-
for i in ['1', '2', '3', '4', '7', '8', '9', '10', '11', '12', '13', '15']:
117+
for i in ['1', '2', '3', '4', '5', '9', '10', '11', '12', '13', '14', '15']:
119118
assert_equal(0, info['fee_histogram']['fee_rate_groups'][i]['size'])
120119
assert_equal(0, info['fee_histogram']['fee_rate_groups'][i]['count'])
121120
assert_equal(0, info['fee_histogram']['fee_rate_groups'][i]['fees'])
122121
assert_equal(int(i), info['fee_histogram']['fee_rate_groups'][i]['from'])
123122

124-
assert_equal(188, info['fee_histogram']['fee_rate_groups']['5']['size'])
125-
assert_equal(1, info['fee_histogram']['fee_rate_groups']['5']['count'])
126-
assert_equal(940, info['fee_histogram']['fee_rate_groups']['5']['fees'])
127-
assert_equal(5, info['fee_histogram']['fee_rate_groups']['5']['from'])
128-
129-
assert_equal(356, info['fee_histogram']['fee_rate_groups']['6']['size'])
123+
assert_equal(188, info['fee_histogram']['fee_rate_groups']['6']['size'])
130124
assert_equal(1, info['fee_histogram']['fee_rate_groups']['6']['count'])
131-
assert_equal(2136, info['fee_histogram']['fee_rate_groups']['6']['fees'])
132-
assert_equal(6, info['fee_histogram']['fee_rate_groups']['6']['from'])
133-
134-
assert_equal(141, info['fee_histogram']['fee_rate_groups']['14']['size'])
135-
assert_equal(1, info['fee_histogram']['fee_rate_groups']['14']['count'])
136-
assert_equal(1974, info['fee_histogram']['fee_rate_groups']['14']['fees'])
137-
assert_equal(14, info['fee_histogram']['fee_rate_groups']['14']['from'])
125+
assert_equal(940, info['fee_histogram']['fee_rate_groups']['6']['fees'])
126+
assert_equal(5, info['fee_histogram']['fee_rate_groups']['6']['from'])
127+
128+
assert_equal(356, info['fee_histogram']['fee_rate_groups']['7']['size'])
129+
assert_equal(1, info['fee_histogram']['fee_rate_groups']['7']['count'])
130+
assert_equal(2136, info['fee_histogram']['fee_rate_groups']['7']['fees'])
131+
assert_equal(6, info['fee_histogram']['fee_rate_groups']['7']['from'])
132+
133+
assert_equal(141, info['fee_histogram']['fee_rate_groups']['8']['size'])
134+
assert_equal(1, info['fee_histogram']['fee_rate_groups']['8']['count'])
135+
assert_equal(1974, info['fee_histogram']['fee_rate_groups']['8']['fees'])
136+
assert_equal(14, info['fee_histogram']['fee_rate_groups']['8']['from'])
138137

139138
assert_equal(total_fees, info['fee_histogram']['total_fees'])
140139

0 commit comments

Comments
 (0)