Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_avalanche_peer_discovery.py
Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"-avaproof={}".format(proof), | "-avaproof={}".format(proof), | ||||
"-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", | "-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", | ||||
]) | ]) | ||||
assert_equal( | assert_equal( | ||||
int(node.getnetworkinfo()['localservices'], 16) & NODE_AVALANCHE, | int(node.getnetworkinfo()['localservices'], 16) & NODE_AVALANCHE, | ||||
NODE_AVALANCHE) | NODE_AVALANCHE) | ||||
self.log.info("Test the avahello signature (node -> P2PInterface)") | def check_avahello(args): | ||||
good_interface = get_ava_p2p_interface(node) | # Restart the node with the given args | ||||
avahello = good_interface.wait_for_avahello().hello | self.restart_node(0, self.extra_args[0] + args) | ||||
peer = get_ava_p2p_interface(node) | |||||
avahello = peer.wait_for_avahello().hello | |||||
avakey = ECPubKey() | avakey = ECPubKey() | ||||
avakey.set(bytes.fromhex(node.getavalanchekey())) | avakey.set(bytes.fromhex(node.getavalanchekey())) | ||||
assert avakey.verify_schnorr( | assert avakey.verify_schnorr( | ||||
avahello.sig, avahello.get_sighash(good_interface)) | avahello.sig, avahello.get_sighash(peer)) | ||||
self.log.info( | |||||
"Test the avahello signature with a generated delegation") | |||||
check_avahello([ | |||||
"-avaproof={}".format(proof), | |||||
"-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN" | |||||
]) | |||||
master_key = ECKey() | |||||
master_key.generate() | |||||
limited_id = FromHex(AvalancheProof(), proof).limited_proofid | |||||
delegation = node.delegateavalancheproof( | |||||
f"{limited_id:0{64}x}", | |||||
bytes_to_wif(privkey.get_bytes()), | |||||
master_key.get_pubkey().get_bytes().hex(), | |||||
) | |||||
self.log.info("Test the avahello signature with a supplied delegation") | |||||
check_avahello([ | |||||
"-avaproof={}".format(proof), | |||||
"-avadelegation={}".format(delegation), | |||||
"-avamasterkey={}".format(bytes_to_wif(master_key.get_bytes())), | |||||
]) | |||||
stakes = create_coinbase_stakes(node, [blockhashes[1]], addrkey0.key) | stakes = create_coinbase_stakes(node, [blockhashes[1]], addrkey0.key) | ||||
interface_proof_hex = node.buildavalancheproof( | interface_proof_hex = node.buildavalancheproof( | ||||
proof_sequence, proof_expiration, pubkey.get_bytes().hex(), | proof_sequence, proof_expiration, pubkey.get_bytes().hex(), | ||||
stakes) | stakes) | ||||
limited_id = FromHex( | limited_id = FromHex( | ||||
AvalancheProof(), | AvalancheProof(), | ||||
interface_proof_hex).limited_proofid | interface_proof_hex).limited_proofid | ||||
Show All 14 Lines | def run_test(self): | ||||
with self.nodes[0].assert_debug_log( | with self.nodes[0].assert_debug_log( | ||||
["Misbehaving", | ["Misbehaving", | ||||
"peer=1 (0 -> 100) BAN THRESHOLD EXCEEDED: invalid-avahello-signature"]): | "peer=1 (0 -> 100) BAN THRESHOLD EXCEEDED: invalid-avahello-signature"]): | ||||
bad_interface.send_avahello(interface_delegation_hex, wrong_key) | bad_interface.send_avahello(interface_delegation_hex, wrong_key) | ||||
bad_interface.wait_for_disconnect() | bad_interface.wait_for_disconnect() | ||||
self.log.info( | self.log.info( | ||||
'Check that receiving a valid avahello triggers a proof getdata request') | 'Check that receiving a valid avahello triggers a proof getdata request') | ||||
good_interface = get_ava_p2p_interface(node) | |||||
proofid = good_interface.send_avahello( | proofid = good_interface.send_avahello( | ||||
interface_delegation_hex, delegated_key) | interface_delegation_hex, delegated_key) | ||||
def getdata_found(): | def getdata_found(): | ||||
with p2p_lock: | with p2p_lock: | ||||
return good_interface.last_message.get( | return good_interface.last_message.get( | ||||
"getdata") and good_interface.last_message["getdata"].inv[-1].hash == proofid | "getdata") and good_interface.last_message["getdata"].inv[-1].hash == proofid | ||||
wait_until(getdata_found) | wait_until(getdata_found) | ||||
▲ Show 20 Lines • Show All 51 Lines • Show Last 20 Lines |