Skip to content
Bitcoin Roots

v29.4-roots.2 · Commit 3: [PATCH 03/21] policy: restore conservative relay and network controls

test/functional/mempool_truc.py

Before: test/functional/mempool_truc.py · After: test/functional/mempool_truc.py

File metadata
index d095033a847b18572d7a1baf3d2ee1a8d55d25ca..edbc5b45039f5e9cda6fec3424acfdaeac553f1f 100755

Download original patch · Release notes

Diff rows 1–148 of 148. Line numbers refer to the original before/after files.

+ Added− RemovedUnmarked lines are context.

Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.

test/functional/mempool_truc.py CHANGED
@@ -4,6 +4,9 @@
4
  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
  from decimal import Decimal
6
 
 
 
 
7
  from test_framework.test_framework import BitcoinTestFramework
8
  from test_framework.util import (
9
  assert_equal,
@@ -55,7 +58,7 @@ class MempoolTRUC(BitcoinTestFramework):
55
  self.log.info("Test TRUC-specific maximum transaction vsize")
56
  tx_v3_heavy = self.wallet.create_self_transfer(target_vsize=TRUC_MAX_VSIZE + 1, version=3)
57
  assert_greater_than_or_equal(tx_v3_heavy["tx"].get_vsize(), TRUC_MAX_VSIZE)
58
- expected_error_heavy = f"TRUC-violation, version=3 tx {tx_v3_heavy['txid']} (wtxid={tx_v3_heavy['wtxid']}) is too big"
59
  assert_raises_rpc_error(-26, expected_error_heavy, node.sendrawtransaction, tx_v3_heavy["hex"])
60
  self.check_mempool([])
61
 
@@ -75,7 +78,7 @@ class MempoolTRUC(BitcoinTestFramework):
75
  version=3
76
  )
77
  assert_greater_than_or_equal(tx_v3_child_heavy["tx"].get_vsize(), TRUC_CHILD_MAX_VSIZE)
78
- expected_error_child_heavy = f"TRUC-violation, version=3 child tx {tx_v3_child_heavy['txid']} (wtxid={tx_v3_child_heavy['wtxid']}) is too big"
79
  assert_raises_rpc_error(-26, expected_error_child_heavy, node.sendrawtransaction, tx_v3_child_heavy["hex"])
80
  self.check_mempool([tx_v3_parent_normal["txid"]])
81
  # tx has no descendants
@@ -113,6 +116,7 @@ class MempoolTRUC(BitcoinTestFramework):
113
  from_node=node,
114
  fee_rate=DEFAULT_FEE,
115
  utxo_to_spend=utxo_v3_bip125,
 
116
  version=3
117
  )
118
  self.check_mempool([tx_v3_bip125["txid"]])
@@ -155,11 +159,10 @@ class MempoolTRUC(BitcoinTestFramework):
155
  utxo_to_spend=tx_v3_parent["new_utxo"],
156
  version=2
157
  )
158
- expected_error_v2_v3 = f"TRUC-violation, non-version=3 tx {tx_v3_child_rbf_v2['txid']} (wtxid={tx_v3_child_rbf_v2['wtxid']}) cannot spend from version=3 tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']})"
159
  assert_raises_rpc_error(-26, expected_error_v2_v3, node.sendrawtransaction, tx_v3_child_rbf_v2["hex"])
160
  self.check_mempool([tx_v3_bip125_rbf_v2["txid"], tx_v3_parent["txid"], tx_v3_child["txid"]])
161
 
162
-
163
  @cleanup(extra_args=["-datacarriersize=40000"])
164
  def test_truc_reorg(self):
165
  node = self.nodes[0]
@@ -276,20 +279,20 @@ class MempoolTRUC(BitcoinTestFramework):
276
 
277
  self.check_mempool([])
278
  result = node.submitpackage([tx_v3_parent_normal["hex"], tx_v3_parent_2_normal["hex"], tx_v3_child_multiparent["hex"]])
279
- assert_equal(result['package_msg'], f"TRUC-violation, tx {tx_v3_child_multiparent['txid']} (wtxid={tx_v3_child_multiparent['wtxid']}) would have too many ancestors")
280
  self.check_mempool([])
281
 
282
  self.check_mempool([])
283
  result = node.submitpackage([tx_v3_parent_normal["hex"], tx_v3_child_heavy["hex"]])
284
  # tx_v3_child_heavy is heavy based on vsize, not sigops.
