Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_proof_inventory.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2021 The Bitcoin developers | # Copyright (c) 2021 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
""" | """ | ||||
Test proof inventory relaying | Test proof inventory relaying | ||||
""" | """ | ||||
import time | import time | ||||
from test_framework.address import ADDRESS_ECREG_UNSPENDABLE | from test_framework.address import ADDRESS_ECREG_UNSPENDABLE | ||||
from test_framework.avatools import ( | from test_framework.avatools import ( | ||||
AvaP2PInterface, | |||||
avalanche_proof_from_hex, | avalanche_proof_from_hex, | ||||
gen_proof, | gen_proof, | ||||
get_proof_ids, | get_proof_ids, | ||||
wait_for_proof, | wait_for_proof, | ||||
) | ) | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
MSG_AVA_PROOF, | MSG_AVA_PROOF, | ||||
MSG_TYPE_MASK, | MSG_TYPE_MASK, | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | def test_ban_invalid_proof(self): | ||||
with node.assert_debug_log([ | with node.assert_debug_log([ | ||||
'Misbehaving', | 'Misbehaving', | ||||
'invalid-proof', | 'invalid-proof', | ||||
]): | ]): | ||||
peer.send_message(msg) | peer.send_message(msg) | ||||
peer.wait_for_disconnect() | peer.wait_for_disconnect() | ||||
def test_proof_relay(self): | def test_proof_relay(self): | ||||
# This test makes no sense with a single node ! | # This test makes no sense with less than 2 nodes ! | ||||
assert_greater_than(self.num_nodes, 1) | assert_greater_than(self.num_nodes, 2) | ||||
node = self.nodes[0] | |||||
def restart_nodes_with_proof(nodes=self.nodes): | proofs_keys = [self.generate_proof(self.nodes[0]) for _ in self.nodes] | ||||
proofs = [] | proofids = set([proof_key[1].proofid for proof_key in proofs_keys]) | ||||
for i in range(self.num_nodes): | |||||
proofs.append(self.generate_proof(self.nodes[0])) | |||||
self.sync_all() | self.sync_all() | ||||
# Restart nodes with new proofs | def restart_nodes_with_proof(nodes, extra_args=None): | ||||
for i, node in enumerate(nodes): | for node in nodes: | ||||
privkey, proof = proofs[i] | privkey, proof = proofs_keys[node.index] | ||||
self.restart_node(node.index, self.extra_args[node.index] + [ | self.restart_node(node.index, self.extra_args[node.index] + [ | ||||
"-avaproof={}".format(proof.serialize().hex()), | "-avaproof={}".format(proof.serialize().hex()), | ||||
"-avamasterkey={}".format(bytes_to_wif(privkey.get_bytes())) | "-avamasterkey={}".format(bytes_to_wif(privkey.get_bytes())) | ||||
]) | ] + (extra_args or [])) | ||||
[self.connect_nodes(node.index, j) for j in range(node.index)] | restart_nodes_with_proof(self.nodes[:-1]) | ||||
return set(proof.proofid for _, proof in proofs) | chainwork = int(self.nodes[-1].getblockchaininfo()['chainwork'], 16) | ||||
restart_nodes_with_proof( | |||||
self.nodes[-1:], extra_args=[f'-minimumchainwork={chainwork + 100:#x}']) | |||||
proofids = restart_nodes_with_proof(self.nodes) | [[self.connect_nodes(node.index, j) | ||||
for j in range(node.index)] for node in self.nodes] | |||||
# Connect a block to make the proofs added to our pool | # Connect a block to make the proofs added to our pool | ||||
node.generate(1) | self.nodes[0].generate(1) | ||||
self.sync_all() | self.sync_all() | ||||
self.log.info("Nodes should eventually get the proof from their peer") | self.log.info("Nodes should eventually get the proof from their peer") | ||||
self.sync_proofs() | self.sync_proofs(self.nodes[:-1]) | ||||
for node in self.nodes: | for node in self.nodes[:-1]: | ||||
assert_equal(set(get_proof_ids(node)), proofids) | assert_equal(set(get_proof_ids(node)), proofids) | ||||
assert self.nodes[-1].getblockchaininfo()['initialblockdownload'] | |||||
self.log.info("Except the node that has not completed IBD") | |||||
assert_equal(len(get_proof_ids(self.nodes[-1])), 1) | |||||
# The same if we send a proof directly with no download request | |||||
peer = AvaP2PInterface() | |||||
self.nodes[-1].add_p2p_connection(peer) | |||||
_, proof = self.generate_proof(self.nodes[0]) | |||||
peer.send_avaproof(proof) | |||||
peer.sync_send_with_ping() | |||||
with p2p_lock: | |||||
assert_equal(peer.message_count.get('getdata', 0), 0) | |||||
# Leave the nodes in good shape for the next tests | |||||
restart_nodes_with_proof(self.nodes) | |||||
[[self.connect_nodes(node.index, j) | |||||
for j in range(node.index)] for node in self.nodes] | |||||
def test_manually_sent_proof(self): | def test_manually_sent_proof(self): | ||||
node0 = self.nodes[0] | node0 = self.nodes[0] | ||||
_, proof = self.generate_proof(node0) | _, proof = self.generate_proof(node0) | ||||
self.log.info( | self.log.info( | ||||
"Send a proof via RPC and check all the nodes download it") | "Send a proof via RPC and check all the nodes download it") | ||||
node0.sendavalancheproof(proof.serialize().hex()) | node0.sendavalancheproof(proof.serialize().hex()) | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |