Skip to content

Commit 1dda189

Browse files
committed
Merge bitcoin/bitcoin#31037: test: enhance p2p_orphan_handling
9de9c85 test: enhance p2p_orphan_handling (tdb3) 33af14b test: reduce assert_debug_log reliance (tdb3) Pull request description: Previously, `p2p_orphan_handling` relied on checking the debug log for orphanage changes. This updates the tests to reduce debug log checking and add checks using `tx_in_orphanage()` and `getorphantxs` introduced in #30793. ACKs for top commit: glozow: light code review ACK 9de9c85 rkrux: tACK 9de9c85 danielabrozzoni: ACK 9de9c85 Tree-SHA512: b53bf0d66d727c79eab972b736a074bd04ca652afd89d2a50830247f42734c61c4c2fa883fde179560e39469c81d0e7be478e1faa0992d3688d5e04d75c067d7
2 parents 2b33322 + 9de9c85 commit 1dda189

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

test/functional/p2p_orphan_handling.py

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ def test_orphan_rejected_parents_exceptions(self):
210210

211211
# Relay the child. It should not be accepted because it has missing inputs.
212212
# Its parent should not be requested because its hash (txid == wtxid) has been added to the rejection filter.
213-
with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(child_nonsegwit["txid"])]):
214-
self.relay_transaction(peer2, child_nonsegwit["tx"])
213+
self.relay_transaction(peer2, child_nonsegwit["tx"])
215214
assert child_nonsegwit["txid"] not in node.getrawmempool()
215+
assert not tx_in_orphanage(node, child_nonsegwit["tx"])
216216

217217
# No parents are requested.
218218
self.nodes[0].bumpmocktime(GETDATA_TX_INTERVAL)
@@ -231,6 +231,7 @@ def test_orphan_rejected_parents_exceptions(self):
231231
# Relay the child. It should not be accepted because it has missing inputs.
232232
self.relay_transaction(peer2, child_low_fee["tx"])
233233
assert child_low_fee["txid"] not in node.getrawmempool()
234+
assert tx_in_orphanage(node, child_low_fee["tx"])
234235

235236
# The parent should be requested because even though the txid commits to the fee, it doesn't
236237
# commit to the feerate. Delayed because it's by txid and this is not a preferred relay peer.
@@ -250,6 +251,7 @@ def test_orphan_rejected_parents_exceptions(self):
250251
# Relay the child. It should not be accepted because it has missing inputs.
251252
self.relay_transaction(peer2, child_invalid_witness["tx"])
252253
assert child_invalid_witness["txid"] not in node.getrawmempool()
254+
assert tx_in_orphanage(node, child_invalid_witness["tx"])
253255

254256
# The parent should be requested since the unstripped wtxid would differ. Delayed because
255257
# it's by txid and this is not a preferred relay peer.
@@ -298,6 +300,7 @@ def test_orphan_multiple_parents(self):
298300
self.relay_transaction(peer, orphan["tx"])
299301
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
300302
peer.sync_with_ping()
303+
assert tx_in_orphanage(node, orphan["tx"])
301304
assert_equal(len(peer.last_message["getdata"].inv), 2)
302305
peer.wait_for_parent_requests([int(txid_conf_old, 16), int(missing_tx["txid"], 16)])
303306

