Skip to content

Commit cd60336

Browse files
committed
Merge bitcoin/bitcoin#28885: mempool / rpc: followup to getprioritisedtransactions and delete a mapDeltas entry when delta==0
0eebd6f test: Assert that a new tx with a delta of 0 is never added (kevkevin) cfdbcd1 rpc: exposing modified_fee in getprioritisedtransactions (kevkevin) 252a867 rpc: renaming txid -> transactionid (kevkevin) 2fca6c2 rpc: changed prioritisation-map -> "" (kevkevin) 3a118e1 test: Directly constructing 2 entry map for getprioritisedtransactions (kevkevin) Pull request description: In this PR I am addressing some comments in bitcoin/bitcoin#27501 as a followup. - changed `prioritisation-map` in the `RPCResult` to `""` - Directly constructing 2 entry map for getprioritisedtransactions in functional tests - renamed `txid` to `transactionid` in `RPCResult` to be more consistent with naming elsewhere - exposed the `modified_fee` field instead of having it be a useless arg - Created a new test that asserts when `prioritisedtransaction` is called with a fee_delta of 0 it is not added to mempool ACKs for top commit: glozow: reACK 0eebd6f, only change is the doc suggestion Tree-SHA512: e99056e37a8b1cfc511d87c83edba7c928b50d2cd6c2fd7c038976779850677ad37fddeb2b983e8bc007ca8567eb21ebb78d7eae9b773657c2b297299993ec05
2 parents 8c5e4f4 + 0eebd6f commit cd60336

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

src/rpc/mining.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,12 @@ static RPCHelpMan getprioritisedtransactions()
495495
"Returns a map of all user-created (see prioritisetransaction) fee deltas by txid, and whether the tx is present in mempool.",
496496
{},
497497
RPCResult{
498-
RPCResult::Type::OBJ_DYN, "prioritisation-map", "prioritisation keyed by txid",
498+
RPCResult::Type::OBJ_DYN, "", "prioritisation keyed by txid",
499499
{
500-
{RPCResult::Type::OBJ, "txid", "", {
500+
{RPCResult::Type::OBJ, "<transactionid>", "", {
501501
{RPCResult::Type::NUM, "fee_delta", "transaction fee delta in satoshis"},
502502
{RPCResult::Type::BOOL, "in_mempool", "whether this transaction is currently in mempool"},
503+
{RPCResult::Type::NUM, "modified_fee", /*optional=*/true, "modified fee in satoshis. Only returned if in_mempool=true"},
503504
}}
504505
},
505506
},
@@ -516,6 +517,9 @@ static RPCHelpMan getprioritisedtransactions()
516517
UniValue result_inner{UniValue::VOBJ};
517518
result_inner.pushKV("fee_delta", delta_info.delta);
518519
result_inner.pushKV("in_mempool", delta_info.in_mempool);
520+
if (delta_info.in_mempool) {
521+
result_inner.pushKV("modified_fee", *delta_info.modified_fee);
522+
}
519523
rpc_result.pushKV(delta_info.txid.GetHex(), result_inner);
520524
}
521525
return rpc_result;

test/functional/mempool_expiry.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ def test_transaction_expiry(self, timeout):
3636
node = self.nodes[0]
3737

3838
# Send a parent transaction that will expire.
39-
parent_txid = self.wallet.send_self_transfer(from_node=node)['txid']
39+
parent = self.wallet.send_self_transfer(from_node=node)
40+
parent_txid = parent["txid"]
4041
parent_utxo = self.wallet.get_utxo(txid=parent_txid)
4142
independent_utxo = self.wallet.get_utxo()
4243

4344
# Add prioritisation to this transaction to check that it persists after the expiry
4445
node.prioritisetransaction(parent_txid, 0, COIN)
45-
assert_equal(node.getprioritisedtransactions()[parent_txid], { "fee_delta" : COIN, "in_mempool" : True})
46+
assert_equal(node.getprioritisedtransactions()[parent_txid], { "fee_delta" : COIN, "in_mempool" : True, "modified_fee": COIN + COIN * parent["fee"] })
4647

4748
# Ensure the transactions we send to trigger the mempool check spend utxos that are independent of
4849
# the transactions being tested for expiration.

test/functional/mining_prioritisetransaction.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ def test_replacement(self):
4545
self.nodes[0].prioritisetransaction(tx_replacee["txid"], 0, 100)
4646
assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : 100, "in_mempool" : False}})
4747
self.nodes[0].sendrawtransaction(tx_replacee["hex"])
48-
assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : 100, "in_mempool" : True}})
48+
assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : 100, "in_mempool" : True, "modified_fee": int(tx_replacee["fee"] * COIN + 100)}})
4949
self.nodes[0].sendrawtransaction(tx_replacement["hex"])
5050
assert tx_replacee["txid"] not in self.nodes[0].getrawmempool()
5151
assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : 100, "in_mempool" : False}})
5252

