diff --git a/src/avalanche/processor.cpp b/src/avalanche/processor.cpp --- a/src/avalanche/processor.cpp +++ b/src/avalanche/processor.cpp @@ -936,6 +936,13 @@ bool Processor::isWorthPolling(const ProofRef &proof) const { AssertLockHeld(cs_peerManager); + if (!gArgs.GetBoolArg("-enableavalancheproofreplacement", + AVALANCHE_DEFAULT_PROOF_REPLACEMENT_ENABLED)) { + // If proof replacement is not enabled there is no point dealing + // with proof polling, so we're done. + return false; + } + const ProofId &proofid = proof->getId(); // No point polling orphans or discarded proofs diff --git a/src/avalanche/test/processor_tests.cpp b/src/avalanche/test/processor_tests.cpp --- a/src/avalanche/test/processor_tests.cpp +++ b/src/avalanche/test/processor_tests.cpp @@ -113,6 +113,7 @@ BOOST_CHECK(m_processor); gArgs.ForceSetArg("-avaproofstakeutxoconfirmations", "1"); + gArgs.ForceSetArg("-enableavalancheproofreplacement", "1"); } ~AvalancheTestingSetup() { @@ -120,6 +121,7 @@ SyncWithValidationInterfaceQueue(); gArgs.ClearForcedArg("-avaproofstakeutxoconfirmations"); + gArgs.ClearForcedArg("-enableavalancheproofreplacement"); } CNode *ConnectNode(ServiceFlags nServices) { @@ -1103,16 +1105,34 @@ BOOST_CHECK_EQUAL(invs.front().hash, lastProofId); } - // The score is not high enough to get polled - auto proof = addProofToReconcile(--score); - auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); - for (auto &inv : invs) { - BOOST_CHECK_NE(inv.hash, proof->getId()); + { + // The score is not high enough to get polled + auto proof = addProofToReconcile(--score); + auto invs = AvalancheTest::getInvsForNextPoll(*m_processor); + for (auto &inv : invs) { + BOOST_CHECK_NE(inv.hash, proof->getId()); + } + } + + { + // If proof replacement is not enabled there is no point polling for the + // proof. + auto proof = buildRandomProof(MIN_VALID_PROOF_SCORE); + m_processor->withPeerManager([&](avalanche::PeerManager &pm) { + BOOST_CHECK(pm.registerProof(proof)); + }); + + gArgs.ForceSetArg("-enableavalancheproofreplacement", "0"); + BOOST_CHECK(!m_processor->addProofToReconcile(proof)); + + gArgs.ForceSetArg("-enableavalancheproofreplacement", "1"); + BOOST_CHECK(m_processor->addProofToReconcile(proof)); + + gArgs.ClearForcedArg("-enableavalancheproofreplacement"); } } BOOST_AUTO_TEST_CASE(proof_record) { - gArgs.ForceSetArg("-enableavalancheproofreplacement", "1"); gArgs.ForceSetArg("-avalancheconflictingproofcooldown", "0"); BOOST_CHECK(!m_processor->isAccepted(nullptr)); @@ -1188,7 +1208,6 @@ BOOST_CHECK_EQUAL(m_processor->getConfidence(orphanProof), -1); gArgs.ClearForcedArg("-avalancheconflictingproofcooldown"); - gArgs.ClearForcedArg("-enableavalancheproofreplacement"); } BOOST_AUTO_TEST_CASE(quorum_detection) { diff --git a/src/net_processing.cpp b/src/net_processing.cpp --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -7092,21 +7092,13 @@ return false; } - if (!gArgs.GetBoolArg("-enableavalancheproofreplacement", - AVALANCHE_DEFAULT_PROOF_REPLACEMENT_ENABLED)) { - // If proof replacement is not enabled there is no point dealing - // with proof polling, so we're done. - return true; - } - - if (state.IsValid() || - state.GetResult() == avalanche::ProofRegistrationResult::CONFLICTING) { - g_avalanche->addProofToReconcile(proof); - return true; + if (!g_avalanche->addProofToReconcile(proof)) { + LogPrint(BCLog::AVALANCHE, + "Not polling the avalanche proof (%s): peer=%d, proofid %s\n", + state.IsValid() ? "not-worth-polling" + : state.GetRejectReason(), + nodeid, proofid.ToString()); } - LogPrint(BCLog::AVALANCHE, - "Not polling the avalanche proof (%s): peer=%d, proofid %s\n", - state.GetRejectReason(), nodeid, proofid.ToString()); return true; } 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 @@ -192,6 +192,16 @@ peer.send_avaproof(avalanche_proof_from_hex(no_stake)) peer.wait_for_disconnect() + self.log.info("We don't poll for proofs if replacement is disabled") + + self.restart_node( + 0, + extra_args=self.extra_args[0] + + ['-enableavalancheproofreplacement=0']) + peer = get_ava_p2p_interface(node) + with node.assert_debug_log(["Not polling the avalanche proof (not-worth-polling)"]): + peer.send_avaproof(avalanche_proof_from_hex(proof_seq10)) + def update_tests(self, node): # Restart the node to get rid of in-flight requests self.restart_node(0)