@@ -347,6 +350,7 @@ def test_orphans_overlapping_parents(self):
347350
# Relay orphan child_A
348351
self.relay_transaction(peer_orphans, child_A["tx"])
349352
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
353+
assert tx_in_orphanage(node, child_A["tx"])
350354
# There are 3 missing parents. missing_parent_A and missing_parent_AB should be requested.
351355
# But inflight_parent_AB should not, because there is already an in-flight request for it.
352356
peer_orphans.wait_for_parent_requests([int(missing_parent_A["txid"], 16), int(missing_parent_AB["txid"], 16)])
@@ -355,6 +359,7 @@ def test_orphans_overlapping_parents(self):
355359
# Relay orphan child_B
356360
self.relay_transaction(peer_orphans, child_B["tx"])
357361
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
362+
assert tx_in_orphanage(node, child_B["tx"])
358363
# Only missing_parent_B should be requested. Not inflight_parent_AB or missing_parent_AB
359364
# because they are already being requested from peer_txrequest and peer_orphans respectively.
360365
peer_orphans.wait_for_parent_requests([int(missing_parent_B["txid"], 16)])
@@ -374,12 +379,14 @@ def test_orphan_of_orphan(self):
374379
# The node should put missing_parent_orphan into the orphanage and request missing_grandparent
375380
self.relay_transaction(peer, missing_parent_orphan["tx"])
376381
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
382+
assert tx_in_orphanage(node, missing_parent_orphan["tx"])
377383
peer.wait_for_parent_requests([int(missing_grandparent["txid"], 16)])
378384

379385
# The node should put the orphan into the orphanage and request missing_parent, skipping
380386
# missing_parent_orphan because it already has it in the orphanage.
381387
self.relay_transaction(peer, orphan["tx"])
382388
self.nodes[0].bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
389+
assert tx_in_orphanage(node, orphan["tx"])
383390
peer.wait_for_parent_requests([int(missing_parent["txid"], 16)])
384391

385392
@cleanup
@@ -399,18 +406,19 @@ def test_orphan_inherit_rejection(self):
399406

400407
# Relay the parent. It should be rejected because it pays 0 fees.
401408
self.relay_transaction(peer1, parent_low_fee_nonsegwit["tx"])
409+
assert parent_low_fee_nonsegwit["txid"] not in node.getrawmempool()
402410

403411
# Relay the child. It should be rejected for having missing parents, and this rejection is
404412
# cached by txid and wtxid.
405-
with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(child["txid"])]):
406-
self.relay_transaction(peer1, child["tx"])
413+
self.relay_transaction(peer1, child["tx"])
407414
assert_equal(0, len(node.getrawmempool()))
415+
assert not tx_in_orphanage(node, child["tx"])
408416
peer1.assert_never_requested(parent_low_fee_nonsegwit["txid"])
409417

410418
# Grandchild should also not be kept in orphanage because its parent has been rejected.
411-
with node.assert_debug_log(['not keeping orphan with rejected parents {}'.format(grandchild["txid"])]):
412-
self.relay_transaction(peer2, grandchild["tx"])
419+
self.relay_transaction(peer2, grandchild["tx"])
413420
assert_equal(0, len(node.getrawmempool()))
421+
assert not tx_in_orphanage(node, grandchild["tx"])
414422
peer2.assert_never_requested(child["txid"])
415423
peer2.assert_never_requested(child["tx"].getwtxid())
416424

@@ -438,6 +446,7 @@ def test_same_txid_orphan(self):
438446

439447
# 1. Fake orphan is received first. It is missing an input.
440448
bad_peer.send_and_ping(msg_tx(tx_orphan_bad_wit))
449+
assert tx_in_orphanage(node, tx_orphan_bad_wit)
441450

442451
# 2. Node requests the missing parent by txid.
443452
parent_txid_int = int(tx_parent["txid"], 16)
@@ -446,8 +455,9 @@ def test_same_txid_orphan(self):
446455

447456
# 3. Honest peer relays the real child, which is also missing parents and should be placed
448457
# in the orphanage.
449-
with node.assert_debug_log(["missingorspent", "stored orphan tx"]):
458+
with node.assert_debug_log(["missingorspent"]):
450459
honest_peer.send_and_ping(msg_tx(tx_child["tx"]))
460+
assert tx_in_orphanage(node, tx_child["tx"])
451461

452462
# Time out the previous request for the parent (node will not request the same transaction
453463
# from multiple nodes at the same time)
@@ -487,6 +497,7 @@ def test_same_txid_orphan_of_orphan(self):
487497