285
- assert_equal(result['package_msg'], f"TRUC-violation, version=3 child tx {tx_v3_child_heavy['txid']} (wtxid={tx_v3_child_heavy['wtxid']}) is too big: {tx_v3_child_heavy['tx'].get_vsize()} > 1000 virtual bytes")
286
  self.check_mempool([])
287
 
288
  tx_v3_parent = self.wallet.create_self_transfer(version=3)
289
  tx_v3_child = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxo"], version=3)
290
  tx_v3_grandchild = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_child["new_utxo"], version=3)
291
  result = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child["hex"], tx_v3_grandchild["hex"]])
292
- assert all([txresult["package-error"] == f"TRUC-violation, tx {tx_v3_grandchild['txid']} (wtxid={tx_v3_grandchild['wtxid']}) would have too many ancestors" for txresult in result])
293
 
294
  @cleanup(extra_args=None)
295
  def test_truc_ancestors_package_and_mempool(self):
@@ -318,7 +321,7 @@ class MempoolTRUC(BitcoinTestFramework):
318
 
319
  # submitpackage(B, C) should fail
320
  result = node.submitpackage([tx_0fee_parent["hex"], tx_child_violator["hex"]])
321
- assert_equal(result['package_msg'], f"TRUC-violation, tx {tx_child_violator['txid']} (wtxid={tx_child_violator['wtxid']}) would have too many ancestors")
322
  self.check_mempool([tx_in_mempool["txid"]])
323
 
324
  @cleanup(extra_args=None)
@@ -371,17 +374,17 @@ class MempoolTRUC(BitcoinTestFramework):
371
  # Fails with another non-related transaction via testmempoolaccept
372
  tx_unrelated = self.wallet.create_self_transfer(version=3)
373
  result_test_unrelated = node.testmempoolaccept([tx_sibling_1["hex"], tx_unrelated["hex"]])
374
- assert_equal(result_test_unrelated[0]["reject-reason"], "TRUC-violation")
375
 
376
  # Fails in a package via testmempoolaccept
377
  result_test_1p1c = node.testmempoolaccept([tx_sibling_1["hex"], tx_has_mempool_uncle["hex"]])
378
- assert_equal(result_test_1p1c[0]["reject-reason"], "TRUC-violation")
379
 
380
  # Allowed when tx is submitted in a package and evaluated individually.
381
  # Note that the child failed since it would be the 3rd generation.
382
  result_package_indiv = node.submitpackage([tx_sibling_1["hex"], tx_has_mempool_uncle["hex"]])
383
  self.check_mempool([tx_mempool_parent["txid"], tx_sibling_1["txid"]])
384
- expected_error_gen3 = f"TRUC-violation, tx {tx_has_mempool_uncle['txid']} (wtxid={tx_has_mempool_uncle['wtxid']}) would have too many ancestors"
385
 
386
  assert_equal(result_package_indiv["tx-results"][tx_has_mempool_uncle['wtxid']]['error'], expected_error_gen3)
387
 
@@ -392,7 +395,7 @@ class MempoolTRUC(BitcoinTestFramework):
392
  # Child cannot pay for sibling eviction for parent, as it violates TRUC topology limits
393
  result_package_cpfp = node.submitpackage([tx_sibling_3["hex"], tx_bumps_parent_with_sibling["hex"]])
394
  self.check_mempool([tx_mempool_parent["txid"], tx_sibling_2["txid"]])
395
- expected_error_cpfp = f"TRUC-violation, tx {tx_mempool_parent['txid']} (wtxid={tx_mempool_parent['wtxid']}) would exceed descendant count limit"
396
 
397
  assert_equal(result_package_cpfp["tx-results"][tx_sibling_3['wtxid']]['error'], expected_error_cpfp)
398
 
@@ -413,7 +416,7 @@ class MempoolTRUC(BitcoinTestFramework):
413
  )
414
  self.check_mempool([])
415
  result = node.submitpackage([tx_v3_parent["hex"], tx_v2_child["hex"]])
416
- assert_equal(result['package_msg'], f"TRUC-violation, non-version=3 tx {tx_v2_child['txid']} (wtxid={tx_v2_child['wtxid']}) cannot spend from version=3 tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']})")
417
  self.check_mempool([])
418
 
419
  @cleanup(extra_args=None)
@@ -434,11 +437,11 @@ class MempoolTRUC(BitcoinTestFramework):
434
  assert all([result["allowed"] for result in test_accept_v2_and_v3])
435
 
436
  test_accept_v3_from_v2 = node.testmempoolaccept([tx_v2["hex"], tx_v3_from_v2["hex"]])
