Merge branch 'feature/SONs-base' into feature/SON-98

This commit is contained in:
Srdjan Obucina 2020-01-15 12:56:37 +01:00
commit ba255da679
2 changed files with 19 additions and 10 deletions

View file

@ -502,19 +502,19 @@ void database::update_active_sons()
obj.network_fee_percentage = 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; obj.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE;
for( const auto& son_id : gpo.active_sons ) for( const auto& son_info : gpo.active_sons )
{ {
const son_object& son = get(son_id); const son_object& son = get(son_info.son_id);
total_votes += _vote_tally_buffer[son.vote_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, // 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. // 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); 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 ) for( const auto& son_info : gpo.active_sons )
{ {
// Ensure that everyone has at least one vote. Zero weights aren't allowed. // Ensure that everyone has at least one vote. Zero weights aren't allowed.
const son_object& son = get(son_id); const son_object& son = get(son_info.son_id);
uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) ); 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.account_auths[son.son_account] += votes;
obj.active.weight_threshold += votes; obj.active.weight_threshold += votes;
@ -533,18 +533,18 @@ void database::update_active_sons()
modify( get(gpo.parameters.get_son_btc_account_id()), [&]( account_object& obj ) modify( get(gpo.parameters.get_son_btc_account_id()), [&]( account_object& obj )
{ {
uint64_t total_votes = 0; uint64_t total_votes = 0;
for( const auto& son_id : gpo.active_sons ) for( const auto& son_info : gpo.active_sons )
{ {
const son_object& son = get(son_id); const son_object& son = get(son_info.son_id);
total_votes += _vote_tally_buffer[son.vote_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, // 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. // 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); 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 ) for( const auto& son_info : gpo.active_sons )
{ {
// Ensure that everyone has at least one vote. Zero weights aren't allowed. // Ensure that everyone has at least one vote. Zero weights aren't allowed.
const son_object& son = get(son_id); const son_object& son = get(son_info.son_id);
uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) ); 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.account_auths[son.son_account] += votes;
obj.active.weight_threshold += votes; obj.active.weight_threshold += votes;

View file

@ -182,8 +182,17 @@ void peerplays_sidechain_plugin_impl::heartbeat_loop()
chain::database& d = plugin.database(); chain::database& d = plugin.database();
chain::son_id_type son_id = *(_sons.begin()); chain::son_id_type son_id = *(_sons.begin());
const chain::global_property_object& gpo = d.get_global_properties(); const chain::global_property_object& gpo = d.get_global_properties();
auto it = std::find(gpo.active_sons.begin(), gpo.active_sons.end(), son_id);
if(it != gpo.active_sons.end()) { vector<son_id_type> active_son_ids;
active_son_ids.reserve(gpo.active_sons.size());
std::transform(gpo.active_sons.begin(), gpo.active_sons.end(),
std::inserter(active_son_ids, active_son_ids.end()),
[](const son_info& swi) {
return swi.son_id;
});
auto it = std::find(active_son_ids.begin(), active_son_ids.end(), son_id);
if(it != active_son_ids.end()) {
ilog("peerplays_sidechain_plugin: sending heartbeat"); ilog("peerplays_sidechain_plugin: sending heartbeat");
chain::son_heartbeat_operation op; chain::son_heartbeat_operation op;
const auto& idx = d.get_index_type<chain::son_index>().indices().get<by_id>(); const auto& idx = d.get_index_type<chain::son_index>().indices().get<by_id>();