#339 refactor sidechain type #677

Merged
vampik merged 27 commits from feature/339-refactor-sidechain_type into feature/son-for-hive-voting 2022-04-12 16:39:05 +00:00
4 changed files with 23 additions and 21 deletions
Showing only changes of commit 9c73357d97 - Show all commits

View file

@ -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;

View file

@ -28,6 +28,7 @@
#include <graphene/chain/protocol/special_authority.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/protocol/vote.hpp>
#include <graphene/chain/sidechain_defs.hpp>
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<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
/// account's balance of core asset.
flat_set<vote_id_type> votes;

View file

@ -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.");
}

View file

@ -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;