Skip to content

Commit e1ee36d

Browse files
jonatackvasild
authored andcommitted
p2p: iterate eviction protection only on networks having candidates
in ProtectEvictionCandidatesByRatio(). Thank you to Vasil Dimov, whose suggestions during a post-merge discussion about PR 21261 reminded me that I had done this in earlier versions of the PR, e.g. commits like ef411cd2. Co-authored-by: Vasil Dimov <[email protected]>
1 parent 1c53554 commit e1ee36d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/net.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,10 @@ void ProtectEvictionCandidatesByRatio(std::vector<NodeEvictionCandidate>& evicti
936936
const size_t max_protect_by_network{total_protect_size / 2};
937937
size_t num_protected{0};
938938

939-
while (num_protected < max_protect_by_network) {
939+
// Count the number of disadvantaged networks from which we have peers to protect.
940+
auto num_networks = std::count_if(networks.begin(), networks.end(), [](const Net& n) { return n.count; });
941+
942+
while (num_networks != 0 && num_protected < max_protect_by_network) {
940943
const size_t disadvantaged_to_protect{max_protect_by_network - num_protected};
941944
const size_t protect_per_network{
942945
std::max(disadvantaged_to_protect / networks.size(), static_cast<size_t>(1))};

0 commit comments

Comments
 (0)