Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_avalanche.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2020-2021 The Bitcoin developers | # Copyright (c) 2020-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 the resolution of forks via avalanche.""" | """Test the resolution of forks via avalanche.""" | ||||
import random | import random | ||||
import struct | import struct | ||||
import time | import time | ||||
from test_framework.avatools import create_coinbase_stakes | from test_framework.avatools import create_coinbase_stakes, get_proof_ids | ||||
from test_framework.key import ( | from test_framework.key import ( | ||||
bytes_to_wif, | bytes_to_wif, | ||||
ECKey, | ECKey, | ||||
ECPubKey, | ECPubKey, | ||||
) | ) | ||||
from test_framework.p2p import P2PInterface, p2p_lock | from test_framework.p2p import P2PInterface, p2p_lock | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
AvalancheDelegation, | AvalancheDelegation, | ||||
▲ Show 20 Lines • Show All 404 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
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) | ||||
self.log.info('Check that we can download the proof from our peer') | self.log.info('Check that we can download the proof from our peer') | ||||
node_proofid = FromHex(AvalancheProof(), proof).proofid | |||||
def wait_for_proof_validation(): | |||||
# Connect some blocks to trigger the proof verification | # Connect some blocks to trigger the proof verification | ||||
node.generate(2) | node.generate(2) | ||||
wait_until(lambda: node_proofid in get_proof_ids(node)) | |||||
wait_for_proof_validation() | |||||
node_proofid = FromHex(AvalancheProof(), proof).proofid | |||||
getdata = msg_getdata([CInv(MSG_AVA_PROOF, node_proofid)]) | getdata = msg_getdata([CInv(MSG_AVA_PROOF, node_proofid)]) | ||||
self.log.info( | self.log.info( | ||||
"Proof has been inv'ed recently, check it can be requested") | "Proof has been inv'ed recently, check it can be requested") | ||||
good_interface.send_message(getdata) | good_interface.send_message(getdata) | ||||
def proof_received(peer): | def proof_received(peer): | ||||
with p2p_lock: | with p2p_lock: | ||||
return peer.last_message.get( | return peer.last_message.get( | ||||
"avaproof") and peer.last_message["avaproof"].proof.proofid == node_proofid | "avaproof") and peer.last_message["avaproof"].proof.proofid == node_proofid | ||||
wait_until(lambda: proof_received(good_interface)) | wait_until(lambda: proof_received(good_interface)) | ||||
# Restart the node | # Restart the node | ||||
self.restart_node(0, self.extra_args[0] + [ | self.restart_node(0, self.extra_args[0] + [ | ||||
"-avaproof={}".format(proof), | "-avaproof={}".format(proof), | ||||
"-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", | "-avamasterkey=cND2ZvtabDbJ1gucx9GWH6XT9kgTAqfb6cotPt5Q5CyxVDhid2EN", | ||||
]) | ]) | ||||
node.generate(2) | wait_for_proof_validation() | ||||
self.log.info( | self.log.info( | ||||
"The proof has not been announced, it cannot be requested") | "The proof has not been announced, it cannot be requested") | ||||
peer = get_node(services=NODE_NETWORK) | peer = get_node(services=NODE_NETWORK) | ||||
peer.send_message(getdata) | peer.send_message(getdata) | ||||
# Give enough time for the node to answer. Since we cannot check for a | # Give enough time for the node to answer. Since we cannot check for a | ||||
# non-event this is the best we can do | # non-event this is the best we can do | ||||
Show All 13 Lines |