Skip to content

Commit 70772dd

Browse files
committed
[test] cut the number of transactions involved in 1p1c DoS tests
We just need enough transactions to push us above the orphanage limits and trigger trimming. Reducing the number of transactions cuts the runtime of this test significantly.
1 parent 73e754b commit 70772dd

File tree

1 file changed

+17
-24
lines changed

1 file changed

+17
-24
lines changed

test/functional/p2p_opportunistic_1p1c.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,10 @@ def test_orphanage_dos_large(self):
407407

408408
peer_normal = node.add_p2p_connection(P2PInterface())
409409
peer_doser = node.add_p2p_connection(P2PInterface())
410+
num_individual_dosers = 10
410411

411412
self.log.info("Create very large orphans to be sent by DoSy peers (may take a while)")
412-
large_orphans = [create_large_orphan() for _ in range(100)]
413+
large_orphans = [create_large_orphan() for _ in range(50)]
413414
# Check to make sure these are orphans, within max standard size (to be accepted into the orphanage)
414415
for large_orphan in large_orphans:
415416
assert_greater_than_or_equal(100000, large_orphan.get_vsize())
@@ -419,11 +420,10 @@ def test_orphanage_dos_large(self):
419420
assert not testres[0]["allowed"]
420421
assert_equal(testres[0]["reject-reason"], "missing-inputs")
421422

422-
num_individual_dosers = 30
423423
self.log.info(f"Connect {num_individual_dosers} peers and send a very large orphan from each one")
424424
# This test assumes that unrequested transactions are processed (skipping inv and
425425
# getdata steps because they require going through request delays)
426-
# Connect 20 peers and have each of them send a large orphan.
426+
# Connect 10 peers and have each of them send a large orphan.
427427
for large_orphan in large_orphans[:num_individual_dosers]:
428428
peer_doser_individual = node.add_p2p_connection(P2PInterface())
429429
peer_doser_individual.send_and_ping(msg_tx(large_orphan))
@@ -459,7 +459,7 @@ def test_orphanage_dos_large(self):
459459
peer_normal.wait_for_getdata([parent_txid_int])
460460

461461
self.log.info("Send another round of very large orphans from a DoSy peer")
462-
for large_orphan in large_orphans[30:]:
462+
for large_orphan in large_orphans[num_individual_dosers:]:
463463
peer_doser.send_and_ping(msg_tx(large_orphan))
464464

465465
# Something was evicted; the orphanage does not contain all large orphans + the 1p1c child
@@ -477,12 +477,12 @@ def test_orphanage_dos_many(self):
477477

478478
peer_normal = node.add_p2p_connection(P2PInterface())
479479

480-
# 2 sets of peers: the first set all send the same batch_size orphans. The second set each
481-
# sends batch_size distinct orphans.
480+
# The first set of peers all send the same batch_size orphans. Then a single peer sends
481+
# batch_single_doser distinct orphans.
482482
batch_size = 51
483483
num_peers_shared = 60
484-
num_peers_unique = 40
485-
484+
batch_single_doser = 100
485+
assert_greater_than(num_peers_shared * batch_size + batch_single_doser, 3000)
486486
# 60 peers * 51 orphans = 3060 announcements
487487
shared_orphans = [self.create_small_orphan() for _ in range(batch_size)]
488488
self.log.info(f"Send the same {batch_size} orphans from {num_peers_shared} DoSy peers (may take a while)")
@@ -522,22 +522,15 @@ def test_orphanage_dos_many(self):
522522
node.bumpmocktime(NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY)
523523
peer_normal.wait_for_getdata([parent_txid_int])
524524

525-
# Each of the num_peers_unique peers creates a distinct set of orphans
526-
many_orphans = [self.create_small_orphan() for _ in range(batch_size * num_peers_unique)]
527-
528-
self.log.info(f"Send sets of {batch_size} orphans from {num_peers_unique} DoSy peers (may take a while)")
529-
for peernum in range(num_peers_unique):
530-
peer_doser_batch = node.add_p2p_connection(P2PInterface())
531-
this_batch_orphans = many_orphans[batch_size*peernum : batch_size*(peernum+1)]
532-
for tx in this_batch_orphans:
533-
# Don't wait for responses, because it dramatically increases the runtime of this test.
534-
peer_doser_batch.send_without_ping(msg_tx(tx))
535-
536-
# Ensure at least one of the peer's orphans shows up in getorphantxs. Since each peer is
537-
# reserved a portion of orphanage space, this must happen as long as the orphans are not
538-
# rejected for some other reason.
539-
peer_doser_batch.sync_with_ping()
540-
self.wait_until(lambda: any([tx.txid_hex in node.getorphantxs() for tx in this_batch_orphans]))
525+
self.log.info(f"Send {batch_single_doser} new orphans from one DoSy peer")
526+
peer_doser_batch = node.add_p2p_connection(P2PInterface())
527+
this_batch_orphans = [self.create_small_orphan() for _ in range(batch_single_doser)]
528+
for tx in this_batch_orphans:
529+
# Don't wait for responses, because it dramatically increases the runtime of this test.
530+
peer_doser_batch.send_without_ping(msg_tx(tx))
531+
532+
peer_doser_batch.sync_with_ping()
533+
self.wait_until(lambda: any([tx.txid_hex in node.getorphantxs() for tx in this_batch_orphans]))
541534

542535
self.log.info("Check that orphan from normal peer still exists in orphanage")
543536
assert high_fee_child["txid"] in node.getorphantxs()

0 commit comments

Comments
 (0)