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,61 +455,68 @@ void database::update_active_sons()
}); });
}); });
if(gpo.parameters.get_son_btc_account_id() == GRAPHENE_NULL_ACCOUNT) { if(gpo.active_sons.size() > 0 ) {
const auto& son_btc_account = create<account_object>( [&]( account_object& obj ) { if(gpo.parameters.get_son_btc_account_id() == GRAPHENE_NULL_ACCOUNT) {
uint64_t total_votes = 0; const auto& son_btc_account = create<account_object>( [&]( account_object& obj ) {
obj.name = "son_btc_account"; uint64_t total_votes = 0;
obj.statistics = create<account_statistics_object>([&]( account_statistics_object& acc_stat ){ acc_stat.owner = obj.id; }).id; obj.name = "son_btc_account";
obj.membership_expiration_date = time_point_sec::maximum(); obj.statistics = create<account_statistics_object>([&]( account_statistics_object& acc_stat ){ acc_stat.owner = obj.id; }).id;
obj.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; obj.membership_expiration_date = time_point_sec::maximum();
obj.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; 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 )
{ {
total_votes += _vote_tally_buffer[son.vote_id]; 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. // total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits,
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0); // then I want to keep the most significant 16 bits of what's left.
for( const son_object& son : gpo.active_sons ) int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
{
// Ensure that everyone has at least one vote. Zero weights aren't allowed.
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;
}
obj.active.weight_threshold *= 2;
obj.active.weight_threshold /= 3;
obj.active.weight_threshold += 1;
});
modify( gpo, [&]( global_property_object& gpo ) { for( const auto& son_id : gpo.active_sons )
gpo.parameters.extensions.value.son_btc_account = son_btc_account; {
if( gpo.pending_parameters ) // Ensure that everyone has at least one vote. Zero weights aren't allowed.
gpo.pending_parameters->extensions.value.son_btc_account = son_btc_account; const son_object& son = get(son_id);
}); uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) );
} else { obj.active.account_auths[son.son_account] += votes;
modify( get(gpo.parameters.get_son_btc_account_id()), [&]( account_object& obj ) obj.active.weight_threshold += votes;
{ }
uint64_t total_votes = 0; obj.active.weight_threshold *= 2;
for( const son_object& son : gpo.active_sons ) obj.active.weight_threshold /= 3;
obj.active.weight_threshold += 1;
});
modify( gpo, [&]( global_property_object& gpo ) {
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.get_id();
});
} else {
modify( get(gpo.parameters.get_son_btc_account_id()), [&]( account_object& obj )
{ {
total_votes += _vote_tally_buffer[son.vote_id]; uint64_t total_votes = 0;
} for( const auto& son_id : gpo.active_sons )
// 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. const son_object& son = get(son_id);
int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0); total_votes += _vote_tally_buffer[son.vote_id];
for( const son_object& son : gpo.active_sons ) }
{ // total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits,
// Ensure that everyone has at least one vote. Zero weights aren't allowed. // then I want to keep the most significant 16 bits of what's left.
uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) ); int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0);
obj.active.account_auths[son.son_account] += votes; for( const auto& son_id : gpo.active_sons )
obj.active.weight_threshold += votes; {
} // Ensure that everyone has at least one vote. Zero weights aren't allowed.
obj.active.weight_threshold *= 2; const son_object& son = get(son_id);
obj.active.weight_threshold /= 3; uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) );
obj.active.weight_threshold += 1; obj.active.account_auths[son.son_account] += votes;
}); obj.active.weight_threshold += votes;
}
obj.active.weight_threshold *= 2;
obj.active.weight_threshold /= 3;
obj.active.weight_threshold += 1;
});
}
} }
} FC_CAPTURE_AND_RETHROW() } } FC_CAPTURE_AND_RETHROW() }

View file

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