488498
# 1. Fake orphan is received first. It is missing an input.
489499
bad_peer.send_and_ping(msg_tx(tx_orphan_bad_wit))
500+
assert tx_in_orphanage(node, tx_orphan_bad_wit)
490501

491502
# 2. Node requests missing tx_grandparent by txid.
492503
grandparent_txid_int = int(tx_grandparent["txid"], 16)
@@ -496,16 +507,16 @@ def test_same_txid_orphan_of_orphan(self):
496507
# 3. Honest peer relays the grandchild, which is missing a parent. The parent by txid already
497508
# exists in orphanage, but should be re-requested because the node shouldn't assume that the
498509
# witness data is the same. In this case, a same-txid-different-witness transaction exists!
499-
with node.assert_debug_log(["stored orphan tx"]):
500-
honest_peer.send_and_ping(msg_tx(tx_grandchild["tx"]))
510+
honest_peer.send_and_ping(msg_tx(tx_grandchild["tx"]))
511+
assert tx_in_orphanage(node, tx_grandchild["tx"])
501512
middle_txid_int = int(tx_middle["txid"], 16)
502513
node.bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
503514
honest_peer.wait_for_getdata([middle_txid_int])
504515

505516
# 4. Honest peer relays the real child, which is also missing parents and should be placed
506517
# in the orphanage.
507-
with node.assert_debug_log(["stored orphan tx"]):
508-
honest_peer.send_and_ping(msg_tx(tx_middle["tx"]))
518+
honest_peer.send_and_ping(msg_tx(tx_middle["tx"]))
519+
assert tx_in_orphanage(node, tx_middle["tx"])
509520
assert_equal(len(node.getrawmempool()), 0)
510521

511522
# 5. Honest peer sends tx_grandparent
@@ -518,6 +529,7 @@ def test_same_txid_orphan_of_orphan(self):
518529
assert tx_middle["txid"] in node_mempool
519530
assert tx_grandchild["txid"] in node_mempool
520531
assert_equal(node.getmempoolentry(tx_middle["txid"])["wtxid"], tx_middle["wtxid"])
532+
assert_equal(len(node.getorphantxs()), 0)
521533

522534
@cleanup
523535
def test_orphan_txid_inv(self):
@@ -536,6 +548,7 @@ def test_orphan_txid_inv(self):
536548

537549
# 1. Fake orphan is received first. It is missing an input.
538550
bad_peer.send_and_ping(msg_tx(tx_orphan_bad_wit))
551+
assert tx_in_orphanage(node, tx_orphan_bad_wit)
539552

540553
# 2. Node requests the missing parent by txid.
541554
parent_txid_int = int(tx_parent["txid"], 16)
@@ -550,8 +563,8 @@ def test_orphan_txid_inv(self):
550563
# 4. The child is requested. Honest peer sends it.
551564
node.bumpmocktime(TXREQUEST_TIME_SKIP)
552565
honest_peer.wait_for_getdata([child_txid_int])
553-
with node.assert_debug_log(["stored orphan tx"]):
554-
honest_peer.send_and_ping(msg_tx(tx_child["tx"]))
566+
honest_peer.send_and_ping(msg_tx(tx_child["tx"]))
567+
assert tx_in_orphanage(node, tx_child["tx"])
555568

556569
# 5. After first parent request times out, the node sends another one for the missing parent
557570
# of the real orphan child.
@@ -568,6 +581,7 @@ def test_orphan_txid_inv(self):
568581
assert tx_parent["txid"] in node_mempool
569582
assert tx_child["txid"] in node_mempool
570583
assert_equal(node.getmempoolentry(tx_child["txid"])["wtxid"], tx_child["wtxid"])
584+
assert_equal(len(node.getorphantxs()), 0)
571585

572586
@cleanup
573587
def test_max_orphan_amount(self):

0 commit comments

Comments
 (0)