437
- expected_error_v3_from_v2 = f"TRUC-violation, version=3 tx {tx_v3_from_v2['txid']} (wtxid={tx_v3_from_v2['wtxid']}) cannot spend from non-version=3 tx {tx_v2['txid']} (wtxid={tx_v2['wtxid']})"
438
  assert all([result["package-error"] == expected_error_v3_from_v2 for result in test_accept_v3_from_v2])
439
 
440
  test_accept_v2_from_v3 = node.testmempoolaccept([tx_v3["hex"], tx_v2_from_v3["hex"]])
441
- expected_error_v2_from_v3 = f"TRUC-violation, non-version=3 tx {tx_v2_from_v3['txid']} (wtxid={tx_v2_from_v3['wtxid']}) cannot spend from version=3 tx {tx_v3['txid']} (wtxid={tx_v3['wtxid']})"
442
  assert all([result["package-error"] == expected_error_v2_from_v3 for result in test_accept_v2_from_v3])
443
 
444
  test_accept_pairs = node.testmempoolaccept([tx_v2["hex"], tx_v3["hex"], tx_v2_from_v2["hex"], tx_v3_from_v3["hex"]])
@@ -450,7 +453,7 @@ class MempoolTRUC(BitcoinTestFramework):
450
  tx_v3_child_1 = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxos"][0], version=3)
451
  tx_v3_child_2 = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxos"][1], version=3)
452
  test_accept_2children = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child_1["hex"], tx_v3_child_2["hex"]])
453
- expected_error_2children = f"TRUC-violation, tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']}) would exceed descendant count limit"
454
  assert all([result["package-error"] == expected_error_2children for result in test_accept_2children])
455
 
456
  # Extra TRUC transaction does not get incorrectly marked as extra descendant
@@ -459,7 +462,7 @@ class MempoolTRUC(BitcoinTestFramework):
459
 
460
  # Extra TRUC transaction does not make us ignore the extra descendant
461
  test_accept_2children_with_exra = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child_1["hex"], tx_v3_child_2["hex"], tx_v3_independent["hex"]])
462
- expected_error_extra = f"TRUC-violation, tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']}) would exceed descendant count limit"
463
  assert all([result["package-error"] == expected_error_extra for result in test_accept_2children_with_exra])
464
  # Same result if the parent is already in mempool
465
  node.sendrawtransaction(tx_v3_parent["hex"])
@@ -596,7 +599,7 @@ class MempoolTRUC(BitcoinTestFramework):
596
  utxo_to_spend=tx_with_multi_children["new_utxos"][2],
597
  fee_rate=DEFAULT_FEE*50
598
  )
599
- expected_error_2siblings = f"TRUC-violation, tx {tx_with_multi_children['txid']} (wtxid={tx_with_multi_children['wtxid']}) would exceed descendant count limit"
600
  assert_raises_rpc_error(-26, expected_error_2siblings, node.sendrawtransaction, tx_with_sibling3["hex"])
601
 
602
  # However, an RBF (with conflicting inputs) is possible even if the resulting cluster size exceeds 2
 
4
  # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
  from decimal import Decimal
6
 
7
+ from test_framework.messages import (
8
+ MAX_BIP125_RBF_SEQUENCE,
9
+ )
10
  from test_framework.test_framework import BitcoinTestFramework
11
  from test_framework.util import (
12
  assert_equal,
 
58
  self.log.info("Test TRUC-specific maximum transaction vsize")
59
  tx_v3_heavy = self.wallet.create_self_transfer(target_vsize=TRUC_MAX_VSIZE + 1, version=3)
60
  assert_greater_than_or_equal(tx_v3_heavy["tx"].get_vsize(), TRUC_MAX_VSIZE)
61
+ expected_error_heavy = f"truc-vsize-toobig, version=3 tx {tx_v3_heavy['txid']} (wtxid={tx_v3_heavy['wtxid']}) is too big"
62
  assert_raises_rpc_error(-26, expected_error_heavy, node.sendrawtransaction, tx_v3_heavy["hex"])
63
  self.check_mempool([])
64
 
 
78
  version=3
79
  )
80
  assert_greater_than_or_equal(tx_v3_child_heavy["tx"].get_vsize(), TRUC_CHILD_MAX_VSIZE)
81
+ expected_error_child_heavy = f"truc-child-toobig, version=3 child tx {tx_v3_child_heavy['txid']} (wtxid={tx_v3_child_heavy['wtxid']}) is too big"
82
  assert_raises_rpc_error(-26, expected_error_child_heavy, node.sendrawtransaction, tx_v3_child_heavy["hex"])
83
  self.check_mempool([tx_v3_parent_normal["txid"]])
84
  # tx has no descendants
 
