Skip to content

Commit

Permalink
#387 change number of active sons
Browse files Browse the repository at this point in the history
  • Loading branch information
Vlad Dobromyslov authored and serkixenos committed Jun 14, 2022
1 parent 29189b3 commit 4b5eebc
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 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
29 changes: 26 additions & 3 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,26 @@ 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];
}
}
const vector<std::reference_wrapper<const son_object>> sons = [this, &son_count]{
if(head_block_time() >= HARDFORK_SON3_TIME)
return sort_votable_objects<son_index>(std::max(son_count*2+1, (size_t)get_chain_properties().immutable_parameters.min_son_count));
else
return sort_votable_objects<son_index>(get_global_properties().parameters.maximum_son_count());
}();
// After SON2 HF
uint64_t total_votes = 0;
for( const son_object& son : sons )
Expand Down Expand Up @@ -679,8 +698,12 @@ 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());
const vector<std::reference_wrapper<const son_object>> sons = [this, &son_count]{
if(head_block_time() >= HARDFORK_SON3_TIME)
return sort_votable_objects<son_index>(std::max(son_count*2+1, (size_t)get_chain_properties().immutable_parameters.min_son_count));
else
return sort_votable_objects<son_index>(get_global_properties().parameters.maximum_son_count());
}();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ namespace graphene { namespace chain {

} } // graphene::chain

FC_REFLECT(graphene::chain::account_options, (memo_key)(voting_account)(num_witness)(num_committee)(votes)(extensions))
FC_REFLECT(graphene::chain::account_options, (memo_key)(voting_account)(num_witness)(num_committee)(num_son)(votes)(extensions))
// FC_REFLECT_TYPENAME( graphene::chain::account_whitelist_operation::account_listing)
FC_REFLECT_ENUM( graphene::chain::account_whitelist_operation::account_listing,
(no_listing)(white_listed)(black_listed)(white_and_black_listed))
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 4b5eebc

Please sign in to comment.