Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_inv_download.py
Show First 20 Lines • Show All 261 Lines • ▼ Show 20 Lines | def test_expiry_fallback(self, context): | ||||
peer_expiry, peer_fallback = ( | peer_expiry, peer_fallback = ( | ||||
peer1, peer2) if peer1.getdata_count == 1 else ( | peer1, peer2) if peer1.getdata_count == 1 else ( | ||||
peer2, peer1) | peer2, peer1) | ||||
assert_equal(peer_fallback.getdata_count, 0) | assert_equal(peer_fallback.getdata_count, 0) | ||||
# Wait for request to peer_expiry to expire | # Wait for request to peer_expiry to expire | ||||
self.nodes[0].setmocktime( | self.nodes[0].setmocktime( | ||||
int(time.time()) + context.constants.getdata_interval + 1) | int(time.time()) + context.constants.getdata_interval + 1) | ||||
peer_fallback.wait_until( | peer_fallback.wait_until( | ||||
lambda: peer_fallback.getdata_count >= 1, timeout=1) | lambda: peer_fallback.getdata_count >= 1) | ||||
with p2p_lock: | with p2p_lock: | ||||
assert_equal(peer_fallback.getdata_count, 1) | assert_equal(peer_fallback.getdata_count, 1) | ||||
# reset mocktime | # reset mocktime | ||||
self.restart_node(0) | self.restart_node(0) | ||||
def test_disconnect_fallback(self, context): | def test_disconnect_fallback(self, context): | ||||
self.log.info( | self.log.info( | ||||
'Check that disconnect will select another peer for download') | 'Check that disconnect will select another peer for download') | ||||
Show All 9 Lines | def test_disconnect_fallback(self, context): | ||||
with p2p_lock: | with p2p_lock: | ||||
peer_disconnect, peer_fallback = ( | peer_disconnect, peer_fallback = ( | ||||
peer1, peer2) if peer1.getdata_count == 1 else ( | peer1, peer2) if peer1.getdata_count == 1 else ( | ||||
peer2, peer1) | peer2, peer1) | ||||
assert_equal(peer_fallback.getdata_count, 0) | assert_equal(peer_fallback.getdata_count, 0) | ||||
peer_disconnect.peer_disconnect() | peer_disconnect.peer_disconnect() | ||||
peer_disconnect.wait_for_disconnect() | peer_disconnect.wait_for_disconnect() | ||||
peer_fallback.wait_until( | peer_fallback.wait_until( | ||||
lambda: peer_fallback.getdata_count >= 1, timeout=1) | lambda: peer_fallback.getdata_count >= 1) | ||||
with p2p_lock: | with p2p_lock: | ||||
assert_equal(peer_fallback.getdata_count, 1) | assert_equal(peer_fallback.getdata_count, 1) | ||||
def test_notfound_fallback(self, context): | def test_notfound_fallback(self, context): | ||||
self.log.info( | self.log.info( | ||||
'Check that notfounds will select another peer for download immediately') | 'Check that notfounds will select another peer for download immediately') | ||||
peer1 = self.nodes[0].add_p2p_connection(context.p2p_conn()) | peer1 = self.nodes[0].add_p2p_connection(context.p2p_conn()) | ||||
peer2 = self.nodes[0].add_p2p_connection(context.p2p_conn()) | peer2 = self.nodes[0].add_p2p_connection(context.p2p_conn()) | ||||
for p in [peer1, peer2]: | for p in [peer1, peer2]: | ||||
p.send_message(msg_inv([CInv(t=context.inv_type, h=0xffdd)])) | p.send_message(msg_inv([CInv(t=context.inv_type, h=0xffdd)])) | ||||
# One of the peers is asked for the data | # One of the peers is asked for the data | ||||
peer2.wait_until( | peer2.wait_until( | ||||
lambda: sum( | lambda: sum( | ||||
p.getdata_count for p in [ | p.getdata_count for p in [ | ||||
peer1, peer2]) == 1) | peer1, peer2]) == 1) | ||||
with p2p_lock: | with p2p_lock: | ||||
peer_notfound, peer_fallback = ( | peer_notfound, peer_fallback = ( | ||||
peer1, peer2) if peer1.getdata_count == 1 else ( | peer1, peer2) if peer1.getdata_count == 1 else ( | ||||
peer2, peer1) | peer2, peer1) | ||||
assert_equal(peer_fallback.getdata_count, 0) | assert_equal(peer_fallback.getdata_count, 0) | ||||
# Send notfound, so that fallback peer is selected | # Send notfound, so that fallback peer is selected | ||||
peer_notfound.send_and_ping(msg_notfound( | peer_notfound.send_and_ping(msg_notfound( | ||||
vec=[CInv(context.inv_type, 0xffdd)])) | vec=[CInv(context.inv_type, 0xffdd)])) | ||||
peer_fallback.wait_until( | peer_fallback.wait_until( | ||||
lambda: peer_fallback.getdata_count >= 1, timeout=1) | lambda: peer_fallback.getdata_count >= 1) | ||||
with p2p_lock: | with p2p_lock: | ||||
assert_equal(peer_fallback.getdata_count, 1) | assert_equal(peer_fallback.getdata_count, 1) | ||||
def test_preferred_inv(self, context): | def test_preferred_inv(self, context): | ||||
self.log.info( | self.log.info( | ||||
'Check that invs from preferred peers are downloaded immediately') | 'Check that invs from preferred peers are downloaded immediately') | ||||
self.restart_node( | self.restart_node( | ||||
0, | 0, | ||||
extra_args=self.extra_args[0] + | extra_args=self.extra_args[0] + | ||||
['-whitelist=noban@127.0.0.1']) | ['-whitelist=noban@127.0.0.1']) | ||||
peer = self.nodes[0].add_p2p_connection(context.p2p_conn()) | peer = self.nodes[0].add_p2p_connection(context.p2p_conn()) | ||||
peer.send_message(msg_inv([CInv(t=context.inv_type, h=0xff00ff00)])) | peer.send_message(msg_inv([CInv(t=context.inv_type, h=0xff00ff00)])) | ||||
peer.wait_until(lambda: peer.getdata_count >= 1, timeout=1) | peer.wait_until(lambda: peer.getdata_count >= 1) | ||||
with p2p_lock: | with p2p_lock: | ||||
assert_equal(peer.getdata_count, 1) | assert_equal(peer.getdata_count, 1) | ||||
def test_large_inv_batch(self, context): | def test_large_inv_batch(self, context): | ||||
max_peer_announcements = context.constants.max_peer_announcements | max_peer_announcements = context.constants.max_peer_announcements | ||||
net_permissions = context.constants.bypass_request_limits_permission_flags | net_permissions = context.constants.bypass_request_limits_permission_flags | ||||
self.log.info( | self.log.info( | ||||
'Test how large inv batches are handled with {} permission'.format(net_permissions)) | 'Test how large inv batches are handled with {} permission'.format(net_permissions)) | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |