From c0af70faf4c91cca95e752eb53ec0cb6db425e67 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Mon, 28 Jun 2021 01:37:47 +0100 Subject: [PATCH 1/3] 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. --- nano/node/wallet.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 648e7d2855..c9c39b22c2 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1643,6 +1643,11 @@ bool nano::wallets::check_rep (nano::account const & account_a, nano::uint128_t lock = nano::unique_lock (reps_cache_mutex); } + if (weight >= half_principal_weight_a) + { + ++representatives.half_principal; + } + auto insert_result = representatives.accounts.insert (account_a); if (!insert_result.second) { @@ -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; } From e27e03f5df9a5c43a3634d204b1fcc1093b24541 Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Tue, 29 Jun 2021 01:51:14 +0100 Subject: [PATCH 2/3] Use have_half_rep() function rather than access variables directly --- nano/node/active_transactions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 2d2cd18e59..10f9c16a98 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -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 (); From b93917661dedf436f8c2c13dfbed30a7dc3c03cc Mon Sep 17 00:00:00 2001 From: Dimitrios Siganos Date: Tue, 29 Jun 2021 01:54:46 +0100 Subject: [PATCH 3/3] 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. --- nano/node/wallet.cpp | 2 +- nano/node/wallet.hpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index c9c39b22c2..d2d2e05289 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -1645,7 +1645,7 @@ bool nano::wallets::check_rep (nano::account const & account_a, nano::uint128_t if (weight >= half_principal_weight_a) { - ++representatives.half_principal; + representatives.half_principal = true; } auto insert_result = representatives.accounts.insert (account_a); diff --git a/nano/node/wallet.hpp b/nano/node/wallet.hpp index 644f772562..d0db01e762 100644 --- a/nano/node/wallet.hpp +++ b/nano/node/wallet.hpp @@ -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 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 { @@ -178,7 +178,7 @@ class wallet_representatives void clear () { voting = 0; - half_principal = 0; + half_principal = false; accounts.clear (); } };