Skip to content

Commit

Permalink
Merge branch 'feature/308-multiple-lists-of-active-SON' into 'feature…
Browse files Browse the repository at this point in the history
…/son-for-hive-voting'

#308 List of active SONs per sidechain

See merge request PBSA/peerplays!92
  • Loading branch information
serkixenos committed Apr 7, 2022
2 parents 94a3998 + eb5ef77 commit 355b9aa
Show file tree
Hide file tree
Showing 26 changed files with 736 additions and 513 deletions.
9 changes: 8 additions & 1 deletion libraries/chain/db_block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,12 @@ void database::_apply_block( const signed_block& next_block )

if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SCHEDULED_ALGORITHM) {
update_witness_schedule(next_block);
if(global_props.active_sons.size() > 0) {
bool need_to_update_son_schedule = false;
for(const auto& active_sons : global_props.active_sons){
if(!active_sons.second.empty())
need_to_update_son_schedule = true;
}
if(need_to_update_son_schedule) {
update_son_schedule(next_block);
}
}
Expand Down Expand Up @@ -737,6 +742,8 @@ void database::_apply_block( const signed_block& next_block )
update_maintenance_flag( maint_needed );
if (global_props.parameters.witness_schedule_algorithm == GRAPHENE_WITNESS_SHUFFLED_ALGORITHM) {
update_witness_schedule();

//! Fixme - here we should take active_sons size for sidechain
if(global_props.active_sons.size() > 0) {
update_son_schedule();
}
Expand Down
34 changes: 27 additions & 7 deletions libraries/chain/db_getter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,18 @@ std::set<son_id_type> database::get_sons_to_be_deregistered()

for( auto& son : son_idx )
{
if(son.status == son_status::in_maintenance)
bool need_to_be_deregistered = true;
for(const auto& status : son.statuses)
{
if(status.second != son_status::in_maintenance)
need_to_be_deregistered = false;
}

if(need_to_be_deregistered)
{
auto stats = son.statistics(*this);
// TODO : We need to add a function that returns if we can deregister SON
// i.e. with introduction of PW code, we have to make a decision if the SON
// TODO : We need to add a function that returns if we can deregister SON
// i.e. with introduction of PW code, we have to make a decision if the SON
// is needed for release of funds from the PW
if(head_block_time() - stats.last_down_timestamp >= fc::seconds(get_global_properties().parameters.son_deregister_time()))
{
Expand Down Expand Up @@ -289,11 +296,18 @@ bool database::is_son_dereg_valid( son_id_type son_id )
return false;
}

return (son->status == son_status::in_maintenance &&
bool status_in_maintenance = true;
for(const auto& status : son->statuses)
{
if(status.second != son_status::in_maintenance)
status_in_maintenance = false;
}

return (status_in_maintenance &&
(head_block_time() - son->statistics(*this).last_down_timestamp >= fc::seconds(get_global_properties().parameters.son_deregister_time())));
}

bool database::is_son_active( son_id_type son_id )
bool database::is_son_active( sidechain_type type, son_id_type son_id )
{
const auto& son_idx = get_index_type<son_index>().indices().get< by_id >();
auto son = son_idx.find( son_id );
Expand All @@ -303,9 +317,15 @@ bool database::is_son_active( son_id_type son_id )
}

const global_property_object& gpo = get_global_properties();
if(!gpo.active_sons.contains(type))
{
return false;
}

const auto& gpo_as = gpo.active_sons.at(type);
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(),
active_son_ids.reserve(gpo_as.size());
std::transform(gpo_as.cbegin(), gpo_as.cend(),
std::inserter(active_son_ids, active_son_ids.end()),
[](const son_info& swi) {
return swi.son_id;
Expand Down
Loading

0 comments on commit 355b9aa

Please sign in to comment.