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