diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index bef80ca378..35e1cfdf88 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -268,7 +268,7 @@ void nano::active_elections::request_confirm (nano::unique_lock & l lock_a.unlock (); nano::confirmation_solicitor solicitor (node.network, node.config); - solicitor.prepare (node.rep_crawler.principal_representatives (std::numeric_limits::max ())); + solicitor.prepare (node.rep_crawler.principal_representatives (std::numeric_limits::max ())); std::size_t unconfirmed_count_l (0); nano::timer elapsed (nano::timer_state::started); @@ -652,4 +652,4 @@ nano::stat::type nano::to_stat_type (nano::election_state state) nano::stat::detail nano::to_stat_detail (nano::election_status_type type) { return nano::enum_util::cast (type); -} \ No newline at end of file +} diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index f6cca66b5f..531ec13771 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -435,8 +435,9 @@ nano::uint128_t nano::rep_crawler::total_weight () const return result; } -std::vector nano::rep_crawler::representatives (std::size_t count, nano::uint128_t const minimum_weight, std::optional const & minimum_protocol_version) +std::vector nano::rep_crawler::representatives (std::ptrdiff_t count, nano::uint128_t const minimum_weight, std::optional const & minimum_protocol_version) { + debug_assert (count >= 0); auto const version_min = minimum_protocol_version.value_or (node.network_params.network.protocol_version_min); nano::lock_guard lock{ mutex }; @@ -452,15 +453,16 @@ std::vector nano::rep_crawler::representatives (std::size_ } std::vector result; - for (auto const & [weight, rep] : ordered | std::views::take (count)) + for (auto const & [weight, rep] : ordered | std::views::take (/* Signed type*/ count)) { result.push_back ({ rep.account, rep.channel }); } return result; } -std::vector nano::rep_crawler::principal_representatives (std::size_t count, std::optional const & minimum_protocol_version) +std::vector nano::rep_crawler::principal_representatives (std::ptrdiff_t count, std::optional const & minimum_protocol_version) { + debug_assert (count >= 0); return representatives (count, node.minimum_principal_weight (), minimum_protocol_version); } diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index 5f9bbf7f7f..c5a1b4257a 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -76,11 +76,11 @@ class rep_crawler final /** 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 = {}); + std::vector representatives (std::ptrdiff_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 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 = {}); + std::vector principal_representatives (std::ptrdiff_t count = std::numeric_limits::max (), std::optional const & minimum_protocol_version = {}); /** Total number of representatives */ std::size_t representative_count ();