The function rep wallets::rep_check() did not check for duplicates when adding a voting representative and the count of voting representatives could therefore be much bigger than the reality.
This commit is contained in:
parent
cb34acc3aa
commit
6ee3cee121
1 changed files with 25 additions and 16 deletions
|
|
@ -1630,24 +1630,33 @@ nano::wallet_representatives nano::wallets::reps () const
|
||||||
|
|
||||||
bool nano::wallets::check_rep (nano::account const & account_a, nano::uint128_t const & half_principal_weight_a, const bool acquire_lock_a)
|
bool nano::wallets::check_rep (nano::account const & account_a, nano::uint128_t const & half_principal_weight_a, const bool acquire_lock_a)
|
||||||
{
|
{
|
||||||
bool result (false);
|
auto weight = node.ledger.weight (account_a);
|
||||||
auto weight (node.ledger.weight (account_a));
|
|
||||||
if (weight >= node.config.vote_minimum.number ())
|
if (weight < node.config.vote_minimum.number ())
|
||||||
{
|
{
|
||||||
nano::unique_lock<nano::mutex> lock;
|
return false; // account not a representative
|
||||||
if (acquire_lock_a)
|
|
||||||
{
|
|
||||||
lock = nano::unique_lock<nano::mutex> (reps_cache_mutex);
|
|
||||||
}
|
|
||||||
result = true;
|
|
||||||
representatives.accounts.insert (account_a);
|
|
||||||
++representatives.voting;
|
|
||||||
if (weight >= half_principal_weight_a)
|
|
||||||
{
|
|
||||||
++representatives.half_principal;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
nano::unique_lock<nano::mutex> lock;
|
||||||
|
if (acquire_lock_a)
|
||||||
|
{
|
||||||
|
lock = nano::unique_lock<nano::mutex> (reps_cache_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto insert_result = representatives.accounts.insert (account_a);
|
||||||
|
if (!insert_result.second)
|
||||||
|
{
|
||||||
|
return false; // account already exists
|
||||||
|
}
|
||||||
|
|
||||||
|
++representatives.voting;
|
||||||
|
|
||||||
|
if (weight >= half_principal_weight_a)
|
||||||
|
{
|
||||||
|
++representatives.half_principal;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nano::wallets::compute_reps ()
|
void nano::wallets::compute_reps ()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue