Skip to content

Commit

Permalink
#387 - change number of active SONs via vote
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Dobromyslov committed Jun 13, 2022
1 parent b05c36b commit 53275c7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
3 changes: 3 additions & 0 deletions libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ void verify_account_votes( const database& db, const account_options& options )
FC_ASSERT( options.num_committee <= chain_params.maximum_committee_count,
"Voted for more committee members than currently allowed (${c})", ("c", chain_params.maximum_committee_count) );
FC_ASSERT( db.find_object(options.voting_account), "Invalid proxy account specified." );
FC_ASSERT( chain_params.extensions.value.maximum_son_count.valid() , "Invalid maximum son count" );
FC_ASSERT( options.num_son <= *chain_params.extensions.value.maximum_son_count,
"Voted for more sons than currently allowed (${c})", ("c", *chain_params.extensions.value.maximum_son_count) );

uint32_t max_vote_id = gpo.next_available_vote_id;
bool has_worker_votes = false;
Expand Down
26 changes: 23 additions & 3 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,21 @@ void database::pay_sons()
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
// Current requirement is that we have to pay every 24 hours, so the following check
if( dpo.son_budget.value > 0 && ((now - dpo.last_son_payout_time) >= fc::seconds(get_global_properties().parameters.son_pay_time()))) {
auto sons = sort_votable_objects<son_index>(get_global_properties().parameters.maximum_son_count());
assert( _son_count_histogram_buffer.size() > 0 );
const share_type stake_target = (_total_voting_stake-_son_count_histogram_buffer[0]) / 2;
/// accounts that vote for 0 or 1 son do not get to express an opinion on
/// the number of sons to have (they abstain and are non-voting accounts)
share_type stake_tally = 0;
size_t son_count = 0;
if( stake_target > 0 )
{
while( (son_count < _son_count_histogram_buffer.size() - 1)
&& (stake_tally <= stake_target) )
{
stake_tally += _son_count_histogram_buffer[++son_count];
}
}
auto sons = sort_votable_objects<son_index>(std::max(son_count*2+1, (size_t)get_chain_properties().immutable_parameters.min_son_count));
// After SON2 HF
uint64_t total_votes = 0;
for( const son_object& son : sons )
Expand Down Expand Up @@ -679,8 +693,7 @@ void database::update_active_sons()
}

const global_property_object& gpo = get_global_properties();
const chain_parameters& cp = gpo.parameters;
auto sons = sort_votable_objects<son_index>(cp.maximum_son_count());
auto sons = sort_votable_objects<son_index>(std::max(son_count*2+1, (size_t)get_chain_properties().immutable_parameters.min_son_count));

const auto& all_sons = get_index_type<son_index>().indices();

Expand Down Expand Up @@ -2041,6 +2054,13 @@ void update_son_params(database& db)
gpo.parameters.extensions.value.maximum_son_count = 7;
});
}
else
{
const auto& gpo = db.get_global_properties();
db.modify( gpo, []( global_property_object& gpo ) {
gpo.parameters.extensions.value.maximum_son_count = GRAPHENE_DEFAULT_MAX_SONS;
});
}
}

void database::perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props)
Expand Down
8 changes: 5 additions & 3 deletions tests/cli/son.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture )
global_property_object gpo;

gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count();
//! Set son number as 5 (as the begining son count)
unsigned int son_number = 5;

flat_map<sidechain_type, string> sidechain_public_keys;

Expand Down Expand Up @@ -400,7 +401,7 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture )
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
BOOST_CHECK(generate_maintenance_block());

BOOST_CHECK(gpo.active_sons.size() == gpo.parameters.maximum_son_count());
BOOST_CHECK(gpo.active_sons.size() == son_number);

} catch( fc::exception& e ) {
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
Expand Down Expand Up @@ -644,7 +645,8 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
global_property_object gpo;

gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count();
//! Set son number as 5 (as the begining son count)
unsigned int son_number = 5;

flat_map<sidechain_type, string> sidechain_public_keys;

Expand Down
7 changes: 2 additions & 5 deletions tests/tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,11 +1040,8 @@ BOOST_FIXTURE_TEST_CASE( hardfork_son2_time, database_fixture )

generate_blocks(HARDFORK_SON3_TIME);
// after this hardfork maximum son account should not reset the value
// on 7 after maintenance interval anymore. So change the global parameters
// and check the value after maintenance interval
db.modify(db.get_global_properties(), [](global_property_object& p) {
p.parameters.extensions.value.maximum_son_count = 13;
});
// on 7 after maintenance interval anymore. It must be GRAPHENE_DEFAULT_MAX_SONS
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maximum_son_count(), GRAPHENE_DEFAULT_MAX_SONS);

generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_block();
Expand Down

0 comments on commit 53275c7

Please sign in to comment.