116
  from_node=node,
117
  fee_rate=DEFAULT_FEE,
118
  utxo_to_spend=utxo_v3_bip125,
119
+ sequence=MAX_BIP125_RBF_SEQUENCE,
120
  version=3
121
  )
122
  self.check_mempool([tx_v3_bip125["txid"]])
 
159
  utxo_to_spend=tx_v3_parent["new_utxo"],
160
  version=2
161
  )
162
+ expected_error_v2_v3 = f"truc-spent-by-nontruc, non-version=3 tx {tx_v3_child_rbf_v2['txid']} (wtxid={tx_v3_child_rbf_v2['wtxid']}) cannot spend from version=3 tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']})"
163
  assert_raises_rpc_error(-26, expected_error_v2_v3, node.sendrawtransaction, tx_v3_child_rbf_v2["hex"])
164
  self.check_mempool([tx_v3_bip125_rbf_v2["txid"], tx_v3_parent["txid"], tx_v3_child["txid"]])
165
 
 
166
  @cleanup(extra_args=["-datacarriersize=40000"])
167
  def test_truc_reorg(self):
168
  node = self.nodes[0]
 
279
 
280
  self.check_mempool([])
281
  result = node.submitpackage([tx_v3_parent_normal["hex"], tx_v3_parent_2_normal["hex"], tx_v3_child_multiparent["hex"]])
282
+ assert_equal(result['package_msg'], f"truc-ancestors-toomany, tx {tx_v3_child_multiparent['txid']} (wtxid={tx_v3_child_multiparent['wtxid']}) would have too many ancestors")
283
  self.check_mempool([])
284
 
285
  self.check_mempool([])
286
  result = node.submitpackage([tx_v3_parent_normal["hex"], tx_v3_child_heavy["hex"]])
287
  # tx_v3_child_heavy is heavy based on vsize, not sigops.
288
+ assert_equal(result['package_msg'], f"truc-child-toobig, version=3 child tx {tx_v3_child_heavy['txid']} (wtxid={tx_v3_child_heavy['wtxid']}) is too big: {tx_v3_child_heavy['tx'].get_vsize()} > 1000 virtual bytes")
289
  self.check_mempool([])
290
 
291
  tx_v3_parent = self.wallet.create_self_transfer(version=3)
292
  tx_v3_child = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxo"], version=3)
293
  tx_v3_grandchild = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_child["new_utxo"], version=3)
294
  result = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child["hex"], tx_v3_grandchild["hex"]])
295
+ assert all([txresult["package-error"] == f"truc-parent-and-child-both, tx {tx_v3_grandchild['txid']} (wtxid={tx_v3_grandchild['wtxid']}) would have too many ancestors" for txresult in result])
296
 
297
  @cleanup(extra_args=None)
298
  def test_truc_ancestors_package_and_mempool(self):
 
321
 
322
  # submitpackage(B, C) should fail
323
  result = node.submitpackage([tx_0fee_parent["hex"], tx_child_violator["hex"]])
324
+ assert_equal(result['package_msg'], f"truc-parent-and-child-both, tx {tx_child_violator['txid']} (wtxid={tx_child_violator['wtxid']}) would have too many ancestors")
325
  self.check_mempool([tx_in_mempool["txid"]])
326
 
327
  @cleanup(extra_args=None)
 
374
  # Fails with another non-related transaction via testmempoolaccept
375
  tx_unrelated = self.wallet.create_self_transfer(version=3)
376
  result_test_unrelated = node.testmempoolaccept([tx_sibling_1["hex"], tx_unrelated["hex"]])
377
+ assert_equal(result_test_unrelated[0]["reject-reason"], "truc-descendants-toomany")
378
 
379
  # Fails in a package via testmempoolaccept
380
  result_test_1p1c = node.testmempoolaccept([tx_sibling_1["hex"], tx_has_mempool_uncle["hex"]])
381
+ assert_equal(result_test_1p1c[0]["reject-reason"], "truc-descendants-toomany")
382
 
383
  # Allowed when tx is submitted in a package and evaluated individually.
384
  # Note that the child failed since it would be the 3rd generation.
385
  result_package_indiv = node.submitpackage([tx_sibling_1["hex"], tx_has_mempool_uncle["hex"]])
386
  self.check_mempool([tx_mempool_parent["txid"], tx_sibling_1["txid"]])
387
+ expected_error_gen3 = f"truc-ancestors-toomany, tx {tx_has_mempool_uncle['txid']} (wtxid={tx_has_mempool_uncle['wtxid']}) would have too many ancestors"
388
 
