Skip to content

Commit

Permalink
hotfix - son max count fix (#389)
Browse files Browse the repository at this point in the history
* hotfix - son max count fix

* init variables
  • Loading branch information
sierra19XX authored Oct 12, 2020
1 parent b31b402 commit a20be87
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
12 changes: 9 additions & 3 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,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>(cp.maximum_son_count());

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

Expand Down Expand Up @@ -1981,7 +1981,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
d._vote_tally_buffer.resize(props.next_available_vote_id);
d._witness_count_histogram_buffer.resize(props.parameters.maximum_witness_count / 2 + 1);
d._committee_count_histogram_buffer.resize(props.parameters.maximum_committee_count / 2 + 1);
d._son_count_histogram_buffer.resize(props.parameters.maximum_son_count / 2 + 1);
d._son_count_histogram_buffer.resize(props.parameters.maximum_son_count() / 2 + 1);
d._total_voting_stake = 0;

auto balance_type = vesting_balance_type::normal;
Expand Down Expand Up @@ -2093,7 +2093,7 @@ 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 )
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);
Expand Down Expand Up @@ -2183,6 +2183,12 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
p.pending_parameters->extensions.value.son_down_time = p.parameters.extensions.value.son_down_time;
if( !p.pending_parameters->extensions.value.son_bitcoin_min_tx_confirmations.valid() )
p.pending_parameters->extensions.value.son_bitcoin_min_tx_confirmations = p.parameters.extensions.value.son_bitcoin_min_tx_confirmations;
if( !p.pending_parameters->extensions.value.son_account.valid() )
p.pending_parameters->extensions.value.son_account = p.parameters.extensions.value.son_account;
if( !p.pending_parameters->extensions.value.btc_asset.valid() )
p.pending_parameters->extensions.value.btc_asset = p.parameters.extensions.value.btc_asset;
if( !p.pending_parameters->extensions.value.maximum_son_count.valid() )
p.pending_parameters->extensions.value.maximum_son_count = p.parameters.extensions.value.maximum_son_count;
p.parameters = std::move(*p.pending_parameters);
p.pending_parameters.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ FC_REFLECT(graphene::chain::budget_record,
(total_budget)
(witness_budget)
(worker_budget)
(son_budget)
(leftover_worker_funds)
(leftover_son_funds)
(supply_delta)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ namespace graphene { namespace chain {
optional < uint32_t > son_heartbeat_frequency = SON_HEARTBEAT_FREQUENCY;
optional < uint32_t > son_down_time = SON_DOWN_TIME;
optional < uint16_t > son_bitcoin_min_tx_confirmations = SON_BITCOIN_MIN_TX_CONFIRMATIONS;

optional < account_id_type > son_account;
optional < asset_id_type > btc_asset;
optional < account_id_type > son_account = GRAPHENE_NULL_ACCOUNT;
optional < asset_id_type > btc_asset = asset_id_type();
optional < uint16_t > maximum_son_count = GRAPHENE_DEFAULT_MAX_SONS; ///< maximum number of active SONS
};

struct chain_parameters
Expand All @@ -86,7 +86,6 @@ namespace graphene { namespace chain {
uint8_t maximum_asset_feed_publishers = GRAPHENE_DEFAULT_MAX_ASSET_FEED_PUBLISHERS; ///< the maximum number of feed publishers for a given asset
uint16_t maximum_witness_count = GRAPHENE_DEFAULT_MAX_WITNESSES; ///< maximum number of active witnesses
uint16_t maximum_committee_count = GRAPHENE_DEFAULT_MAX_COMMITTEE; ///< maximum number of active committee_members
uint16_t maximum_son_count = GRAPHENE_DEFAULT_MAX_SONS; ///< maximum number of active SONS
uint16_t maximum_authority_membership = GRAPHENE_DEFAULT_MAX_AUTHORITY_MEMBERSHIP; ///< largest number of keys/accounts an authority can have
uint16_t reserve_percent_of_fee = GRAPHENE_DEFAULT_BURN_PERCENT_OF_FEE; ///< the percentage of the network's allocation of a fee that is taken out of circulation
uint16_t network_percent_of_fee = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; ///< percent of transaction fees paid to network
Expand Down Expand Up @@ -205,6 +204,9 @@ namespace graphene { namespace chain {
inline asset_id_type btc_asset() const {
return extensions.value.btc_asset.valid() ? *extensions.value.btc_asset : asset_id_type();
}
inline uint16_t maximum_son_count()const {
return extensions.value.maximum_son_count.valid() ? *extensions.value.maximum_son_count : GRAPHENE_DEFAULT_MAX_SONS;
}
};

} } // graphene::chain
Expand Down Expand Up @@ -237,6 +239,7 @@ FC_REFLECT( graphene::chain::parameter_extension,
(son_bitcoin_min_tx_confirmations)
(son_account)
(btc_asset)
(maximum_son_count)
)

FC_REFLECT( graphene::chain::chain_parameters,
Expand All @@ -253,7 +256,6 @@ FC_REFLECT( graphene::chain::chain_parameters,
(maximum_asset_feed_publishers)
(maximum_witness_count)
(maximum_committee_count)
(maximum_son_count)
(maximum_authority_membership)
(reserve_percent_of_fee)
(network_percent_of_fee)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ typedef generic_far_future_witness_scheduler<
typedef generic_witness_scheduler<
/* WitnessID = */ son_id_type,
/* RNG = */ witness_scheduler_rng,
/* CountType = */ decltype( chain_parameters::maximum_son_count ),
/* CountType = */ decltype( chain_parameters::extensions.value.maximum_son_count )::value_type,
/* OffsetType = */ uint32_t,
/* debug = */ true
> son_scheduler;

typedef generic_far_future_witness_scheduler<
/* WitnessID = */ son_id_type,
/* RNG = */ witness_scheduler_rng,
/* CountType = */ decltype( chain_parameters::maximum_son_count ),
/* CountType = */ decltype( chain_parameters::extensions.value.maximum_son_count )::value_type,
/* OffsetType = */ uint32_t,
/* debug = */ true
> far_future_son_scheduler;
Expand Down
4 changes: 2 additions & 2 deletions programs/witness_node/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@
"maximum_asset_feed_publishers": 10,
"maximum_witness_count": 1001,
"maximum_committee_count": 1001,
"maximum_son_count": 15,
"maximum_authority_membership": 10,
"reserve_percent_of_fee": 2000,
"network_percent_of_fee": 2000,
Expand Down Expand Up @@ -392,7 +391,8 @@
"son_pay_time": 86400,
"son_deregister_time": 43200,
"son_heartbeat_frequency": 180,
"son_down_time": 360
"son_down_time": 360,
"maximum_son_count": 15
}
},
"initial_bts_accounts": [],
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/son.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ 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;
unsigned int son_number = gpo.parameters.maximum_son_count();

flat_map<sidechain_type, string> sidechain_public_keys;

Expand Down Expand Up @@ -578,7 +578,7 @@ 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;
unsigned int son_number = gpo.parameters.maximum_son_count();

flat_map<sidechain_type, string> sidechain_public_keys;

Expand Down Expand Up @@ -645,7 +645,7 @@ BOOST_AUTO_TEST_CASE( maintenance_test )

global_property_object gpo;
gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count;
unsigned int son_number = gpo.parameters.maximum_son_count();

flat_map<sidechain_type, string> sidechain_public_keys;

Expand Down

0 comments on commit a20be87

Please sign in to comment.