5353
# PrioritiseTransaction is additive
5454
self.nodes[0].prioritisetransaction(tx_replacee["txid"], 0, COIN)
5555
self.nodes[0].sendrawtransaction(tx_replacee["hex"])
56-
assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : COIN + 100, "in_mempool" : True}})
56+
assert_equal(self.nodes[0].getprioritisedtransactions(), { tx_replacee["txid"] : { "fee_delta" : COIN + 100, "in_mempool" : True, "modified_fee": int(tx_replacee["fee"] * COIN + COIN + 100)}})
5757
self.generate(self.nodes[0], 1)
5858
assert_equal(self.nodes[0].getprioritisedtransactions(), {})
5959

@@ -111,9 +111,7 @@ def test_diamond(self):
111111
raw_after = self.nodes[0].getrawmempool(verbose=True)
112112
assert_equal(raw_before[txid_a], raw_after[txid_a])
113113
assert_equal(raw_before, raw_after)
114-
prioritisation_map_in_mempool = self.nodes[0].getprioritisedtransactions()
115-
assert_equal(prioritisation_map_in_mempool[txid_b], {"fee_delta" : fee_delta_b*COIN, "in_mempool" : True})
116-
assert_equal(prioritisation_map_in_mempool[txid_c], {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : True})
114+
assert_equal(self.nodes[0].getprioritisedtransactions(), {txid_b: {"fee_delta" : fee_delta_b*COIN, "in_mempool" : True, "modified_fee": int(fee_delta_b*COIN + COIN * tx_o_b["fee"])}, txid_c: {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : True, "modified_fee": int((fee_delta_c_1 + fee_delta_c_2 ) * COIN + COIN * tx_o_c["fee"])}})
117115
# Clear prioritisation, otherwise the transactions' fee deltas are persisted to mempool.dat and loaded again when the node
118116
# is restarted at the end of this subtest. Deltas are removed when a transaction is mined, but only at that time. We do
119117
# not check whether mapDeltas transactions were mined when loading from mempool.dat.
@@ -126,17 +124,13 @@ def test_diamond(self):
126124
self.nodes[0].prioritisetransaction(txid=txid_b, fee_delta=int(fee_delta_b * COIN))
127125
self.nodes[0].prioritisetransaction(txid=txid_c, fee_delta=int(fee_delta_c_1 * COIN))
128126
self.nodes[0].prioritisetransaction(txid=txid_c, fee_delta=int(fee_delta_c_2 * COIN))
129-
prioritisation_map_not_in_mempool = self.nodes[0].getprioritisedtransactions()
130-
assert_equal(prioritisation_map_not_in_mempool[txid_b], {"fee_delta" : fee_delta_b*COIN, "in_mempool" : False})
131-
assert_equal(prioritisation_map_not_in_mempool[txid_c], {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : False})
127+
assert_equal(self.nodes[0].getprioritisedtransactions(), {txid_b: {"fee_delta" : fee_delta_b*COIN, "in_mempool" : False}, txid_c: {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : False}})
132128
for t in [tx_o_a["hex"], tx_o_b["hex"], tx_o_c["hex"], tx_o_d["hex"]]:
133129
self.nodes[0].sendrawtransaction(t)
134130
raw_after = self.nodes[0].getrawmempool(verbose=True)
135131
assert_equal(raw_before[txid_a], raw_after[txid_a])
136132
assert_equal(raw_before, raw_after)
137-
prioritisation_map_in_mempool = self.nodes[0].getprioritisedtransactions()
138-
assert_equal(prioritisation_map_in_mempool[txid_b], {"fee_delta" : fee_delta_b*COIN, "in_mempool" : True})
139-
assert_equal(prioritisation_map_in_mempool[txid_c], {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : True})
133+
assert_equal(self.nodes[0].getprioritisedtransactions(), {txid_b: {"fee_delta" : fee_delta_b*COIN, "in_mempool" : True, "modified_fee": int(fee_delta_b*COIN + COIN * tx_o_b["fee"])}, txid_c: {"fee_delta" : (fee_delta_c_1 + fee_delta_c_2)*COIN, "in_mempool" : True, "modified_fee": int((fee_delta_c_1 + fee_delta_c_2 ) * COIN + COIN * tx_o_c["fee"])}})
140134

