diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 1e3310ae..8923d55c 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -455,61 +455,68 @@ void database::update_active_sons() }); }); - if(gpo.parameters.get_son_btc_account_id() == GRAPHENE_NULL_ACCOUNT) { - const auto& son_btc_account = create( [&]( account_object& obj ) { - uint64_t total_votes = 0; - obj.name = "son_btc_account"; - obj.statistics = create([&]( account_statistics_object& acc_stat ){ acc_stat.owner = obj.id; }).id; - obj.membership_expiration_date = time_point_sec::maximum(); - obj.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - obj.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; + 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& obj ) { + uint64_t total_votes = 0; + obj.name = "son_btc_account"; + obj.statistics = create([&]( account_statistics_object& acc_stat ){ acc_stat.owner = obj.id; }).id; + obj.membership_expiration_date = time_point_sec::maximum(); + 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 ) - { - 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 ) - { - // 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; - }); + 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); - modify( gpo, [&]( global_property_object& gpo ) { - gpo.parameters.extensions.value.son_btc_account = son_btc_account; - if( gpo.pending_parameters ) - gpo.pending_parameters->extensions.value.son_btc_account = son_btc_account; - }); - } 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 ) + { + // 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; + } + obj.active.weight_threshold *= 2; + 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]; - } - // 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 ) - { - // 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; - }); + uint64_t total_votes = 0; + 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 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; + } + obj.active.weight_threshold *= 2; + obj.active.weight_threshold /= 3; + obj.active.weight_threshold += 1; + }); + } } } FC_CAPTURE_AND_RETHROW() } diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index 9dcd5aad..51024e16 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -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; } };