SON194-SON195 - Addition of SON BTC Account and report son down changes
This commit is contained in:
parent
1d5878db28
commit
7ea3bc159f
10 changed files with 132 additions and 7 deletions
|
|
@ -310,6 +310,9 @@ struct get_impacted_account_visitor
|
|||
void operator()( const son_heartbeat_operation& op ){
|
||||
_impacted.insert( op.owner_account );
|
||||
}
|
||||
void operator()( const son_report_down_operation& op ){
|
||||
_impacted.insert( op.payer );
|
||||
}
|
||||
};
|
||||
|
||||
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
||||
|
|
|
|||
|
|
@ -248,6 +248,7 @@ void database::initialize_evaluators()
|
|||
register_evaluator<update_son_evaluator>();
|
||||
register_evaluator<delete_son_evaluator>();
|
||||
register_evaluator<son_heartbeat_evaluator>();
|
||||
register_evaluator<son_report_down_evaluator>();
|
||||
}
|
||||
|
||||
void database::initialize_indexes()
|
||||
|
|
|
|||
|
|
@ -455,11 +455,62 @@ void database::update_active_sons()
|
|||
});
|
||||
});
|
||||
|
||||
//const witness_schedule_object& wso = witness_schedule_id_type()(*this);
|
||||
//modify(wso, [&](witness_schedule_object& _wso)
|
||||
//{
|
||||
// _wso.scheduler.update(gpo.active_witnesses);
|
||||
//});
|
||||
if(gpo.parameters.get_son_btc_account_id() == GRAPHENE_NULL_ACCOUNT) {
|
||||
const auto& son_btc_account = create<account_object>( [&]( account_object& obj ) {
|
||||
uint64_t total_votes = 0;
|
||||
obj.name = "son_btc_account";
|
||||
obj.statistics = create<account_statistics_object>([&]( 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;
|
||||
});
|
||||
|
||||
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 )
|
||||
{
|
||||
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;
|
||||
});
|
||||
}
|
||||
} FC_CAPTURE_AND_RETHROW() }
|
||||
|
||||
void database::initialize_budget_record( fc::time_point_sec now, budget_record& rec )const
|
||||
|
|
|
|||
|
|
@ -297,6 +297,9 @@ struct get_impacted_account_visitor
|
|||
void operator()( const son_heartbeat_operation& op ) {
|
||||
_impacted.insert( op.owner_account );
|
||||
}
|
||||
void operator()( const son_report_down_operation& op ) {
|
||||
_impacted.insert( op.payer );
|
||||
}
|
||||
};
|
||||
|
||||
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
|
||||
|
|
|
|||
|
|
@ -46,6 +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;
|
||||
};
|
||||
|
||||
struct chain_parameters
|
||||
|
|
@ -138,6 +139,9 @@ 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 {
|
||||
return extensions.value.son_btc_account.valid() ? *extensions.value.son_btc_account : GRAPHENE_NULL_ACCOUNT;
|
||||
}
|
||||
};
|
||||
|
||||
} } // graphene::chain
|
||||
|
|
@ -155,6 +159,7 @@ FC_REFLECT( graphene::chain::parameter_extension,
|
|||
(son_vesting_amount)
|
||||
(son_vesting_period)
|
||||
(son_pay_daily_max)
|
||||
(son_btc_account)
|
||||
)
|
||||
|
||||
FC_REFLECT( graphene::chain::chain_parameters,
|
||||
|
|
|
|||
|
|
@ -140,7 +140,8 @@ namespace graphene { namespace chain {
|
|||
son_create_operation,
|
||||
son_update_operation,
|
||||
son_delete_operation,
|
||||
son_heartbeat_operation
|
||||
son_heartbeat_operation,
|
||||
son_report_down_operation
|
||||
> operation;
|
||||
|
||||
/// @} // operations group
|
||||
|
|
|
|||
|
|
@ -60,6 +60,19 @@ namespace graphene { namespace chain {
|
|||
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
||||
};
|
||||
|
||||
struct son_report_down_operation : public base_operation
|
||||
{
|
||||
struct fee_parameters_type { uint64_t fee = 0; };
|
||||
|
||||
asset fee;
|
||||
son_id_type son_id;
|
||||
account_id_type payer;
|
||||
time_point_sec down_ts;
|
||||
|
||||
account_id_type fee_payer()const { return payer; }
|
||||
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
||||
};
|
||||
|
||||
} } // namespace graphene::chain
|
||||
|
||||
FC_REFLECT(graphene::chain::son_create_operation::fee_parameters_type, (fee) )
|
||||
|
|
@ -74,4 +87,7 @@ FC_REFLECT(graphene::chain::son_delete_operation::fee_parameters_type, (fee) )
|
|||
FC_REFLECT(graphene::chain::son_delete_operation, (fee)(son_id)(payer)(owner_account) )
|
||||
|
||||
FC_REFLECT(graphene::chain::son_heartbeat_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT(graphene::chain::son_heartbeat_operation, (fee)(son_id)(owner_account)(ts) )
|
||||
FC_REFLECT(graphene::chain::son_heartbeat_operation, (fee)(son_id)(owner_account)(ts) )
|
||||
|
||||
FC_REFLECT(graphene::chain::son_report_down_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT(graphene::chain::son_report_down_operation, (fee)(son_id)(payer)(down_ts) )
|
||||
|
|
@ -40,4 +40,13 @@ public:
|
|||
object_id_type do_apply(const son_heartbeat_operation& o);
|
||||
};
|
||||
|
||||
class son_report_down_evaluator : public evaluator<son_report_down_evaluator>
|
||||
{
|
||||
public:
|
||||
typedef son_report_down_operation operation_type;
|
||||
|
||||
void_result do_evaluate(const son_report_down_operation& o);
|
||||
object_id_type do_apply(const son_report_down_operation& o);
|
||||
};
|
||||
|
||||
} } // namespace graphene::chain
|
||||
|
|
|
|||
|
|
@ -152,6 +152,10 @@ struct proposal_operation_hardfork_visitor
|
|||
FC_ASSERT( block_time >= HARDFORK_SON_TIME, "son_heartbeat_operation not allowed yet!" );
|
||||
}
|
||||
|
||||
void operator()(const son_report_down_operation &v) const {
|
||||
FC_ASSERT( block_time >= HARDFORK_SON_TIME, "son_report_down_operation not allowed yet!" );
|
||||
}
|
||||
|
||||
// loop and self visit in proposals
|
||||
void operator()(const proposal_create_operation &v) const {
|
||||
for (const op_wrapper &op : v.proposed_ops)
|
||||
|
|
|
|||
|
|
@ -141,4 +141,36 @@ object_id_type son_heartbeat_evaluator::do_apply(const son_heartbeat_operation&
|
|||
return op.son_id;
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
void_result son_report_down_evaluator::do_evaluate(const son_report_down_operation& op)
|
||||
{ try {
|
||||
FC_ASSERT(op.payer == db().get_global_properties().parameters.get_son_btc_account_id(), "Payer should be the son btc account");
|
||||
const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
|
||||
FC_ASSERT( idx.find(op.son_id) != idx.end() );
|
||||
auto itr = idx.find(op.son_id);
|
||||
auto stats = itr->statistics( db() );
|
||||
FC_ASSERT(itr->status == son_status::active, "Inactive/Deregistered/in_maintenance SONs cannot be reported on as down");
|
||||
FC_ASSERT(op.down_ts >= stats.last_active_timestamp, "down_ts should be greater than last_active_timestamp");
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
object_id_type son_report_down_evaluator::do_apply(const son_report_down_operation& op)
|
||||
{ try {
|
||||
const auto& idx = db().get_index_type<son_index>().indices().get<by_id>();
|
||||
auto itr = idx.find(op.son_id);
|
||||
if(itr != idx.end())
|
||||
{
|
||||
if (itr->status == son_status::active) {
|
||||
db().modify( itr->statistics( db() ), [&]( son_statistics_object& sso )
|
||||
{
|
||||
sso.last_down_timestamp = op.down_ts;
|
||||
});
|
||||
|
||||
db().modify(*itr, [&op](son_object &so) {
|
||||
so.status = son_status::in_maintenance;
|
||||
});
|
||||
}
|
||||
}
|
||||
return op.son_id;
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
} } // namespace graphene::chain
|
||||
|
|
|
|||
Loading…
Reference in a new issue