Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Feb 24, 2024
1 parent 9041175 commit 4138889
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
22 changes: 11 additions & 11 deletions nano/node/repcrawler.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <nano/node/node.hpp>
#include <nano/node/repcrawler.hpp>

#include <boost/format.hpp>
#include <ranges>

nano::rep_crawler::rep_crawler (nano::rep_crawler_config const & config_a, nano::node & node_a) :
config{ config_a },
Expand Down Expand Up @@ -397,33 +397,33 @@ nano::uint128_t nano::rep_crawler::total_weight () const
return result;
}

std::vector<nano::representative> nano::rep_crawler::representatives (std::size_t count_a, nano::uint128_t const weight_a, boost::optional<decltype (nano::network_constants::protocol_version)> const & opt_version_min_a)
std::vector<nano::representative> nano::rep_crawler::representatives (std::size_t count, nano::uint128_t const minimum_weight, std::optional<decltype (nano::network_constants::protocol_version)> 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<nano::mutex> lock{ mutex };

std::multimap<nano::amount, rep_entry, std::greater<>> ordered;
for (const auto & i : reps.get<tag_account> ())
for (const auto & rep : reps.get<tag_account> ())
{
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<nano::representative> 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::representative> nano::rep_crawler::principal_representatives (std::size_t count_a, boost::optional<decltype (nano::network_constants::protocol_version)> const & opt_version_min_a)
std::vector<nano::representative> nano::rep_crawler::principal_representatives (std::size_t count, std::optional<decltype (nano::network_constants::protocol_version)> 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 */
Expand Down
11 changes: 7 additions & 4 deletions nano/node/repcrawler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<representative> representatives (std::size_t count_a = std::numeric_limits<std::size_t>::max (), nano::uint128_t weight_a = 0, boost::optional<decltype (nano::network_constants::protocol_version)> 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<representative> representatives (std::size_t count = std::numeric_limits<std::size_t>::max (), nano::uint128_t minimum_weight = 0, std::optional<decltype (nano::network_constants::protocol_version)> 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<representative> principal_representatives (std::size_t count_a = std::numeric_limits<std::size_t>::max (), boost::optional<decltype (nano::network_constants::protocol_version)> 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<representative> principal_representatives (std::size_t count = std::numeric_limits<std::size_t>::max (), std::optional<decltype (nano::network_constants::protocol_version)> const & minimum_protocol_version = {});

/** Total number of representatives */

std::size_t representative_count ();

private: // Dependencies
Expand Down

0 comments on commit 4138889

Please sign in to comment.