Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_tx_download.py
Show All 39 Lines | def on_getdata(self, message): | ||||
self.tx_getdata_count += 1 | self.tx_getdata_count += 1 | ||||
# Constants from net_processing | # Constants from net_processing | ||||
GETDATA_TX_INTERVAL = 60 # seconds | GETDATA_TX_INTERVAL = 60 # seconds | ||||
INBOUND_PEER_TX_DELAY = 2 # seconds | INBOUND_PEER_TX_DELAY = 2 # seconds | ||||
OVERLOADED_PEER_DELAY = 2 # seconds | OVERLOADED_PEER_DELAY = 2 # seconds | ||||
MAX_GETDATA_IN_FLIGHT = 100 | MAX_GETDATA_IN_FLIGHT = 100 | ||||
MAX_PEER_TX_ANNOUNCEMENTS = 5000 | |||||
# Python test constants | # Python test constants | ||||
NUM_INBOUND = 10 | NUM_INBOUND = 10 | ||||
MAX_GETDATA_INBOUND_WAIT = GETDATA_TX_INTERVAL + INBOUND_PEER_TX_DELAY | MAX_GETDATA_INBOUND_WAIT = GETDATA_TX_INTERVAL + INBOUND_PEER_TX_DELAY | ||||
class TxDownloadTest(BitcoinTestFramework): | class TxDownloadTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
▲ Show 20 Lines • Show All 199 Lines • ▼ Show 20 Lines | def test_preferred_inv(self): | ||||
'Check that invs from preferred peers are downloaded immediately') | 'Check that invs from preferred peers are downloaded immediately') | ||||
self.restart_node(0, extra_args=['-whitelist=noban@127.0.0.1']) | self.restart_node(0, extra_args=['-whitelist=noban@127.0.0.1']) | ||||
peer = self.nodes[0].add_p2p_connection(TestP2PConn()) | peer = self.nodes[0].add_p2p_connection(TestP2PConn()) | ||||
peer.send_message(msg_inv([CInv(t=MSG_TX, h=0xff00ff00)])) | peer.send_message(msg_inv([CInv(t=MSG_TX, h=0xff00ff00)])) | ||||
peer.wait_until(lambda: peer.tx_getdata_count >= 1, timeout=1) | peer.wait_until(lambda: peer.tx_getdata_count >= 1, timeout=1) | ||||
with mininode_lock: | with mininode_lock: | ||||
assert_equal(peer.tx_getdata_count, 1) | assert_equal(peer.tx_getdata_count, 1) | ||||
def test_large_inv_batch(self): | |||||
self.log.info( | |||||
'Test how large inv batches are handled with relay permission') | |||||
self.restart_node(0, extra_args=['-whitelist=relay@127.0.0.1']) | |||||
peer = self.nodes[0].add_p2p_connection(TestP2PConn()) | |||||
peer.send_message(msg_inv([CInv(t=MSG_TX, h=txid) | |||||
for txid in range(MAX_PEER_TX_ANNOUNCEMENTS + 1)])) | |||||
peer.wait_until(lambda: peer.tx_getdata_count == | |||||
MAX_PEER_TX_ANNOUNCEMENTS + 1) | |||||
self.log.info( | |||||
'Test how large inv batches are handled without relay permission') | |||||
self.restart_node(0) | |||||
peer = self.nodes[0].add_p2p_connection(TestP2PConn()) | |||||
peer.send_message(msg_inv([CInv(t=MSG_TX, h=txid) | |||||
for txid in range(MAX_PEER_TX_ANNOUNCEMENTS + 1)])) | |||||
peer.wait_until(lambda: peer.tx_getdata_count == | |||||
MAX_PEER_TX_ANNOUNCEMENTS) | |||||
peer.sync_with_ping() | |||||
with mininode_lock: | |||||
assert_equal(peer.tx_getdata_count, MAX_PEER_TX_ANNOUNCEMENTS) | |||||
def test_spurious_notfound(self): | def test_spurious_notfound(self): | ||||
self.log.info('Check that spurious notfound is ignored') | self.log.info('Check that spurious notfound is ignored') | ||||
self.nodes[0].p2ps[0].send_message(msg_notfound(vec=[CInv(MSG_TX, 1)])) | self.nodes[0].p2ps[0].send_message(msg_notfound(vec=[CInv(MSG_TX, 1)])) | ||||
def run_test(self): | def run_test(self): | ||||
# Run tests without mocktime that only need one peer-connection first, | # Run tests without mocktime that only need one peer-connection first, | ||||
# to avoid restarting the nodes | # to avoid restarting the nodes | ||||
self.test_expiry_fallback() | self.test_expiry_fallback() | ||||
self.test_disconnect_fallback() | self.test_disconnect_fallback() | ||||
self.test_notfound_fallback() | self.test_notfound_fallback() | ||||
self.test_preferred_inv() | self.test_preferred_inv() | ||||
self.test_large_inv_batch() | |||||
self.test_spurious_notfound() | self.test_spurious_notfound() | ||||
# Run each test against new bitcoind instances, as setting mocktimes has long-term effects on when | # Run each test against new bitcoind instances, as setting mocktimes has long-term effects on when | ||||
# the next trickle relay event happens. | # the next trickle relay event happens. | ||||
for test in [self.test_in_flight_max, | for test in [self.test_in_flight_max, | ||||
self.test_inv_block, self.test_tx_requests]: | self.test_inv_block, self.test_tx_requests]: | ||||
self.stop_nodes() | self.stop_nodes() | ||||
self.start_nodes() | self.start_nodes() | ||||
Show All 13 Lines |