389
  assert_equal(result_package_indiv["tx-results"][tx_has_mempool_uncle['wtxid']]['error'], expected_error_gen3)
390
 
 
395
  # Child cannot pay for sibling eviction for parent, as it violates TRUC topology limits
396
  result_package_cpfp = node.submitpackage([tx_sibling_3["hex"], tx_bumps_parent_with_sibling["hex"]])
397
  self.check_mempool([tx_mempool_parent["txid"], tx_sibling_2["txid"]])
398
+ expected_error_cpfp = f"truc-descendants-toomany, tx {tx_mempool_parent['txid']} (wtxid={tx_mempool_parent['wtxid']}) would exceed descendant count limit"
399
 
400
  assert_equal(result_package_cpfp["tx-results"][tx_sibling_3['wtxid']]['error'], expected_error_cpfp)
401
 
 
416
  )
417
  self.check_mempool([])
418
  result = node.submitpackage([tx_v3_parent["hex"], tx_v2_child["hex"]])
419
+ assert_equal(result['package_msg'], f"truc-spent-by-nontruc, non-version=3 tx {tx_v2_child['txid']} (wtxid={tx_v2_child['wtxid']}) cannot spend from version=3 tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']})")
420
  self.check_mempool([])
421
 
422
  @cleanup(extra_args=None)
 
437
  assert all([result["allowed"] for result in test_accept_v2_and_v3])
438
 
439
  test_accept_v3_from_v2 = node.testmempoolaccept([tx_v2["hex"], tx_v3_from_v2["hex"]])
440
+ expected_error_v3_from_v2 = f"truc-spends-nontruc, version=3 tx {tx_v3_from_v2['txid']} (wtxid={tx_v3_from_v2['wtxid']}) cannot spend from non-version=3 tx {tx_v2['txid']} (wtxid={tx_v2['wtxid']})"
441
  assert all([result["package-error"] == expected_error_v3_from_v2 for result in test_accept_v3_from_v2])
442
 
443
  test_accept_v2_from_v3 = node.testmempoolaccept([tx_v3["hex"], tx_v2_from_v3["hex"]])
444
+ expected_error_v2_from_v3 = f"truc-spent-by-nontruc, non-version=3 tx {tx_v2_from_v3['txid']} (wtxid={tx_v2_from_v3['wtxid']}) cannot spend from version=3 tx {tx_v3['txid']} (wtxid={tx_v3['wtxid']})"
445
  assert all([result["package-error"] == expected_error_v2_from_v3 for result in test_accept_v2_from_v3])
446
 
447
  test_accept_pairs = node.testmempoolaccept([tx_v2["hex"], tx_v3["hex"], tx_v2_from_v2["hex"], tx_v3_from_v3["hex"]])
 
453
  tx_v3_child_1 = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxos"][0], version=3)
454
  tx_v3_child_2 = self.wallet.create_self_transfer(utxo_to_spend=tx_v3_parent["new_utxos"][1], version=3)
455
  test_accept_2children = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child_1["hex"], tx_v3_child_2["hex"]])
456
+ expected_error_2children = f"truc-sibling-known, tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']}) would exceed descendant count limit"
457
  assert all([result["package-error"] == expected_error_2children for result in test_accept_2children])
458
 
459
  # Extra TRUC transaction does not get incorrectly marked as extra descendant
 
462
 
463
  # Extra TRUC transaction does not make us ignore the extra descendant
464
  test_accept_2children_with_exra = node.testmempoolaccept([tx_v3_parent["hex"], tx_v3_child_1["hex"], tx_v3_child_2["hex"], tx_v3_independent["hex"]])
465
+ expected_error_extra = f"truc-sibling-known, tx {tx_v3_parent['txid']} (wtxid={tx_v3_parent['wtxid']}) would exceed descendant count limit"
466
  assert all([result["package-error"] == expected_error_extra for result in test_accept_2children_with_exra])
467
  # Same result if the parent is already in mempool
468
  node.sendrawtransaction(tx_v3_parent["hex"])
 
599
  utxo_to_spend=tx_with_multi_children["new_utxos"][2],
600
  fee_rate=DEFAULT_FEE*50
601
  )
602
+ expected_error_2siblings = f"truc-descendants-toomany, tx {tx_with_multi_children['txid']} (wtxid={tx_with_multi_children['wtxid']}) would exceed descendant count limit"
603
  assert_raises_rpc_error(-26, expected_error_2siblings, node.sendrawtransaction, tx_with_sibling3["hex"])
604
 
605
  # However, an RBF (with conflicting inputs) is possible even if the resulting cluster size exceeds 2