Merge branch 'feature/SONs-base' of https://github.com/peerplays-network/peerplays into feature/SON-322_SON-324

This commit is contained in:
Srdjan Obucina 2020-04-04 05:49:39 +02:00
commit dc26b5b2ac
4 changed files with 45 additions and 0 deletions

View file

@ -77,6 +77,32 @@ vector<std::reference_wrapper<const typename Index::object_type>> database::sort
return refs;
}
template<>
vector<std::reference_wrapper<const son_object>> database::sort_votable_objects<son_index>(size_t count) const
{
const auto& all_sons = get_index_type<son_index>().indices().get< by_id >();
std::vector<std::reference_wrapper<const son_object>> refs;
for( auto& son : all_sons )
{
if(son.has_valid_config())
{
refs.push_back(std::cref(son));
}
}
count = std::min(count, refs.size());
std::partial_sort(refs.begin(), refs.begin() + count, refs.end(),
[this](const son_object& a, const son_object& b)->bool {
share_type oa_vote = _vote_tally_buffer[a.vote_id];
share_type ob_vote = _vote_tally_buffer[b.vote_id];
if( oa_vote != ob_vote )
return oa_vote > ob_vote;
return a.vote_id < b.vote_id;
});
refs.resize(count, refs.front());
return refs;
}
template<class Type>
void database::perform_account_maintenance(Type tally_helper)
{
@ -730,6 +756,13 @@ void database::update_active_sons()
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);
}
});
} FC_CAPTURE_AND_RETHROW() }

View file

@ -73,6 +73,7 @@ namespace graphene { namespace chain {
flat_map<sidechain_type, string> sidechain_public_keys;
void pay_son_fee(share_type pay, database& db);
bool has_valid_config()const;
};
struct by_account;

View file

@ -76,6 +76,7 @@ void_result delete_son_evaluator::do_evaluate(const son_delete_operation& op)
void_result delete_son_evaluator::do_apply(const son_delete_operation& op)
{ try {
const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
const auto& ss_idx = db().get_index_type<son_stats_index>().indices().get<by_id>();
auto son = idx.find(op.son_id);
if(son != idx.end()) {
vesting_balance_object deposit = son->deposit(db());
@ -88,6 +89,9 @@ void_result delete_son_evaluator::do_apply(const son_delete_operation& op)
vbo.policy = new_vesting_policy;
});
auto stats_obj = ss_idx.find(son->statistics);
if(stats_obj != ss_idx.end())
db().remove(*stats_obj);
db().remove(*son);
}
return void_result();

View file

@ -5,4 +5,11 @@ namespace graphene { namespace chain {
void son_object::pay_son_fee(share_type pay, database& db) {
db.adjust_balance(son_account, pay);
}
bool son_object::has_valid_config()const {
return ((std::string(signing_key).length() > 0) &&
(sidechain_public_keys.size() > 0) &&
(sidechain_public_keys.find( sidechain_type::bitcoin ) != sidechain_public_keys.end()) &&
(sidechain_public_keys.at(sidechain_type::bitcoin).length() > 0));
}
}}