@@ -960,6 +960,8 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
960960 }
961961 }
962962
963+ if (vEvictionCandidates.empty ()) return false ;
964+
963965 // Protect connections with certain characteristics
964966
965967 // Deterministically select 4 peers to protect by netgroup.
@@ -968,18 +970,21 @@ static bool AttemptToEvictConnection(bool fPreferNewConnection) {
968970 std::sort (vEvictionCandidates.begin (), vEvictionCandidates.end (), comparerNetGroupKeyed);
969971 vEvictionCandidates.erase (vEvictionCandidates.end () - std::min (4 , static_cast <int >(vEvictionCandidates.size ())), vEvictionCandidates.end ());
970972
973+ if (vEvictionCandidates.empty ()) return false ;
974+
971975 // Protect the 8 nodes with the best ping times.
972976 // An attacker cannot manipulate this metric without physically moving nodes closer to the target.
973977 std::sort (vEvictionCandidates.begin (), vEvictionCandidates.end (), ReverseCompareNodeMinPingTime);
974978 vEvictionCandidates.erase (vEvictionCandidates.end () - std::min (8 , static_cast <int >(vEvictionCandidates.size ())), vEvictionCandidates.end ());
975979
980+ if (vEvictionCandidates.empty ()) return false ;
981+
976982 // Protect the 64 nodes which have been connected the longest.
977983 // This replicates the existing implicit behavior.
978984 std::sort (vEvictionCandidates.begin (), vEvictionCandidates.end (), ReverseCompareNodeTimeConnected);
979- vEvictionCandidates.erase (vEvictionCandidates.end () - std::min ( static_cast <int >(vEvictionCandidates.size () / 2 ), static_cast < int >(vEvictionCandidates. size ()) ), vEvictionCandidates.end ());
985+ vEvictionCandidates.erase (vEvictionCandidates.end () - static_cast <int >(vEvictionCandidates.size () / 2 ), vEvictionCandidates.end ());
980986
981- if (vEvictionCandidates.empty ())
982- return false ;
987+ if (vEvictionCandidates.empty ()) return false ;
983988
984989 // Identify CNetAddr with the most connections
985990 CNetAddr naMostConnections;
0 commit comments