SON194-SON195 - SON BTC Account errors rectification

This commit is contained in:
satyakoneru 2019-12-13 02:57:43 +00:00
parent 7ea3bc159f
commit 43d27401ea
2 changed files with 61 additions and 54 deletions

View file

@ -455,6 +455,7 @@ void database::update_active_sons()
});
});
if(gpo.active_sons.size() > 0 ) {
if(gpo.parameters.get_son_btc_account_id() == GRAPHENE_NULL_ACCOUNT) {
const auto& son_btc_account = create<account_object>( [&]( account_object& obj ) {
uint64_t total_votes = 0;
@ -464,16 +465,19 @@ void database::update_active_sons()
obj.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
obj.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
for( const son_object& son : gpo.active_sons )
for( const auto& son_id : gpo.active_sons )
{
const son_object& son = get(son_id);
total_votes += _vote_tally_buffer[son.vote_id];
}
// total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits,
// then I want to keep the most significant 16 bits of what's left.
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
for( const son_object& son : gpo.active_sons )
for( const auto& son_id : gpo.active_sons )
{
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
const son_object& son = get(son_id);
uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) );
obj.active.account_auths[son.son_account] += votes;
obj.active.weight_threshold += votes;
@ -484,24 +488,26 @@ void database::update_active_sons()
});
modify( gpo, [&]( global_property_object& gpo ) {
gpo.parameters.extensions.value.son_btc_account = son_btc_account;
gpo.parameters.extensions.value.son_btc_account = son_btc_account.get_id();
if( gpo.pending_parameters )
gpo.pending_parameters->extensions.value.son_btc_account = son_btc_account;
gpo.pending_parameters->extensions.value.son_btc_account = son_btc_account.get_id();
});
} else {
modify( get(gpo.parameters.get_son_btc_account_id()), [&]( account_object& obj )
{
uint64_t total_votes = 0;
for( const son_object& son : gpo.active_sons )
for( const auto& son_id : gpo.active_sons )
{
const son_object& son = get(son_id);
total_votes += _vote_tally_buffer[son.vote_id];
}
// total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits,
// then I want to keep the most significant 16 bits of what's left.
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
for( const son_object& son : gpo.active_sons )
for( const auto& son_id : gpo.active_sons )
{
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
const son_object& son = get(son_id);
uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) );
obj.active.account_auths[son.son_account] += votes;
obj.active.weight_threshold += votes;
@ -511,6 +517,7 @@ void database::update_active_sons()
obj.active.weight_threshold += 1;
});
}
}
} FC_CAPTURE_AND_RETHROW() }
void database::initialize_budget_record( fc::time_point_sec now, budget_record& rec )const

View file

@ -46,7 +46,7 @@ namespace graphene { namespace chain {
optional < uint32_t > son_vesting_amount;
optional < uint32_t > son_vesting_period;
optional < uint32_t > son_pay_daily_max;
optional < graphene::chain::account_id_type > son_btc_account;
optional < account_id_type > son_btc_account;
};
struct chain_parameters
@ -139,7 +139,7 @@ namespace graphene { namespace chain {
inline uint16_t son_pay_daily_max()const {
return extensions.value.son_pay_daily_max.valid() ? *extensions.value.son_pay_daily_max : MIN_SON_PAY_DAILY_MAX;
}
inline const account_id_type& get_son_btc_account_id() const {
inline account_id_type get_son_btc_account_id() const {
return extensions.value.son_btc_account.valid() ? *extensions.value.son_btc_account : GRAPHENE_NULL_ACCOUNT;
}
};