Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_eviction.py
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
block_peer.send_blocks_and_test([block], node, success=True) | block_peer.send_blocks_and_test([block], node, success=True) | ||||
protected_peers.add(current_peer) | protected_peers.add(current_peer) | ||||
self.log.info( | self.log.info( | ||||
"Create 4 peers and protect them from eviction by sending us a proof") | "Create 4 peers and protect them from eviction by sending us a proof") | ||||
privkey = ECKey() | privkey = ECKey() | ||||
privkey.generate() | privkey.generate() | ||||
wif_privkey = bytes_to_wif(privkey.get_bytes()) | wif_privkey = bytes_to_wif(privkey.get_bytes()) | ||||
pubkey = privkey.get_pubkey() | |||||
stakes = create_coinbase_stakes( | stakes = create_coinbase_stakes( | ||||
node, blocks, node.get_deterministic_priv_key().key) | node, blocks, node.get_deterministic_priv_key().key) | ||||
for i in range(4): | for i in range(4): | ||||
proof_peer = node.add_p2p_connection(SlowP2PDataStore()) | proof_peer = node.add_p2p_connection(SlowP2PDataStore()) | ||||
current_peer += 1 | current_peer += 1 | ||||
proof_peer.sync_with_ping() | proof_peer.sync_with_ping() | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
fastpeer = node.add_p2p_connection(P2PInterface()) | fastpeer = node.add_p2p_connection(P2PInterface()) | ||||
current_peer += 1 | current_peer += 1 | ||||
self.wait_until(lambda: "ping" in fastpeer.last_message, | self.wait_until(lambda: "ping" in fastpeer.last_message, | ||||
timeout=10) | timeout=10) | ||||
self.log.info( | self.log.info( | ||||
"Create 128 peers and protect them from eviction by sending an avahello message") | "Create 128 peers and protect them from eviction by sending an avahello message") | ||||
proof = node.buildavalancheproof( | |||||
42, 2000000000, wif_privkey, [stakes[0]]) | |||||
proof_obj = avalanche_proof_from_hex(proof) | |||||
delegation = node.delegateavalancheproof( | |||||
f"{proof_obj.limited_proofid:064x}", | |||||
bytes_to_wif(privkey.get_bytes()), | |||||
pubkey.get_bytes().hex(), | |||||
) | |||||
for _ in range(128): | for _ in range(128): | ||||
avapeer = node.add_p2p_connection(SlowAvaP2PInterface()) | node.add_p2p_connection(SlowAvaP2PInterface()) | ||||
current_peer += 1 | current_peer += 1 | ||||
avapeer.sync_with_ping() | |||||
avapeer.send_avahello(delegation, privkey) | |||||
# Make sure by asking the node what the actual min pings are | # Make sure by asking the node what the actual min pings are | ||||
peerinfo = node.getpeerinfo() | peerinfo = node.getpeerinfo() | ||||
pings = {} | pings = {} | ||||
for i in range(len(peerinfo)): | for i in range(len(peerinfo)): | ||||
pings[i] = peerinfo[i]['minping'] if 'minping' in peerinfo[i] else 1000000 | pings[i] = peerinfo[i]['minping'] if 'minping' in peerinfo[i] else 1000000 | ||||
sorted_pings = sorted(pings.items(), key=lambda x: x[1]) | sorted_pings = sorted(pings.items(), key=lambda x: x[1]) | ||||
Show All 34 Lines |