mempool_ephemeral_dust.py raw
1 #!/usr/bin/env python3
2 # Copyright (c) 2024-present The Limenka developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6 from decimal import Decimal
7
8 from test_framework.messages import (
9 COIN,
10 CTxOut,
11 )
12 from test_framework.test_framework import LimenkaTestFramework
13 from test_framework.mempool_util import assert_mempool_contents
14 from test_framework.util import (
15 assert_equal,
16 assert_greater_than,
17 assert_raises_rpc_error,
18 )
19 from test_framework.wallet import (
20 MiniWallet,
21 )
22
23 class EphemeralDustTest(LimenkaTestFramework):
24 def set_test_params(self):
25 # Mempools should match via 1P1C p2p relay
26 self.num_nodes = 2
27
28 # Don't test trickling logic
29 self.noban_tx_relay = True
30
31 def add_output_to_create_multi_result(self, result, output_value=0):
32 """ Add output without changing absolute tx fee
33 """
34 assert len(result["tx"].vout) > 0
35 assert result["tx"].vout[0].nValue >= output_value
36 result["tx"].vout.append(CTxOut(output_value, result["tx"].vout[0].scriptPubKey))
37 # Take value from first output
38 result["tx"].vout[0].nValue -= output_value
39 result["new_utxos"][0]["value"] = Decimal(result["tx"].vout[0].nValue) / COIN
40 new_txid = result["tx"].rehash()
41 result["txid"] = new_txid
42 result["wtxid"] = result["tx"].getwtxid()
43 result["hex"] = result["tx"].serialize().hex()
44 for new_utxo in result["new_utxos"]:
45 new_utxo["txid"] = new_txid
46 new_utxo["wtxid"] = result["tx"].getwtxid()
47
48 result["new_utxos"].append({"txid": new_txid, "vout": len(result["tx"].vout) - 1, "value": Decimal(output_value) / COIN, "height": 0, "coinbase": False, "confirmations": 0})
49
50 def create_ephemeral_dust_package(self, *, tx_version, dust_tx_fee=0, dust_value=0, num_dust_outputs=1, extra_sponsors=None):
51 """Creates a 1P1C package containing ephemeral dust. By default, the parent transaction
52 is zero-fee and creates a single zero-value dust output, and all of its outputs are
53 spent by the child."""
54 dusty_tx = self.wallet.create_self_transfer_multi(fee_per_output=dust_tx_fee, version=tx_version)
55 for _ in range(num_dust_outputs):
56 self.add_output_to_create_multi_result(dusty_tx, dust_value)
57
58 extra_sponsors = extra_sponsors or []
59 sweep_tx = self.wallet.create_self_transfer_multi(
60 utxos_to_spend=dusty_tx["new_utxos"] + extra_sponsors,
61 version=tx_version,
62 )
63
64 return dusty_tx, sweep_tx
65
66 def run_test(self):
67
68 node = self.nodes[0]
69 self.wallet = MiniWallet(node)
70
71 self.test_normal_dust()
72 self.test_sponsor_cycle()
73 self.test_node_restart()
74 self.test_fee_having_parent()
75 self.test_multidust()
76 self.test_nonzero_dust()
77 self.test_non_truc()
78 self.test_unspent_ephemeral()
79 self.test_reorgs()
80 self.test_no_minrelay_fee()
81
82 def test_normal_dust(self):
83 self.log.info("Create 0-value dusty output, show that it works inside truc when spent in package")
84
85 assert_equal(self.nodes[0].getrawmempool(), [])
86 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=3)
87
88 # Test doesn't work because lack of package feerates
89 test_res = self.nodes[0].testmempoolaccept([dusty_tx["hex"], sweep_tx["hex"]])
90 assert not test_res[0]["allowed"]
91 assert_equal(test_res[0]["reject-reason"], "min relay fee not met")
92
93 # And doesn't work on its own
94 assert_raises_rpc_error(-26, "min relay fee not met", self.nodes[0].sendrawtransaction, dusty_tx["hex"])
95
96 # If we add modified fees, it is still not allowed due to dust check
97 self.nodes[0].prioritisetransaction(txid=dusty_tx["txid"], fee_delta=COIN)
98 test_res = self.nodes[0].testmempoolaccept([dusty_tx["hex"]])
99 assert not test_res[0]["allowed"]
100 assert_equal(test_res[0]["reject-reason"], "dust")
101 # Reset priority
102 self.nodes[0].prioritisetransaction(txid=dusty_tx["txid"], fee_delta=-COIN)
103 assert_equal(self.nodes[0].getprioritisedtransactions(), {})
104
105 # Package evaluation succeeds
106 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
107 assert_equal(res["package_msg"], "success")
108 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
109
110 # Entry is denied when non-0-fee, either base or unmodified.
111 # If in-mempool, we're not allowed to prioritise due to detected dust output
112 assert_raises_rpc_error(-8, "Priority is not supported for transactions with dust outputs.", self.nodes[0].prioritisetransaction, dusty_tx["txid"], 0, 1)
113 assert_equal(self.nodes[0].getprioritisedtransactions(), {})
114
115 self.generate(self.nodes[0], 1)
116 assert_equal(self.nodes[0].getrawmempool(), [])
117
118 def test_node_restart(self):
119 self.log.info("Test that an ephemeral package is rejected on restart due to individual evaluation")
120
121 assert_equal(self.nodes[0].getrawmempool(), [])
122 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=3)
123
124 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
125 assert_equal(res["package_msg"], "success")
126 assert_equal(len(self.nodes[0].getrawmempool()), 2)
127 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
128
129 # Node restart; doesn't allow ephemeral transaction back in due to individual submission
130 # resulting in 0-fee. Supporting re-submission of CPFP packages on restart is desired but not
131 # yet implemented.
132 self.restart_node(0)
133 self.restart_node(1)
134 self.connect_nodes(0, 1)
135 assert_mempool_contents(self, self.nodes[0], expected=[])
136
137 def test_fee_having_parent(self):
138 self.log.info("Test that a transaction with ephemeral dust may not have non-0 base fee")
139
140 assert_equal(self.nodes[0].getrawmempool(), [])
141
142 sats_fee = 1
143 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=3, dust_tx_fee=sats_fee)
144 assert_equal(int(COIN * dusty_tx["fee"]), sats_fee) # has fees
145 assert_greater_than(dusty_tx["tx"].vout[0].nValue, 330) # main output is not dust
146 assert_equal(dusty_tx["tx"].vout[1].nValue, 0) # added one is dust
147
148 # When base fee is non-0, we report dust like usual
149 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
150 assert_equal(res["package_msg"], "transaction failed")
151 assert_equal(res["tx-results"][dusty_tx["wtxid"]]["error"], "dust, tx with dust output must be 0-fee")
152
153 # Priority is ignored: rejected even if modified fee is 0
154 self.nodes[0].prioritisetransaction(txid=dusty_tx["txid"], fee_delta=-sats_fee)
155 self.nodes[1].prioritisetransaction(txid=dusty_tx["txid"], fee_delta=-sats_fee)
156 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
157 assert_equal(res["package_msg"], "transaction failed")
158 assert_equal(res["tx-results"][dusty_tx["wtxid"]]["error"], "dust, tx with dust output must be 0-fee")
159
160 # Will not be accepted if base fee is 0 with modified fee of non-0
161 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=3)
162
163 self.nodes[0].prioritisetransaction(txid=dusty_tx["txid"], fee_delta=1000)
164 self.nodes[1].prioritisetransaction(txid=dusty_tx["txid"], fee_delta=1000)
165
166 # It's rejected submitted alone
167 test_res = self.nodes[0].testmempoolaccept([dusty_tx["hex"]])
168 assert not test_res[0]["allowed"]
169 assert_equal(test_res[0]["reject-reason"], "dust")
170
171 # Or as a package
172 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
173 assert_equal(res["package_msg"], "transaction failed")
174 assert_equal(res["tx-results"][dusty_tx["wtxid"]]["error"], "dust, tx with dust output must be 0-fee")
175
176 assert_mempool_contents(self, self.nodes[0], expected=[])
177
178 def test_multidust(self):
179 self.log.info("Test that a transaction with multiple ephemeral dusts is not allowed")
180
181 assert_mempool_contents(self, self.nodes[0], expected=[])
182 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=3, num_dust_outputs=2)
183
184 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
185 assert_equal(res["package_msg"], "transaction failed")
186 assert_equal(res["tx-results"][dusty_tx["wtxid"]]["error"], "dust")
187 assert_equal(self.nodes[0].getrawmempool(), [])
188
189 def test_nonzero_dust(self):
190 self.log.info("Test that a single output of any satoshi amount is allowed, not checking spending")
191
192 # We aren't checking spending, allow it in with no fee
193 self.restart_node(0, extra_args=["-minrelaytxfee=0"])
194 self.restart_node(1, extra_args=["-minrelaytxfee=0"])
195 self.connect_nodes(0, 1)
196
197 # 330 is dust threshold for taproot outputs
198 for value in [1, 329, 330]:
199 assert_equal(self.nodes[0].getrawmempool(), [])
200 dusty_tx, _ = self.create_ephemeral_dust_package(tx_version=3, dust_value=value)
201 test_res = self.nodes[0].testmempoolaccept([dusty_tx["hex"]])
202 assert test_res[0]["allowed"]
203
204 self.restart_node(0, extra_args=[])
205 self.restart_node(1, extra_args=[])
206 self.connect_nodes(0, 1)
207 assert_mempool_contents(self, self.nodes[0], expected=[])
208
209 # N.B. If individual minrelay requirement is dropped, this test can be dropped
210 def test_non_truc(self):
211 self.log.info("Test that v2 dust-having transaction is rejected even if spent, because of min relay requirement")
212
213 assert_equal(self.nodes[0].getrawmempool(), [])
214 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=2)
215
216 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
217 assert_equal(res["package_msg"], "transaction failed")
218 assert_equal(res["tx-results"][dusty_tx["wtxid"]]["error"], "min relay fee not met, 0 < 15")
219
220 assert_equal(self.nodes[0].getrawmempool(), [])
221
222 def test_unspent_ephemeral(self):
223 self.log.info("Test that spending from a tx with ephemeral outputs is only allowed if dust is spent as well")
224
225 assert_equal(self.nodes[0].getrawmempool(), [])
226 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=3, dust_value=329)
227
228 # Valid sweep we will RBF incorrectly by not spending dust as well
229 self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
230 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
231
232 # Doesn't spend in-mempool dust output from parent
233 unspent_sweep_tx = self.wallet.create_self_transfer_multi(fee_per_output=2000, utxos_to_spend=[dusty_tx["new_utxos"][0]], version=3)
234 assert_greater_than(unspent_sweep_tx["fee"], sweep_tx["fee"])
235 res = self.nodes[0].submitpackage([dusty_tx["hex"], unspent_sweep_tx["hex"]])
236 assert_equal(res["tx-results"][unspent_sweep_tx["wtxid"]]["error"], f"missing-ephemeral-spends, tx {unspent_sweep_tx['txid']} (wtxid={unspent_sweep_tx['wtxid']}) did not spend parent's ephemeral dust")
237 assert_raises_rpc_error(-26, f"missing-ephemeral-spends, tx {unspent_sweep_tx['txid']} (wtxid={unspent_sweep_tx['wtxid']}) did not spend parent's ephemeral dust", self.nodes[0].sendrawtransaction, unspent_sweep_tx["hex"])
238 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
239
240 # Spend works with dust spent
241 sweep_tx_2 = self.wallet.create_self_transfer_multi(fee_per_output=2000, utxos_to_spend=dusty_tx["new_utxos"], version=3)
242 assert sweep_tx["hex"] != sweep_tx_2["hex"]
243 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx_2["hex"]])
244 assert_equal(res["package_msg"], "success")
245
246 # Re-set and test again with nothing from package in mempool this time
247 self.generate(self.nodes[0], 1)
248 assert_equal(self.nodes[0].getrawmempool(), [])
249
250 dusty_tx, _ = self.create_ephemeral_dust_package(tx_version=3, dust_value=329)
251
252 # Spend non-dust only
253 unspent_sweep_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=[dusty_tx["new_utxos"][0]], version=3)
254
255 res = self.nodes[0].submitpackage([dusty_tx["hex"], unspent_sweep_tx["hex"]])
256 assert_equal(res["package_msg"], "unspent-dust")
257
258 assert_equal(self.nodes[0].getrawmempool(), [])
259
260 # Now spend dust only which should work
261 second_coin = self.wallet.get_utxo() # another fee-bringing coin
262 sweep_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=[dusty_tx["new_utxos"][1], second_coin], version=3)
263
264 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
265 assert_equal(res["package_msg"], "success")
266 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
267
268 self.generate(self.nodes[0], 1)
269 assert_mempool_contents(self, self.nodes[0], expected=[])
270
271 def test_sponsor_cycle(self):
272 self.log.info("Test that dust txn is not evicted when it becomes childless, but won't be mined")
273
274 assert_equal(self.nodes[0].getrawmempool(), [])
275 sponsor_coin = self.wallet.get_utxo()
276 # Bring "fee" input that can be double-spend separately
277 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=3, extra_sponsors=[sponsor_coin])
278
279 res = self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
280 assert_equal(res["package_msg"], "success")
281 assert_equal(len(self.nodes[0].getrawmempool()), 2)
282 # sync to make sure unsponsor_tx hits second node's mempool after initial package
283 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
284
285 # Now we RBF away the child using the sponsor input only
286 unsponsor_tx = self.wallet.create_self_transfer_multi(
287 utxos_to_spend=[sponsor_coin],
288 num_outputs=1,
289 fee_per_output=2000,
290 version=3
291 )
292 self.nodes[0].sendrawtransaction(unsponsor_tx["hex"])
293
294 # Parent is now childless and fee-free, so will not be mined
295 entry_info = self.nodes[0].getmempoolentry(dusty_tx["txid"])
296 assert_equal(entry_info["descendantcount"], 1)
297 assert_equal(entry_info["fees"]["descendant"], Decimal(0))
298
299 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], unsponsor_tx["tx"]])
300
301 # Dust tx is not mined
302 self.generate(self.nodes[0], 1)
303 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"]])
304
305 # Create sweep that doesn't spend conflicting sponsor coin
306 sweep_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=dusty_tx["new_utxos"], version=3)
307
308 # Can resweep
309 self.nodes[0].sendrawtransaction(sweep_tx["hex"])
310 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
311
312 self.generate(self.nodes[0], 1)
313 assert_mempool_contents(self, self.nodes[0], expected=[])
314
315 def test_reorgs(self):
316 self.log.info("Test that reorgs breaking the truc topology doesn't cause issues")
317
318 assert_equal(self.nodes[0].getrawmempool(), [])
319
320 # Many shallow re-orgs confuse block gossiping making test less reliable otherwise
321 self.disconnect_nodes(0, 1)
322
323 # Get dusty tx mined, then check that it makes it back into mempool on reorg
324 # due to bypass_limits allowing 0-fee individually
325 dusty_tx, _ = self.create_ephemeral_dust_package(tx_version=3)
326 assert_raises_rpc_error(-26, "min relay fee not met", self.nodes[0].sendrawtransaction, dusty_tx["hex"])
327
328 block_res = self.generateblock(self.nodes[0], self.wallet.get_address(), [dusty_tx["hex"]], sync_fun=self.no_op)
329 self.nodes[0].invalidateblock(block_res["hash"])
330 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"]], sync=False)
331
332 # Create a sweep that has dust of its own and leaves dusty_tx's dust unspent
333 sweep_tx = self.wallet.create_self_transfer_multi(fee_per_output=0, utxos_to_spend=[dusty_tx["new_utxos"][0]], version=3)
334 self.add_output_to_create_multi_result(sweep_tx)
335 assert_raises_rpc_error(-26, "min relay fee not met", self.nodes[0].sendrawtransaction, sweep_tx["hex"])
336
337 # Mine the sweep then re-org, the sweep will not make it back in due to spend checks
338 block_res = self.generateblock(self.nodes[0], self.wallet.get_address(), [dusty_tx["hex"], sweep_tx["hex"]], sync_fun=self.no_op)
339 self.nodes[0].invalidateblock(block_res["hash"])
340 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"]], sync=False)
341
342 # Should re-enter if dust is swept
343 sweep_tx_2 = self.wallet.create_self_transfer_multi(fee_per_output=0, utxos_to_spend=dusty_tx["new_utxos"], version=3)
344 self.add_output_to_create_multi_result(sweep_tx_2)
345 assert_raises_rpc_error(-26, "min relay fee not met", self.nodes[0].sendrawtransaction, sweep_tx_2["hex"])
346
347 reconsider_block_res = self.generateblock(self.nodes[0], self.wallet.get_address(), [dusty_tx["hex"], sweep_tx_2["hex"]], sync_fun=self.no_op)
348 self.nodes[0].invalidateblock(reconsider_block_res["hash"])
349 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx_2["tx"]], sync=False)
350
351 # TRUC transactions restriction for ephemeral dust disallows further spends of ancestor chains
352 child_tx = self.wallet.create_self_transfer_multi(utxos_to_spend=sweep_tx_2["new_utxos"], version=3)
353 assert_raises_rpc_error(-26, "truc-ancestors-toomany", self.nodes[0].sendrawtransaction, child_tx["hex"])
354
355 self.nodes[0].reconsiderblock(reconsider_block_res["hash"])
356 assert_equal(self.nodes[0].getrawmempool(), [])
357
358 self.log.info("Test that ephemeral dust tx with fees or multi dust don't enter mempool via reorg")
359 multi_dusty_tx, _ = self.create_ephemeral_dust_package(tx_version=3, num_dust_outputs=2)
360 block_res = self.generateblock(self.nodes[0], self.wallet.get_address(), [multi_dusty_tx["hex"]], sync_fun=self.no_op)
361 self.nodes[0].invalidateblock(block_res["hash"])
362 assert_equal(self.nodes[0].getrawmempool(), [])
363
364 # With fee and one dust
365 dusty_fee_tx, _ = self.create_ephemeral_dust_package(tx_version=3, dust_tx_fee=1)
366 block_res = self.generateblock(self.nodes[0], self.wallet.get_address(), [dusty_fee_tx["hex"]], sync_fun=self.no_op)
367 self.nodes[0].invalidateblock(block_res["hash"])
368 assert_equal(self.nodes[0].getrawmempool(), [])
369
370 # Re-connect and make sure we have same state still
371 self.connect_nodes(0, 1)
372 self.sync_all()
373
374 # N.B. this extra_args can be removed post cluster mempool
375 def test_no_minrelay_fee(self):
376 self.log.info("Test that ephemeral dust works in non-TRUC contexts when there's no minrelay requirement")
377
378 # Note: since minrelay is 0, it is not testing 1P1C relay
379 self.restart_node(0, extra_args=["-minrelaytxfee=0"])
380 self.restart_node(1, extra_args=["-minrelaytxfee=0"])
381 self.connect_nodes(0, 1)
382
383 assert_equal(self.nodes[0].getrawmempool(), [])
384 dusty_tx, sweep_tx = self.create_ephemeral_dust_package(tx_version=2)
385
386 self.nodes[0].submitpackage([dusty_tx["hex"], sweep_tx["hex"]])
387
388 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"], sweep_tx["tx"]])
389
390 # generate coins for next tests
391 self.generate(self.nodes[0], 1)
392 self.wallet.rescan_utxos()
393 assert_equal(self.nodes[0].getrawmempool(), [])
394
395 self.log.info("Test batched ephemeral dust sweep")
396 dusty_txs = []
397 for _ in range(24):
398 dusty_txs.append(self.wallet.create_self_transfer_multi(fee_per_output=0, version=2))
399 self.add_output_to_create_multi_result(dusty_txs[-1])
400
401 all_parent_utxos = [utxo for tx in dusty_txs for utxo in tx["new_utxos"]]
402
403 # Missing one dust spend from a single parent, child rejected
404 insufficient_sweep_tx = self.wallet.create_self_transfer_multi(fee_per_output=25000, utxos_to_spend=all_parent_utxos[:-1], version=2)
405
406 res = self.nodes[0].submitpackage([dusty_tx["hex"] for dusty_tx in dusty_txs] + [insufficient_sweep_tx["hex"]])
407 assert_equal(res['package_msg'], "transaction failed")
408 assert_equal(res['tx-results'][insufficient_sweep_tx['wtxid']]['error'], f"missing-ephemeral-spends, tx {insufficient_sweep_tx['txid']} (wtxid={insufficient_sweep_tx['wtxid']}) did not spend parent's ephemeral dust")
409 # Everything got in except for insufficient spend
410 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"] for dusty_tx in dusty_txs])
411
412 # Next put some parents in mempool, but not others, and test unspent dust again with all parents spent
413 B_coin = self.wallet.get_utxo() # coin to cycle out CPFP
414 sweep_all_but_one_tx = self.wallet.create_self_transfer_multi(fee_per_output=20000, utxos_to_spend=all_parent_utxos[:-2] + [B_coin], version=2)
415 res = self.nodes[0].submitpackage([dusty_tx["hex"] for dusty_tx in dusty_txs[:-1]] + [sweep_all_but_one_tx["hex"]])
416 assert_equal(res['package_msg'], "success")
417 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"] for dusty_tx in dusty_txs] + [sweep_all_but_one_tx["tx"]])
418
419 res = self.nodes[0].submitpackage([dusty_tx["hex"] for dusty_tx in dusty_txs] + [insufficient_sweep_tx["hex"]])
420 assert_equal(res['package_msg'], "transaction failed")
421 assert_equal(res['tx-results'][insufficient_sweep_tx["wtxid"]]["error"], f"missing-ephemeral-spends, tx {insufficient_sweep_tx['txid']} (wtxid={insufficient_sweep_tx['wtxid']}) did not spend parent's ephemeral dust")
422 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"] for dusty_tx in dusty_txs] + [sweep_all_but_one_tx["tx"]])
423
424 # Cycle out the partial sweep to avoid triggering package RBF behavior which limits package to no in-mempool ancestors
425 cancel_sweep = self.wallet.create_self_transfer_multi(fee_per_output=21000, utxos_to_spend=[B_coin], version=2)
426 self.nodes[0].sendrawtransaction(cancel_sweep["hex"])
427 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"] for dusty_tx in dusty_txs] + [cancel_sweep["tx"]])
428
429 # Sweeps all dust, where all dusty txs are already in-mempool
430 sweep_tx = self.wallet.create_self_transfer_multi(fee_per_output=25000, utxos_to_spend=all_parent_utxos, version=2)
431
432 # N.B. Since we have multiple parents these are not propagating via 1P1C relay.
433 # minrelay being zero allows them to propagate on their own.
434 res = self.nodes[0].submitpackage([dusty_tx["hex"] for dusty_tx in dusty_txs] + [sweep_tx["hex"]])
435 assert_equal(res['package_msg'], "success")
436 assert_mempool_contents(self, self.nodes[0], expected=[dusty_tx["tx"] for dusty_tx in dusty_txs] + [sweep_tx["tx"], cancel_sweep["tx"]])
437
438 self.generate(self.nodes[0], 1)
439 self.wallet.rescan_utxos()
440 assert_equal(self.nodes[0].getrawmempool(), [])
441
442 # Other topology tests (e.g., grandparents and parents both with dust) require relaxation of submitpackage topology
443
444 self.restart_node(0, extra_args=[])
445 self.restart_node(1, extra_args=[])
446 self.connect_nodes(0, 1)
447
448 assert_equal(self.nodes[0].getrawmempool(), [])
449
450 if __name__ == "__main__":
451 EphemeralDustTest(__file__).main()
452