Skip to content

Commit

Permalink
Apply Wesley review
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiySW committed Oct 17, 2019
1 parent cd0d3a7 commit 547bc9b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
29 changes: 13 additions & 16 deletions nano/node/bootstrap/bootstrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,29 +648,26 @@ void nano::bootstrap_attempt::confirm_frontiers (nano::unique_lock<std::mutex> &
auto representatives_copy (representatives);
nano::uint128_t total_weight (0);
// Select random peers from bottom 50% of principal representatives
if (!representatives.empty ())
if (representatives.size () > 1)
{
if (representatives.size () > 1)
std::reverse (representatives.begin (), representatives.end ());
representatives.resize (representatives.size () / 2);
for (auto i = static_cast<CryptoPP::word32> (representatives.size () - 1); i > 0; --i)
{
std::reverse (representatives.begin (), representatives.end ());
representatives.resize (representatives.size () / 2, nano::representative{ 0, 0, nullptr });
for (auto i = static_cast<CryptoPP::word32> (representatives.size () - 1); i > 0; --i)
{
auto k = nano::random_pool::generate_word32 (0, i);
std::swap (representatives[i], representatives[k]);
}
if (representatives.size () > reps_limit)
{
representatives.resize (reps_limit, nano::representative{ 0, 0, nullptr });
}
auto k = nano::random_pool::generate_word32 (0, i);
std::swap (representatives[i], representatives[k]);
}
for (auto const & rep : representatives)
if (representatives.size () > reps_limit)
{
total_weight += rep.weight.number ();
representatives.resize (reps_limit);
}
}
for (auto const & rep : representatives)
{
total_weight += rep.weight.number ();
}
// Select peers with total 25% of reps stake from top 50% of principal representatives
representatives_copy.resize (representatives_copy.size () / 2, nano::representative{ 0, 0, nullptr });
representatives_copy.resize (representatives_copy.size () / 2);
while (total_weight < reps_weight / 4) // 25%
{
auto k = nano::random_pool::generate_word32 (0, static_cast<CryptoPP::word32> (representatives_copy.size () - 1));
Expand Down
1 change: 1 addition & 0 deletions nano/node/repcrawler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class node;
class representative
{
public:
representative () = default;
representative (nano::account account_a, nano::amount weight_a, std::shared_ptr<nano::transport::channel> channel_a) :
account (account_a), weight (weight_a), channel (channel_a)
{
Expand Down

0 comments on commit 547bc9b

Please sign in to comment.