141135
# Clear mempool
142136
self.generate(self.nodes[0], 1)
@@ -217,7 +211,7 @@ def run_test(self):
217211
# add a fee delta to something in the cheapest bucket and make sure it gets mined
218212
# also check that a different entry in the cheapest bucket is NOT mined
219213
self.nodes[0].prioritisetransaction(txid=txids[0][0], fee_delta=int(3*base_fee*COIN))
220-
assert_equal(self.nodes[0].getprioritisedtransactions(), {txids[0][0] : { "fee_delta" : 3*base_fee*COIN, "in_mempool" : True}})
214+
assert_equal(self.nodes[0].getprioritisedtransactions(), {txids[0][0] : { "fee_delta" : 3*base_fee*COIN, "in_mempool" : True, "modified_fee": int(3*base_fee*COIN + COIN * 1 * base_fee)}})
221215

222216
# Priority disappears when prioritisetransaction is called with an inverse value...
223217
self.nodes[0].prioritisetransaction(txid=txids[0][0], fee_delta=int(-3*base_fee*COIN))
@@ -264,11 +258,17 @@ def run_test(self):
264258
mempool = self.nodes[0].getrawmempool()
265259
self.log.info("Assert that de-prioritised transaction is still in mempool")
266260
assert high_fee_tx in mempool
267-
assert_equal(self.nodes[0].getprioritisedtransactions()[high_fee_tx], { "fee_delta" : -2*base_fee*COIN, "in_mempool" : True})
261+
assert_equal(self.nodes[0].getprioritisedtransactions()[high_fee_tx], { "fee_delta" : -2*base_fee*COIN, "in_mempool" : True, "modified_fee": int(-2*base_fee*COIN + COIN * 3 * base_fee)})
268262
for x in txids[2]:
269263
if (x != high_fee_tx):
270264
assert x not in mempool
271265

266+
267+
self.log.info("Assert that 0 delta is never added to mapDeltas")
268+
tx_id_zero_del = self.wallet.create_self_transfer()['txid']
269+
self.nodes[0].prioritisetransaction(txid=tx_id_zero_del, fee_delta=0)
270+
assert tx_id_zero_del not in self.nodes[0].getprioritisedtransactions()
271+
272272
# Create a free transaction. Should be rejected.
273273
tx_res = self.wallet.create_self_transfer(fee_rate=0)
274274
tx_hex = tx_res['hex']
@@ -287,7 +287,7 @@ def run_test(self):
287287
self.log.info("Assert that prioritised free transaction is accepted to mempool")
288288
assert_equal(self.nodes[0].sendrawtransaction(tx_hex), tx_id)
289289
assert tx_id in self.nodes[0].getrawmempool()
290-
assert_equal(self.nodes[0].getprioritisedtransactions()[tx_id], { "fee_delta" : self.relayfee*COIN, "in_mempool" : True})
290+
assert_equal(self.nodes[0].getprioritisedtransactions()[tx_id], { "fee_delta" : self.relayfee*COIN, "in_mempool" : True, "modified_fee": int(self.relayfee*COIN + COIN * tx_res["fee"])})
291291

292292
# Test that calling prioritisetransaction is sufficient to trigger
293293
# getblocktemplate to (eventually) return a new block.

0 commit comments

Comments
 (0)