Skip to content

Commit ec590f1

Browse files
committed
p2p, refactor: improve constness in ProtectEvictionCandidatesByRatio()
1 parent 4a19f50 commit ec590f1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& vEvict
903903
// longest uptime overall. This helps protect tor peers, which tend to be otherwise
904904
// disadvantaged under our eviction criteria.
905905
const size_t initial_size = vEvictionCandidates.size();
906-
size_t total_protect_size = initial_size / 2;
906+
const size_t total_protect_size{initial_size / 2};
907907
const size_t onion_protect_size = total_protect_size / 2;
908908

909909
if (onion_protect_size) {
@@ -926,8 +926,8 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& vEvict
926926

927927
// Calculate how many we removed, and update our total number of peers that
928928
// we want to protect based on uptime accordingly.
929-
total_protect_size -= initial_size - vEvictionCandidates.size();
930-
EraseLastKElements(vEvictionCandidates, ReverseCompareNodeTimeConnected, total_protect_size);
929+
const size_t remaining_to_protect{total_protect_size - (initial_size - vEvictionCandidates.size())};
930+
EraseLastKElements(vEvictionCandidates, ReverseCompareNodeTimeConnected, remaining_to_protect);
931931
}
932932

933933
[[nodiscard]] std::optional<NodeId> SelectNodeToEvict(std::vector<NodeEvictionCandidate>&& vEvictionCandidates)

0 commit comments

Comments
 (0)