#308 - fix update_son_statuses + son_schedule

This commit is contained in:
Vlad Dobromyslov 2022-03-31 15:31:56 +03:00
parent 467522f7d8
commit f6c9b1b7a6
2 changed files with 52 additions and 18 deletions

View file

@ -315,23 +315,21 @@ void database::update_son_metrics(const flat_map<sidechain_type, vector<son_info
void database::update_son_statuses( const flat_map<sidechain_type, vector<son_info> >& curr_active_sons,
const flat_map<sidechain_type, vector<son_info> >& new_active_sons )
{
FC_ASSERT(curr_active_sons.size() == new_active_sons.size(), "Invalid size in SON active lists,"
" curr_active_sons_size={curr_active_sons_size}, new_active_sons_size={new_active_sons_size}",
("curr_active_sons_size", curr_active_sons.size())("new_active_sons_size", new_active_sons.size()));
for(const auto& curr_active_sidechain_sons : curr_active_sons) {
const auto& sidechain = curr_active_sidechain_sons.first;
for(const auto& new_active_sidechain_sons : new_active_sons) {
const auto& sidechain = new_active_sidechain_sons.first;
vector<son_id_type> current_sons, new_sons;
vector<son_id_type> sons_to_remove, sons_to_add;
const auto &idx = get_index_type<son_index>().indices().get<by_id>();
current_sons.reserve(curr_active_sons.at(sidechain).size());
std::transform(curr_active_sons.at(sidechain).cbegin(), curr_active_sons.at(sidechain).cend(),
std::inserter(current_sons, current_sons.end()),
[](const son_info &swi) {
return swi.son_id;
});
if(curr_active_sons.contains(sidechain)) {
current_sons.reserve(curr_active_sons.at(sidechain).size());
std::transform(curr_active_sons.at(sidechain).cbegin(), curr_active_sons.at(sidechain).cend(),
std::inserter(current_sons, current_sons.end()),
[](const son_info &swi) {
return swi.son_id;
});
}
new_sons.reserve(new_active_sons.at(sidechain).size());
std::transform(new_active_sons.at(sidechain).cbegin(), new_active_sons.at(sidechain).cend(),
@ -388,10 +386,22 @@ void database::update_son_statuses( const flat_map<sidechain_type, vector<son_in
continue;
ilog("${s}, status = ${ss}, total_votes = ${sv}", ("s", new_sons[i])("ss", son->statuses.at(sidechain))("sv", son->total_votes));
}
}
if (sons_to_remove.size() > 0) {
remove_inactive_son_proposals(sons_to_remove);
//! Remove inactive sons (when all sidechain inactive)
vector<son_id_type> sons_to_remove;
const auto &idx = get_index_type<son_index>().indices().get<by_id>();
for(const auto& son : idx) {
bool inactive_son = true;
for(const auto& status : son.statuses) {
if (status.second != son_status::inactive)
inactive_son = false;
}
if (inactive_son)
sons_to_remove.emplace_back(son.id);
}
if (sons_to_remove.size() > 0) {
remove_inactive_son_proposals(sons_to_remove);
}
}
@ -799,7 +809,10 @@ void database::update_active_sons()
const auto &acc = get(gpo.parameters.son_account());
for( const auto& sidechain_sons : sons ){
const auto& sidechain = sidechain_sons.first;
for( const son_object& son : sidechain_sons.second ) {
const auto& sons_array = sidechain_sons.second;
new_active_sons[sidechain].reserve(sons_array.size());
for( const son_object& son : sons_array ) {
son_info swi;
swi.son_id = son.id;
swi.weight = acc.active.account_auths.at(son.son_account);
@ -848,6 +861,27 @@ void database::update_active_sons()
}
});
//! Fixme - fix this schedule
const son_schedule_object& sso = son_schedule_id_type()(*this);
modify(sso, [&](son_schedule_object& _sso)
{
flat_set<son_id_type> active_sons;
active_sons.reserve(gpo.active_sons.at(sidechain_type::bitcoin).size());
std::transform(gpo.active_sons.at(sidechain_type::bitcoin).cbegin(), gpo.active_sons.at(sidechain_type::bitcoin).cend(),
std::inserter(active_sons, active_sons.end()),
[](const son_info& swi) {
return swi.son_id;
});
_sso.scheduler.update(active_sons);
// similar to witness, produce schedule for sons
if(cur_active_sons.size() == 0 && new_active_sons.size() > 0)
{
witness_scheduler_rng rng(_sso.rng_seed.begin(), GRAPHENE_NEAR_SCHEDULE_CTR_IV);
for( size_t i=0; i<new_active_sons.size(); ++i )
_sso.scheduler.produce_schedule(rng);
}
});
// for now put the all active_sons in hive schedule object
// later we will make here the change which will take only son's from
// active_sons that are hive

View file

@ -434,7 +434,7 @@ void database::update_son_schedule(const signed_block& next_block)
_sso.slots_since_genesis += schedule_slot;
witness_scheduler_rng rng(sso.rng_seed.data, _sso.slots_since_genesis);
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.size()) / 2, 1);
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(sidechain_type::bitcoin).size()) / 2, 1);
if( slot_is_near )
{
@ -467,7 +467,7 @@ void database::update_son_schedule(const signed_block& next_block)
_sso.slots_since_genesis += schedule_slot;
witness_scheduler_rng rng(ssohive.rng_seed.data, _sso.slots_since_genesis);
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.size()) / 2, 1);
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(sidechain_type::hive).size()) / 2, 1);
if( slot_is_near_hive )
{
@ -500,7 +500,7 @@ void database::update_son_schedule(const signed_block& next_block)
_sso.slots_since_genesis += schedule_slot;
witness_scheduler_rng rng(ssohive.rng_seed.data, _sso.slots_since_genesis);
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.size()) / 2, 1);
_sso.scheduler._min_token_count = std::max(int(gpo.active_sons.at(sidechain_type::bitcoin).size()) / 2, 1);
if( slot_is_near_bitcoin )
{