Skip to content

Commit

Permalink
Fix half principal rep check (#3358)
Browse files Browse the repository at this point in the history
* Check for half principal even if the account is a duplicate

An account might be added that is not a half principal but might become
a half principal later. So we should check for half principal every time.

* Use have_half_rep() function rather than access variables directly

* Convert half_principal counter to boolean

The counting of half principals without tracking what is counted is
unreliable. Fortunately, we only care about whether a half principal
exists or not. So therefore convert the counter to a boolean so that
the counter does not get used when it is wrong.
  • Loading branch information
dsiganos committed Jun 30, 2021
1 parent 20fcdd4 commit 966180a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
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

0 comments on commit 966180a

Please sign in to comment.