diff --git a/src/avalanche/peermanager.cpp b/src/avalanche/peermanager.cpp --- a/src/avalanche/peermanager.cpp +++ b/src/avalanche/peermanager.cpp @@ -1066,11 +1066,8 @@ return std::nullopt; } - size_t total_remotes{0}; double total_score{0}; - size_t present_remotes{0}; double present_score{0}; - size_t missing_remotes{0}; double missing_score{0}; for (auto it = begin; it != end; it++) { @@ -1090,24 +1087,19 @@ const double score = double(pit->getScore()) / pit->node_count; - ++total_remotes; total_score += score; if (it->present) { - ++present_remotes; present_score += score; } else { - ++missing_remotes; missing_score += score; } } - if ((double(present_remotes) / total_remotes > 0.8) && - (present_score / total_score > 0.8)) { + if (present_score / total_score > 0.8) { return std::make_optional(true); } - if ((double(missing_remotes) / total_remotes > 0.8) && - (missing_score / total_score > 0.8)) { + if (missing_score / total_score > 0.8) { return std::make_optional(false); } diff --git a/src/avalanche/test/peermanager_tests.cpp b/src/avalanche/test/peermanager_tests.cpp --- a/src/avalanche/test/peermanager_tests.cpp +++ b/src/avalanche/test/peermanager_tests.cpp @@ -2577,7 +2577,7 @@ !TestPeerManager::getRemotePresenceStatus(pm, ProofId(uint256::ZERO)) .has_value()); - // 50/50 on the remotes + // 50/50 of the stakes for (NodeId nodeid = 0; nodeid < 10; nodeid++) { auto proof = buildRandomProof(active_chainstate, MIN_VALID_PROOF_SCORE); BOOST_CHECK(pm.registerProof(proof)); @@ -2590,7 +2590,7 @@ !TestPeerManager::getRemotePresenceStatus(pm, ProofId(uint256::ZERO)) .has_value()); - // 90% on the remotes + // 90% of the stakes BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), 0, false)); for (NodeId nodeid = 1; nodeid < 10; nodeid++) { BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), nodeid, true)); @@ -2599,7 +2599,7 @@ TestPeerManager::getRemotePresenceStatus(pm, ProofId(uint256::ZERO)) .value()); - // 10% on the remotes + // 10% of the stakes BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), 0, true)); for (NodeId nodeid = 1; nodeid < 10; nodeid++) { BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), nodeid, false)); @@ -2615,23 +2615,23 @@ // Update the node's proof BOOST_CHECK(pm.addNode(0, bigProof->getId())); - // 90% on the remotes, but not enough stakes => inconclusive + // 90% of the remotes, but < 10% of the stakes => absent BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), 0, false)); for (NodeId nodeid = 1; nodeid < 10; nodeid++) { BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), nodeid, true)); } BOOST_CHECK( !TestPeerManager::getRemotePresenceStatus(pm, ProofId(uint256::ZERO)) - .has_value()); + .value()); - // 10% on the remotes, but not enough stakes => inconclusive + // 10% of the remotes, but > 90% of the stakes => present BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), 0, true)); for (NodeId nodeid = 1; nodeid < 10; nodeid++) { BOOST_CHECK(pm.saveRemoteProof(ProofId(uint256::ZERO), nodeid, false)); } BOOST_CHECK( - !TestPeerManager::getRemotePresenceStatus(pm, ProofId(uint256::ZERO)) - .has_value()); + TestPeerManager::getRemotePresenceStatus(pm, ProofId(uint256::ZERO)) + .value()); TestPeerManager::clearPeers(pm);