From 9c73357d9717d15ce3505f1f4731e92322cd2a4b Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Thu, 24 Mar 2022 08:27:51 +0300 Subject: [PATCH] =?UTF-8?q?=E2=84=96328=20-=20Fix=20needed=5Fsons=20in=20a?= =?UTF-8?q?ccount=5Foptions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/chain/db_maint.cpp | 24 ++++++++++--------- .../graphene/chain/protocol/account.hpp | 3 ++- libraries/chain/protocol/account.cpp | 15 ++++++------ libraries/wallet/wallet.cpp | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 02afb7e2..66647569 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -2236,17 +2236,19 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g // same rationale as for witnesses d._committee_count_histogram_buffer[offset] += voting_stake; } - if( opinion_account.options.num_son <= props.parameters.maximum_son_count() ) - { - uint16_t offset = std::min(size_t(opinion_account.options.num_son/2), - d._son_count_histogram_buffer.size() - 1); - // votes for a number greater than maximum_son_count - // are turned into votes for maximum_son_count. - // - // in particular, this takes care of the case where a - // member was voting for a high number, then the - // parameter was lowered. - d._son_count_histogram_buffer[offset] += voting_stake; + for(const auto& num_sidechain_son : opinion_account.options.num_son) { + const auto& num_son = num_sidechain_son.second; + if (num_son <= props.parameters.maximum_son_count()) { + uint16_t offset = std::min(size_t(num_son / 2), + d._son_count_histogram_buffer.size() - 1); + // votes for a number greater than maximum_son_count + // are turned into votes for maximum_son_count. + // + // in particular, this takes care of the case where a + // member was voting for a high number, then the + // parameter was lowered. + d._son_count_histogram_buffer[offset] += voting_stake; + } } d._total_voting_stake += voting_stake; diff --git a/libraries/chain/include/graphene/chain/protocol/account.hpp b/libraries/chain/include/graphene/chain/protocol/account.hpp index 50ccb8ae..cbd39770 100644 --- a/libraries/chain/include/graphene/chain/protocol/account.hpp +++ b/libraries/chain/include/graphene/chain/protocol/account.hpp @@ -28,6 +28,7 @@ #include #include #include +#include namespace graphene { namespace chain { @@ -54,7 +55,7 @@ namespace graphene { namespace chain { uint16_t num_committee = 0; /// The number of active son members this account votes the blockchain should appoint /// Must not exceed the actual number of son members voted for in @ref votes - uint16_t num_son = 0; + flat_map num_son; /// This is the list of vote IDs this account votes for. The weight of these votes is determined by this /// account's balance of core asset. flat_set votes; diff --git a/libraries/chain/protocol/account.cpp b/libraries/chain/protocol/account.cpp index 435dfa57..178c447a 100644 --- a/libraries/chain/protocol/account.cpp +++ b/libraries/chain/protocol/account.cpp @@ -174,26 +174,25 @@ void account_options::validate() const { auto needed_witnesses = num_witness; auto needed_committee = num_committee; - auto needed_sons_bitcoin = num_son; - auto needed_sons_hive = num_son; + auto needed_sons = num_son; for( vote_id_type id : votes ) if( id.type() == vote_id_type::witness && needed_witnesses ) --needed_witnesses; else if ( id.type() == vote_id_type::committee && needed_committee ) --needed_committee; - else if ( id.type() == vote_id_type::son_bitcoin && needed_sons_bitcoin ) - --needed_sons_bitcoin; - else if ( id.type() == vote_id_type::son_hive && needed_sons_hive ) - --needed_sons_hive; + else if ( id.type() == vote_id_type::son_bitcoin && needed_sons[sidechain_type::bitcoin] ) + --needed_sons[sidechain_type::bitcoin]; + else if ( id.type() == vote_id_type::son_hive && needed_sons[sidechain_type::hive] ) + --needed_sons[sidechain_type::hive]; FC_ASSERT( needed_witnesses == 0, "May not specify fewer witnesses than the number voted for."); FC_ASSERT( needed_committee == 0, "May not specify fewer committee members than the number voted for."); - FC_ASSERT( needed_sons_bitcoin == 0, + FC_ASSERT( needed_sons[sidechain_type::bitcoin] == 0, "May not specify fewer Bitcoin SONs than the number voted for."); - FC_ASSERT( needed_sons_hive == 0, + FC_ASSERT( needed_sons[sidechain_type::hive] == 0, "May not specify fewer Hive SONs than the number voted for."); } diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 19719ff0..6d7af8d1 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2878,7 +2878,7 @@ public: if (!votes_removed) FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son)); } - voting_account_object.options.num_son = desired_number_of_sons; + voting_account_object.options.num_son[sidechain] = desired_number_of_sons; account_update_operation account_update_op; account_update_op.account = voting_account_object.id;