diff --git a/test/functional/abc_p2p_avalanche_proof_voting.py b/test/functional/abc_p2p_avalanche_proof_voting.py --- a/test/functional/abc_p2p_avalanche_proof_voting.py +++ b/test/functional/abc_p2p_avalanche_proof_voting.py @@ -20,12 +20,7 @@ AvalancheVote, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - assert_greater_than, - assert_raises_rpc_error, - try_rpc, -) +from test_framework.util import assert_equal, assert_raises_rpc_error, try_rpc from test_framework.wallet_util import bytes_to_wif QUORUM_NODE_COUNT = 16 @@ -86,6 +81,20 @@ return found_hash + def can_not_find_proof_in_poll(self, hash, response): + # We call can_find_proof_in_poll multiple times to be sure of the + # outcome. + for _ in range(5): + if self.can_find_proof_in_poll(hash, response): + return False + + # The expected poll wasn't found. Wait a little and try again. + time.sleep(0.5) + + # After a short time, it appears that no peer is being polled for this + # item. + return True + @staticmethod def send_proof(from_peer, proof_hex): proof = avalanche_proof_from_hex(proof_hex) @@ -245,17 +254,9 @@ self.log.info("Test the peer replacement rate limit") # Wait until proof_seq30 is finalized - retry = 5 - while retry > 0: - try: - with node.assert_debug_log([f"Avalanche finalized proof {proofid_seq30:0{64}x}"]): - self.wait_until(lambda: not self.can_find_proof_in_poll( - proofid_seq30, response=AvalancheProofVoteResponse.ACTIVE)) - break - except AssertionError: - retry -= 1 - - assert_greater_than(retry, 0) + with node.assert_debug_log([f"Avalanche finalized proof {proofid_seq30:0{64}x}"]): + self.wait_until(lambda: self.can_not_find_proof_in_poll( + proofid_seq30, response=AvalancheProofVoteResponse.ACTIVE)) # Not enough assert self.conflicting_proof_cooldown < self.peer_replacement_cooldown @@ -470,17 +471,9 @@ proofid_seq1, response=AvalancheProofVoteResponse.UNKNOWN), timeout=10) # Wait until proof_seq1 voting goes stale - retry = 5 - while retry > 0: - try: - with node.assert_debug_log([f"Avalanche stalled proof {proofid_seq1:0{64}x}"]): - self.wait_until(lambda: not self.can_find_proof_in_poll( - proofid_seq1, response=AvalancheProofVoteResponse.UNKNOWN), timeout=10) - break - except AssertionError: - retry -= 1 - - assert_greater_than(retry, 0) + with node.assert_debug_log([f"Avalanche stalled proof {proofid_seq1:0{64}x}"]): + self.wait_until(lambda: self.can_not_find_proof_in_poll( + proofid_seq1, response=AvalancheProofVoteResponse.UNKNOWN)) # Verify that proof_seq2 was not replaced assert proofid_seq2 in get_proof_ids(node)