Changeset View
Changeset View
Standalone View
Standalone View
test/functional/abc_p2p_proof_inventory.py
Show All 17 Lines | from test_framework.messages import ( | ||||
MSG_TYPE_MASK, | MSG_TYPE_MASK, | ||||
) | ) | ||||
from test_framework.mininode import ( | from test_framework.mininode import ( | ||||
P2PInterface, | P2PInterface, | ||||
mininode_lock, | mininode_lock, | ||||
) | ) | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | |||||
assert_greater_than_or_equal, | |||||
connect_nodes, | connect_nodes, | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
import time | |||||
class ProofInvStoreP2PInterface(P2PInterface): | class ProofInvStoreP2PInterface(P2PInterface): | ||||
def __init__(self): | def __init__(self): | ||||
super().__init__() | super().__init__() | ||||
self.proof_invs = set() | self.proof_invs = set() | ||||
self.proof_invs_counter = 0 | |||||
def on_inv(self, message): | def on_inv(self, message): | ||||
for i in message.inv: | for i in message.inv: | ||||
if i.type & MSG_TYPE_MASK == MSG_AVA_PROOF: | if i.type & MSG_TYPE_MASK == MSG_AVA_PROOF: | ||||
self.proof_invs.add(i.hash) | self.proof_invs.add(i.hash) | ||||
self.proof_invs_counter += 1 | |||||
class ProofInventoryTest(BitcoinTestFramework): | class ProofInventoryTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.extra_args = [['-enableavalanche=1', | self.extra_args = [['-enableavalanche=1', | ||||
'-avacooldown=0']] * self.num_nodes | '-avacooldown=0']] * self.num_nodes | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | def test_send_proof_inv(self): | ||||
node.sendavalancheproof(proof.serialize().hex()) | node.sendavalancheproof(proof.serialize().hex()) | ||||
assert proof.proofid in get_proof_ids(node) | assert proof.proofid in get_proof_ids(node) | ||||
peer = ProofInvStoreP2PInterface() | peer = ProofInvStoreP2PInterface() | ||||
node.add_p2p_connection(peer) | node.add_p2p_connection(peer) | ||||
wait_until(lambda: set(get_proof_ids(node)) == peer.proof_invs) | wait_until(lambda: set(get_proof_ids(node)) == peer.proof_invs) | ||||
self.log.info("Test that we don't send the same inv several times") | |||||
_, spam_proof = self.gen_proof(node) | |||||
node.sendavalancheproof(spam_proof.serialize().hex()) | |||||
assert spam_proof.proofid in get_proof_ids(node) | |||||
wait_until(lambda: set(get_proof_ids(node)) == peer.proof_invs) | |||||
initial_num_proof_invs = peer.proof_invs_counter | |||||
assert_greater_than_or_equal( | |||||
initial_num_proof_invs, len( | |||||
peer.proof_invs)) | |||||
# From now we will stop broadcasting this proof to the same peer | |||||
for i in range(10): | |||||
node.sendavalancheproof(spam_proof.serialize().hex()) | |||||
# Force the node to run the send loop by sending it some message, and | |||||
# give enough time for our peer to receive the possible invs | |||||
peer.sync_with_ping() | |||||
time.sleep(2) | |||||
assert_equal(peer.proof_invs_counter, initial_num_proof_invs) | |||||
def run_test(self): | def run_test(self): | ||||
self.test_send_proof_inv() | self.test_send_proof_inv() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
ProofInventoryTest().main() | ProofInventoryTest().main() |