Skip to content

Commit

Permalink
#328 son voting test
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Dobromyslov authored and serkixenos committed Mar 28, 2022
1 parent d39f3f3 commit 99d10b9
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 99 deletions.
35 changes: 19 additions & 16 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,12 @@ void database::update_active_sons()
});
}
modify( son, [local_vote_buffer_ref]( son_object& obj ){
//! FIXME - only bitcoin_vote_id ???
obj.total_votes = local_vote_buffer_ref[obj.get_bitcoin_vote_id()];
if(obj.status == son_status::request_maintenance)
obj.status = son_status::in_maintenance;
});
for(const auto& sidechain_vote_id : obj.sidechain_vote_ids ){
obj.total_votes[sidechain_vote_id.first] = local_vote_buffer_ref[sidechain_vote_id.second];
}
if(obj.status == son_status::request_maintenance)
obj.status = son_status::in_maintenance;
});
}

// Update SON authority
Expand Down Expand Up @@ -2235,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;
Expand Down
3 changes: 2 additions & 1 deletion libraries/chain/include/graphene/chain/protocol/account.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/son_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace graphene { namespace chain {

account_id_type son_account;
flat_map<sidechain_type, vote_id_type> sidechain_vote_ids;
uint64_t total_votes = 0;
flat_map<sidechain_type, uint64_t> total_votes;
string url;
vesting_balance_id_type deposit;
public_key_type signing_key;
Expand Down
15 changes: 7 additions & 8 deletions libraries/chain/protocol/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2878,7 +2878,7 @@ class wallet_api_impl
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;
Expand Down
Loading

0 comments on commit 99d10b9

Please sign in to comment.