mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-09 11:27:28 -03:00
Merge bitcoin/bitcoin#31040: test: Assert that when we add the max orphan amount that we cannot add anymore and that a random orphan gets dropped
Some checks are pending
Some checks are pending
5c299ecafe
test: Assert that when we add the max orphan amount that we cannot add anymore and that a random orphan gets dropped (kevkevinpal) Pull request description: After joining the bitcoin pr review club about https://github.com/bitcoin/bitcoin/pull/30793 I learned about [`CVE-2012-3789`](https://github.com/bitcoin/bitcoin/blob/master/src/net_processing.cpp#L4693) So I was motivated to write a functional test that covers this part of the code, This test should add the max number of orphans to a nodes orphanage and then attempt to add another, then asserts that the number of orphans is still at the max amount ACKs for top commit: achow101: ACK5c299ecafe
rkrux: ACK5c299ecafe
instagibbs: ACK5c299ecafe
tdb3: ACK5c299ecafe
Tree-SHA512: 687bba337978e0945e94af71632998221e5565a5d83cf5a59ecf2ee52c7262d8ff907b94dceea3b80bed441dd19b24790b2904e88e1da14d30827c5469fcb4d3
This commit is contained in:
commit
25dacae9c7
2 changed files with 45 additions and 1 deletions
|
@ -5,6 +5,7 @@
|
|||
|
||||
import time
|
||||
|
||||
from test_framework.mempool_util import tx_in_orphanage
|
||||
from test_framework.messages import (
|
||||
CInv,
|
||||
CTxInWitness,
|
||||
|
@ -41,6 +42,8 @@ from test_framework.wallet import (
|
|||
# for one peer and y seconds for another, use specific values instead.
|
||||
TXREQUEST_TIME_SKIP = NONPREF_PEER_TX_DELAY + TXID_RELAY_DELAY + OVERLOADED_PEER_TX_DELAY + 1
|
||||
|
||||
DEFAULT_MAX_ORPHAN_TRANSACTIONS = 100
|
||||
|
||||
def cleanup(func):
|
||||
# Time to fastfoward (using setmocktime) in between subtests to ensure they do not interfere with
|
||||
# one another, in seconds. Equal to 12 hours, which is enough to expire anything that may exist
|
||||
|
@ -566,6 +569,47 @@ class OrphanHandlingTest(BitcoinTestFramework):
|
|||
assert tx_child["txid"] in node_mempool
|
||||
assert_equal(node.getmempoolentry(tx_child["txid"])["wtxid"], tx_child["wtxid"])
|
||||
|
||||
@cleanup
|
||||
def test_max_orphan_amount(self):
|
||||
self.log.info("Check that we never exceed our storage limits for orphans")
|
||||
|
||||
node = self.nodes[0]
|
||||
self.generate(self.wallet, 1)
|
||||
peer_1 = node.add_p2p_connection(P2PInterface())
|
||||
|
||||
self.log.info("Check that orphanage is empty on start of test")
|
||||
assert len(node.getorphantxs()) == 0
|
||||
|
||||
self.log.info("Filling up orphanage with " + str(DEFAULT_MAX_ORPHAN_TRANSACTIONS) + "(DEFAULT_MAX_ORPHAN_TRANSACTIONS) orphans")
|
||||
orphans = []
|
||||
parent_orphans = []
|
||||
for _ in range(DEFAULT_MAX_ORPHAN_TRANSACTIONS):
|
||||
tx_parent_1 = self.wallet.create_self_transfer()
|
||||
tx_child_1 = self.wallet.create_self_transfer(utxo_to_spend=tx_parent_1["new_utxo"])
|
||||
parent_orphans.append(tx_parent_1["tx"])
|
||||
orphans.append(tx_child_1["tx"])
|
||||
peer_1.send_message(msg_tx(tx_child_1["tx"]))
|
||||
|
||||
peer_1.sync_with_ping()
|
||||
orphanage = node.getorphantxs()
|
||||
assert_equal(len(orphanage), DEFAULT_MAX_ORPHAN_TRANSACTIONS)
|
||||
|
||||
for orphan in orphans:
|
||||
assert tx_in_orphanage(node, orphan)
|
||||
|
||||
self.log.info("Check that we do not add more than the max orphan amount")
|
||||
tx_parent_1 = self.wallet.create_self_transfer()
|
||||
tx_child_1 = self.wallet.create_self_transfer(utxo_to_spend=tx_parent_1["new_utxo"])
|
||||
peer_1.send_and_ping(msg_tx(tx_child_1["tx"]))
|
||||
parent_orphans.append(tx_parent_1["tx"])
|
||||
orphanage = node.getorphantxs()
|
||||
assert_equal(len(orphanage), DEFAULT_MAX_ORPHAN_TRANSACTIONS)
|
||||
|
||||
self.log.info("Clearing the orphanage")
|
||||
for index, parent_orphan in enumerate(parent_orphans):
|
||||
peer_1.send_and_ping(msg_tx(parent_orphan))
|
||||
assert_equal(len(node.getorphantxs()),0)
|
||||
|
||||
|
||||
def run_test(self):
|
||||
self.nodes[0].setmocktime(int(time.time()))
|
||||
|
@ -582,6 +626,7 @@ class OrphanHandlingTest(BitcoinTestFramework):
|
|||
self.test_same_txid_orphan()
|
||||
self.test_same_txid_orphan_of_orphan()
|
||||
self.test_orphan_txid_inv()
|
||||
self.test_max_orphan_amount()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -125,6 +125,5 @@ class GetOrphanTxsTest(BitcoinTestFramework):
|
|||
self.log.info("Check the transaction hex of orphan")
|
||||
assert_equal(orphan["hex"], tx["hex"])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
GetOrphanTxsTest(__file__).main()
|
||||
|
|
Loading…
Reference in a new issue