diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index 9a987e716a..f10f3f6467 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -1,7 +1,7 @@ #include #include -#include +#include nano::rep_crawler::rep_crawler (nano::rep_crawler_config const & config_a, nano::node & node_a) : config{ config_a }, @@ -397,33 +397,33 @@ nano::uint128_t nano::rep_crawler::total_weight () const return result; } -std::vector nano::rep_crawler::representatives (std::size_t count_a, nano::uint128_t const weight_a, boost::optional const & opt_version_min_a) +std::vector nano::rep_crawler::representatives (std::size_t count, nano::uint128_t const minimum_weight, std::optional const & minimum_protocol_version) { - auto const version_min = opt_version_min_a.value_or (node.network_params.network.protocol_version_min); + auto const version_min = minimum_protocol_version.value_or (node.network_params.network.protocol_version_min); nano::lock_guard lock{ mutex }; std::multimap> ordered; - for (const auto & i : reps.get ()) + for (const auto & rep : reps.get ()) { - auto weight = node.ledger.weight (i.account); - if (weight > weight_a && i.channel->get_network_version () >= version_min) + auto weight = node.ledger.weight (rep.account); + if (weight >= minimum_weight && rep.channel->get_network_version () >= version_min) { - ordered.insert ({ nano::amount{ weight }, i }); + ordered.insert ({ nano::amount{ weight }, rep }); } } std::vector result; - for (auto i = ordered.begin (), n = ordered.end (); i != n && result.size () < count_a; ++i) + for (auto const & [weight, rep] : ordered | std::views::take (count)) { - result.push_back ({ i->second.account, i->second.channel }); + result.push_back ({ rep.account, rep.channel }); } return result; } -std::vector nano::rep_crawler::principal_representatives (std::size_t count_a, boost::optional const & opt_version_min_a) +std::vector nano::rep_crawler::principal_representatives (std::size_t count, std::optional const & minimum_protocol_version) { - return representatives (count_a, node.minimum_principal_weight (), opt_version_min_a); + return representatives (count, node.minimum_principal_weight (), minimum_protocol_version); } /** Total number of representatives */ diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index 3a8ec3ab3e..48c8bda3a0 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -79,13 +79,16 @@ class rep_crawler final /** Get total available weight from representatives */ nano::uint128_t total_weight () const; - /** Request a list of the top \p count_a known representatives in descending order of weight, with at least \p weight_a voting weight, and optionally with a minimum version \p opt_version_min_a */ - std::vector representatives (std::size_t count_a = std::numeric_limits::max (), nano::uint128_t weight_a = 0, boost::optional const & opt_version_min_a = boost::none); + /** Request a list of the top \p count known representatives in descending order of weight, with at least \p weight_a voting weight, and optionally with a minimum version \p minimum_protocol_version + */ + std::vector representatives (std::size_t count = std::numeric_limits::max (), nano::uint128_t minimum_weight = 0, std::optional const & minimum_protocol_version = {}); - /** Request a list of the top \p count_a known principal representatives in descending order of weight, optionally with a minimum version \p opt_version_min_a */ - std::vector principal_representatives (std::size_t count_a = std::numeric_limits::max (), boost::optional const & opt_version_min_a = boost::none); + /** Request a list of the top \p count known principal representatives in descending order of weight, optionally with a minimum version \p minimum_protocol_version + */ + std::vector principal_representatives (std::size_t count = std::numeric_limits::max (), std::optional const & minimum_protocol_version = {}); /** Total number of representatives */ + std::size_t representative_count (); private: // Dependencies