Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_getavaaddr.py
Show First 20 Lines • Show All 246 Lines • ▼ Show 20 Lines | def getavaaddr_outbound_test(self): | ||||
avapeers.append(avapeer) | avapeers.append(avapeer) | ||||
self.check_all_peers_received_getavaaddr_once(avapeers) | self.check_all_peers_received_getavaaddr_once(avapeers) | ||||
# Generate some block to poll for | # Generate some block to poll for | ||||
node.generate(1) | node.generate(1) | ||||
# Because none of the avalanche peers is responding, our node should | # Because none of the avalanche peers is responding, our node should | ||||
# fail out of option shortly and send a getavaaddr message to one of its | # fail out of option shortly and send a getavaaddr message to its | ||||
# outbound avalanche peers. | # outbound avalanche peers. | ||||
node.mockscheduler(MAX_GETAVAADDR_DELAY) | node.mockscheduler(MAX_GETAVAADDR_DELAY) | ||||
def any_peer_received_getavaaddr(): | def all_peers_received_getavaaddr(): | ||||
with p2p_lock: | with p2p_lock: | ||||
return any([p.message_count.get( | return all([p.message_count.get( | ||||
"getavaaddr", 0) > 1 for p in avapeers]) | "getavaaddr", 0) > 1 for p in avapeers]) | ||||
self.wait_until(any_peer_received_getavaaddr) | self.wait_until(all_peers_received_getavaaddr) | ||||
def getavaaddr_manual_test(self): | def getavaaddr_manual_test(self): | ||||
self.log.info( | self.log.info( | ||||
"Check we send a getavaaddr message to our manually connected peers that support avalanche") | "Check we send a getavaaddr message to our manually connected peers that support avalanche") | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
# Get rid of previously connected nodes | # Get rid of previously connected nodes | ||||
node.disconnect_p2ps() | node.disconnect_p2ps() | ||||
Show All 33 Lines | def getavaaddr_manual_test(self): | ||||
p.wait_until(lambda: p.message_count.get("getavaaddr", 0) > 1) | p.wait_until(lambda: p.message_count.get("getavaaddr", 0) > 1) | ||||
def getavaaddr_noquorum(self): | def getavaaddr_noquorum(self): | ||||
self.log.info( | self.log.info( | ||||
"Check we send a getavaaddr message while our quorum is not established") | "Check we send a getavaaddr message while our quorum is not established") | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
self.restart_node(0, extra_args=self.extra_args[0] + [ | self.restart_node(0, extra_args=self.extra_args[0] + [ | ||||
'-avaminquorumstake=1000000000', | '-avaminquorumstake=500000000', | ||||
'-avaminquorumconnectedstakeratio=0.8', | '-avaminquorumconnectedstakeratio=0.8', | ||||
]) | ]) | ||||
avapeers = [] | avapeers = [] | ||||
for i in range(16): | for i in range(16): | ||||
avapeer = AllYesAvaP2PInterface(node) | avapeer = AllYesAvaP2PInterface(node) | ||||
node.add_outbound_p2p_connection( | node.add_outbound_p2p_connection( | ||||
avapeer, | avapeer, | ||||
Show All 9 Lines | def getavaaddr_noquorum(self): | ||||
self.check_all_peers_received_getavaaddr_once(avapeers) | self.check_all_peers_received_getavaaddr_once(avapeers) | ||||
def total_getavaaddr_msg(): | def total_getavaaddr_msg(): | ||||
with p2p_lock: | with p2p_lock: | ||||
return sum([p.message_count.get("getavaaddr", 0) | return sum([p.message_count.get("getavaaddr", 0) | ||||
for p in avapeers]) | for p in avapeers]) | ||||
# Because we have not enough stake to start polling, we keep requesting | # Because we have not enough stake to start polling, we keep requesting | ||||
# more addresses | # more addresses from all our peers | ||||
total_getavaaddr = total_getavaaddr_msg() | total_getavaaddr = total_getavaaddr_msg() | ||||
for i in range(5): | |||||
node.mockscheduler(MAX_GETAVAADDR_DELAY) | node.mockscheduler(MAX_GETAVAADDR_DELAY) | ||||
self.wait_until(lambda: total_getavaaddr_msg() > total_getavaaddr) | self.wait_until(lambda: total_getavaaddr_msg() == | ||||
total_getavaaddr = total_getavaaddr_msg() | total_getavaaddr + len(avapeers)) | ||||
# Move the schedulter time forward to make seure we get statistics | # Move the schedulter time forward to make sure we get statistics | ||||
# computed. But since we did not start polling yet it should remain all | # computed. But since we did not start polling yet it should remain all | ||||
# zero. | # zero. | ||||
node.mockscheduler(AVALANCHE_STATISTICS_INTERVAL) | node.mockscheduler(AVALANCHE_STATISTICS_INTERVAL) | ||||
def wait_for_availability_score(): | def wait_for_availability_score(): | ||||
peerinfo = node.getpeerinfo() | peerinfo = node.getpeerinfo() | ||||
return all([p.get('availability_score', None) == Decimal(0) | return all([p.get('availability_score', None) == Decimal(0) | ||||
for p in peerinfo]) | for p in peerinfo]) | ||||
self.wait_until(wait_for_availability_score) | self.wait_until(wait_for_availability_score) | ||||
requester = node.add_p2p_connection(AddrReceiver()) | requester = node.add_p2p_connection(AddrReceiver()) | ||||
requester.send_and_ping(msg_getavaaddr()) | requester.send_and_ping(msg_getavaaddr()) | ||||
node.setmocktime(int(time.time() + MAX_ADDR_SEND_DELAY)) | node.setmocktime(int(time.time() + MAX_ADDR_SEND_DELAY)) | ||||
# Check all the peers addresses are returned. | # Check all the peers addresses are returned. | ||||
requester.wait_until(requester.addr_received) | requester.wait_until(requester.addr_received) | ||||
addresses = requester.get_received_addrs() | addresses = requester.get_received_addrs() | ||||
assert_equal(len(addresses), len(avapeers)) | assert_equal(len(addresses), len(avapeers)) | ||||
expected_addresses = [avapeer.addr for avapeer in avapeers] | expected_addresses = [avapeer.addr for avapeer in avapeers] | ||||
assert all([address in expected_addresses for address in addresses]) | assert all([address in expected_addresses for address in addresses]) | ||||
# Add more nodes so we reach the mininum quorum stake amount. | |||||
for _ in range(4): | |||||
avapeer = AllYesAvaP2PInterface(node) | |||||
node.add_p2p_connection(avapeer) | |||||
self.wait_until(lambda: node.getavalancheinfo()['active'] is True) | |||||
# From now only a single outbound peer is requested periodically | |||||
total_getavaaddr = total_getavaaddr_msg() | |||||
node.mockscheduler(MAX_GETAVAADDR_DELAY) | |||||
self.wait_until(lambda: total_getavaaddr_msg() == total_getavaaddr + 1) | |||||
# And no more | |||||
for p in avapeers: | |||||
p.sync_send_with_ping() | |||||
assert_equal(total_getavaaddr_msg(), total_getavaaddr + 1) | |||||
def test_send_inbound_getavaaddr_until_quorum_is_established(self): | def test_send_inbound_getavaaddr_until_quorum_is_established(self): | ||||
self.log.info( | self.log.info( | ||||
"Check we also request the inbounds until the quorum is established") | "Check we also request the inbounds until the quorum is established") | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
self.restart_node( | self.restart_node( | ||||
0, | 0, | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |