Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_avalanche_peer_discovery.py
Show All 34 Lines | |||||
UNCONDITIONAL_RELAY_DELAY = 2 * 60 | UNCONDITIONAL_RELAY_DELAY = 2 * 60 | ||||
class AvalancheTest(BitcoinTestFramework): | class AvalancheTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [['-enableavalanche=1', | self.extra_args = [['-enableavalanche=1', | ||||
'-avaproofstakeutxoconfirmations=1', | '-avaproofstakeutxoconfirmations=3', | ||||
'-enableavalanchepeerdiscovery=1']] | '-enableavalanchepeerdiscovery=1']] | ||||
self.supports_cli = False | self.supports_cli = False | ||||
def run_test(self): | def run_test(self): | ||||
node = self.nodes[0] | node = self.nodes[0] | ||||
# duplicate the deterministic sig test from src/test/key_tests.cpp | # duplicate the deterministic sig test from src/test/key_tests.cpp | ||||
privkey = ECKey() | privkey = ECKey() | ||||
privkey.set(bytes.fromhex( | privkey.set(bytes.fromhex( | ||||
"12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747"), True) | "12b004fff7f4b69ef8650e767f18f11ede158148b425660723b9f9a66e61f747"), True) | ||||
wif_privkey = bytes_to_wif(privkey.get_bytes()) | wif_privkey = bytes_to_wif(privkey.get_bytes()) | ||||
self.log.info( | self.log.info( | ||||
"Check the node is signalling the avalanche service bit only if there is a proof.") | "Check the node is signalling the avalanche service bit only if there is a proof.") | ||||
assert_equal( | assert_equal( | ||||
int(node.getnetworkinfo()['localservices'], 16) & NODE_AVALANCHE, | int(node.getnetworkinfo()['localservices'], 16) & NODE_AVALANCHE, | ||||
0) | 0) | ||||
# Create stakes by mining blocks | # Create stakes by mining blocks | ||||
addrkey0 = node.get_deterministic_priv_key() | addrkey0 = node.get_deterministic_priv_key() | ||||
blockhashes = node.generatetoaddress(2, addrkey0.address) | blockhashes = node.generatetoaddress(4, addrkey0.address) | ||||
stakes = create_coinbase_stakes(node, [blockhashes[0]], addrkey0.key) | stakes = create_coinbase_stakes(node, [blockhashes[0]], addrkey0.key) | ||||
proof_sequence = 11 | proof_sequence = 11 | ||||
proof_expiration = 12 | proof_expiration = 12 | ||||
proof = node.buildavalancheproof( | proof = node.buildavalancheproof( | ||||
proof_sequence, proof_expiration, wif_privkey, stakes) | proof_sequence, proof_expiration, wif_privkey, stakes) | ||||
# Restart the node | # Restart the node | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
"The proof has not been announced, it cannot be requested") | "The proof has not been announced, it cannot be requested") | ||||
peer = get_ava_p2p_interface(node, services=NODE_NETWORK) | peer = get_ava_p2p_interface(node, services=NODE_NETWORK) | ||||
# Build a new proof and only announce this one | # Build a new proof and only announce this one | ||||
_, new_proof_obj = gen_proof(node) | _, new_proof_obj = gen_proof(node) | ||||
new_proof = new_proof_obj.serialize().hex() | new_proof = new_proof_obj.serialize().hex() | ||||
new_proofid = new_proof_obj.proofid | new_proofid = new_proof_obj.proofid | ||||
# Make the proof mature | |||||
node.generate(2) | |||||
node.sendavalancheproof(new_proof) | node.sendavalancheproof(new_proof) | ||||
wait_for_proof(node, f"{new_proofid:0{64}x}") | wait_for_proof(node, f"{new_proofid:0{64}x}") | ||||
# Request both our local proof and the new proof | # Request both our local proof and the new proof | ||||
getdata = msg_getdata( | getdata = msg_getdata( | ||||
[CInv(MSG_AVA_PROOF, node_proofid), CInv(MSG_AVA_PROOF, new_proofid)]) | [CInv(MSG_AVA_PROOF, node_proofid), CInv(MSG_AVA_PROOF, new_proofid)]) | ||||
peer.send_message(getdata) | peer.send_message(getdata) | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info("Check that repeated avahello messages are ignored") | self.log.info("Check that repeated avahello messages are ignored") | ||||
for i in range(3): | for i in range(3): | ||||
with node.assert_debug_log(['Ignoring avahello from peer']): | with node.assert_debug_log(['Ignoring avahello from peer']): | ||||
peer_proof_known.send_avahello( | peer_proof_known.send_avahello( | ||||
interface_delegation_hex, delegated_key) | interface_delegation_hex, delegated_key) | ||||
self.log.info("Invalidate the proof and check the nodes are removed") | self.log.info("Invalidate the proof and check the nodes are removed") | ||||
tip = node.getbestblockhash() | tip = node.getbestblockhash() | ||||
# Invalidate the block with the proof utxo | # Invalidate the block after the proof utxo to make the proof immature | ||||
node.invalidateblock(blockhashes[1]) | node.invalidateblock(blockhashes[2]) | ||||
# Change the address to make sure we don't generate a block identical | # Change the address to make sure we don't generate a block identical | ||||
# to the one we just invalidated. Can be generate(1) after D9694 or | # to the one we just invalidated. Can be generate(1) after D9694 or | ||||
# D9697 is landed. | # D9697 is landed. | ||||
forked_tip = node.generatetoaddress(1, ADDRESS_ECREG_UNSPENDABLE)[0] | forked_tip = node.generatetoaddress(1, ADDRESS_ECREG_UNSPENDABLE)[0] | ||||
self.wait_until(lambda: node.getbestblockhash() == forked_tip) | self.wait_until(lambda: node.getbestblockhash() == forked_tip) | ||||
self.wait_until(lambda: len(node.getavalanchepeerinfo()) == 1) | self.wait_until(lambda: len(node.getavalanchepeerinfo()) == 1) | ||||
assert peer_proofid not in get_proof_ids(node) | assert peer_proofid not in get_proof_ids(node) | ||||
Show All 15 Lines |