Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix half principal rep check #3358

Merged
merged 3 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ nano::frontiers_confirmation_info nano::active_transactions::get_frontiers_confi
// Limit maximum count of elections to start
auto rep_counts (node.wallets.reps ());
bool representative (node.config.enable_voting && rep_counts.voting > 0);
bool half_princpal_representative (representative && rep_counts.half_principal > 0);
bool half_princpal_representative (representative && rep_counts.have_half_rep ());
/* Check less frequently for regular nodes in auto mode */
bool agressive_mode (half_princpal_representative || node.config.frontiers_confirmation == nano::frontiers_confirmation_mode::always);
auto is_dev_network = node.network_params.network.is_dev_network ();
Expand Down
10 changes: 5 additions & 5 deletions nano/node/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1643,6 +1643,11 @@ bool nano::wallets::check_rep (nano::account const & account_a, nano::uint128_t
lock = nano::unique_lock<nano::mutex> (reps_cache_mutex);
}

if (weight >= half_principal_weight_a)
{
representatives.half_principal = true;
}

auto insert_result = representatives.accounts.insert (account_a);
if (!insert_result.second)
{
Expand All @@ -1651,11 +1656,6 @@ bool nano::wallets::check_rep (nano::account const & account_a, nano::uint128_t

++representatives.voting;

if (weight >= half_principal_weight_a)
{
++representatives.half_principal;
}

return true;
}

Expand Down
6 changes: 3 additions & 3 deletions nano/node/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@ class wallet_representatives
{
public:
uint64_t voting{ 0 }; // Number of representatives with at least the configured minimum voting weight
uint64_t half_principal{ 0 }; // Number of representatives with at least 50% of principal representative requirements
bool half_principal{ false }; // has representatives with at least 50% of principal representative requirements
std::unordered_set<nano::account> accounts; // Representatives with at least the configured minimum voting weight
bool have_half_rep () const
{
return half_principal > 0;
return half_principal;
}
bool exists (nano::account const & rep_a) const
{
Expand All @@ -178,7 +178,7 @@ class wallet_representatives
void clear ()
{
voting = 0;
half_principal = 0;
half_principal = false;
accounts.clear ();
}
};
Expand Down