№328 - Fix needed_sons in account_options

This commit is contained in:
Vlad Dobromyslov 2022-03-24 08:27:51 +03:00
parent eec19a350b
commit 9c73357d97
4 changed files with 23 additions and 21 deletions

View file

@ -2236,17 +2236,19 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
// same rationale as for witnesses // same rationale as for witnesses
d._committee_count_histogram_buffer[offset] += voting_stake; d._committee_count_histogram_buffer[offset] += voting_stake;
} }
if( opinion_account.options.num_son <= props.parameters.maximum_son_count() ) for(const auto& num_sidechain_son : opinion_account.options.num_son) {
{ const auto& num_son = num_sidechain_son.second;
uint16_t offset = std::min(size_t(opinion_account.options.num_son/2), if (num_son <= props.parameters.maximum_son_count()) {
d._son_count_histogram_buffer.size() - 1); uint16_t offset = std::min(size_t(num_son / 2),
// votes for a number greater than maximum_son_count d._son_count_histogram_buffer.size() - 1);
// are turned into votes for maximum_son_count. // 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 // in particular, this takes care of the case where a
// parameter was lowered. // member was voting for a high number, then the
d._son_count_histogram_buffer[offset] += voting_stake; // parameter was lowered.
d._son_count_histogram_buffer[offset] += voting_stake;
}
} }
d._total_voting_stake += voting_stake; d._total_voting_stake += voting_stake;

View file

@ -28,6 +28,7 @@
#include <graphene/chain/protocol/special_authority.hpp> #include <graphene/chain/protocol/special_authority.hpp>
#include <graphene/chain/protocol/types.hpp> #include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/protocol/vote.hpp> #include <graphene/chain/protocol/vote.hpp>
#include <graphene/chain/sidechain_defs.hpp>
namespace graphene { namespace chain { namespace graphene { namespace chain {
@ -54,7 +55,7 @@ namespace graphene { namespace chain {
uint16_t num_committee = 0; uint16_t num_committee = 0;
/// The number of active son members this account votes the blockchain should appoint /// 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 /// Must not exceed the actual number of son members voted for in @ref votes
uint16_t num_son = 0; flat_map<sidechain_type, uint16_t> num_son;
/// This is the list of vote IDs this account votes for. The weight of these votes is determined by this /// 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. /// account's balance of core asset.
flat_set<vote_id_type> votes; flat_set<vote_id_type> votes;

View file

@ -174,26 +174,25 @@ void account_options::validate() const
{ {
auto needed_witnesses = num_witness; auto needed_witnesses = num_witness;
auto needed_committee = num_committee; auto needed_committee = num_committee;
auto needed_sons_bitcoin = num_son; auto needed_sons = num_son;
auto needed_sons_hive = num_son;
for( vote_id_type id : votes ) for( vote_id_type id : votes )
if( id.type() == vote_id_type::witness && needed_witnesses ) if( id.type() == vote_id_type::witness && needed_witnesses )
--needed_witnesses; --needed_witnesses;
else if ( id.type() == vote_id_type::committee && needed_committee ) else if ( id.type() == vote_id_type::committee && needed_committee )
--needed_committee; --needed_committee;
else if ( id.type() == vote_id_type::son_bitcoin && needed_sons_bitcoin ) else if ( id.type() == vote_id_type::son_bitcoin && needed_sons[sidechain_type::bitcoin] )
--needed_sons_bitcoin; --needed_sons[sidechain_type::bitcoin];
else if ( id.type() == vote_id_type::son_hive && needed_sons_hive ) else if ( id.type() == vote_id_type::son_hive && needed_sons[sidechain_type::hive] )
--needed_sons_hive; --needed_sons[sidechain_type::hive];
FC_ASSERT( needed_witnesses == 0, FC_ASSERT( needed_witnesses == 0,
"May not specify fewer witnesses than the number voted for."); "May not specify fewer witnesses than the number voted for.");
FC_ASSERT( needed_committee == 0, FC_ASSERT( needed_committee == 0,
"May not specify fewer committee members than the number voted for."); "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."); "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."); "May not specify fewer Hive SONs than the number voted for.");
} }

View file

@ -2878,7 +2878,7 @@ public:
if (!votes_removed) if (!votes_removed)
FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son)); 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_operation account_update_op;
account_update_op.account = voting_account_object.id; account_update_op.account = voting_account_object.id;