Skip to content

Commit

Permalink
chore: normalized naming
Browse files Browse the repository at this point in the history
  • Loading branch information
RootkitKiller committed Jan 15, 2020
1 parent 0738f62 commit 616a0b8
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 85 deletions.
2 changes: 1 addition & 1 deletion libraries/chain/db_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void database::deposit_contract_call_cashback(const account_object& acct, share_

return;
}
void database::deposit_staking_cashback(const account_object& acct, share_type amount)
void database::staking_cashback(const account_object& acct, share_type amount)
{
if( amount == 0 )
return;
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/db_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ void database::initialize_evaluators()
register_evaluator<staking_create_evaluator>();
register_evaluator<staking_update_evaluator>();
register_evaluator<staking_claim_evaluator>();
register_evaluator<wit_commission_set_evaluator>();
register_evaluator<wit_banned_remove_evaluator>();
register_evaluator<witness_set_commission_evaluator>();
register_evaluator<witness_unbanned_evaluator>();
}

void database::initialize_indexes()
Expand Down
125 changes: 64 additions & 61 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,14 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
d._vote_id_valid[committee_itr->vote_id.instance()] = committee_itr->is_valid;
}
}
bool check_block_missed(const witness_object &wit){
if(wit.total_missed < wit.previous_missed || wit.is_banned) return false;
return wit.total_missed - wit.previous_missed <= d.get_vote_params().missed_limit || wit.previous_missed == 0;
bool check_witness_available(const witness_object &wit){
if(wit.is_banned) return false;
return wit.total_missed - wit.previous_missed <= d.get_vote_params().missed_block_limit || wit.previous_missed == 0;
}
void statistical_vote_weight(){
const auto& all_witnesses = d.get_index_type<witness_index>().indices();
for (const witness_object &wit : all_witnesses) {
if(check_block_missed(wit)){
if(check_witness_available(wit)){
d.modify(wit, [&](witness_object &obj) {
d._vote_tally_buffer[wit.vote_id] = wit.total_vote_weights.value;
d._total_voting_stake += wit.total_vote_weights.value;
Expand Down Expand Up @@ -700,14 +700,14 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
a.statistics(d).process_fees(a, d);
}
} fee_helper(*this, gpo);
if (head_block_time() > HARDFORK_1025_TIME && get_vote_params().switch_vote_one == true) {
if (head_block_time() > HARDFORK_1025_TIME && get_vote_params().staking_mode_on == true) {
//Count the new round of votes
tally_helper.statistical_vote_weight();
perform_account_maintenance(std::tie(fee_helper));

//current staking awards pools
const dynamic_global_property_object& dpo = get_dynamic_global_properties();
share_type staking_awards_pools_bak = dpo.current_staking_awards_pools;
share_type staking_awards_pools_bak = dpo.current_staking_reward_pool;
//The reward pool is distributed proportionally to each witness_node
const auto& witness_objects = get_index_type<witness_index>().indices();
uint32_t count = witness_objects.size();
Expand All @@ -719,64 +719,67 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
reward_total_weight += wit.total_vote_weights;
}
}
for(const witness_object& wit : wits){
if(!wit.is_banned && wit.is_valid){
share_type reward_pay = staking_awards_pools_bak * wit.total_vote_weights / reward_total_weight;
reward_pay = std::min(reward_pay, dpo.current_staking_awards_pools);
modify( dpo, [&]( dynamic_global_property_object& _dpo )
{
_dpo.current_staking_awards_pools -= reward_pay;
} );
share_type vote_pay = reward_pay * wit.commission_rate / 1000;
vote_pay = std::min(reward_pay,vote_pay);
modify(wit, [&](witness_object &obj) {
obj.vote_reward_pool += vote_pay;
});
share_type witness_pay = reward_pay - vote_pay;
deposit_witness_pay( wit, witness_pay );
if(reward_total_weight != 0 ){
for(const witness_object& wit : wits){
if(!wit.is_banned && wit.is_valid){
share_type reward_pay = staking_awards_pools_bak * wit.total_vote_weights / reward_total_weight;
reward_pay = std::min(reward_pay, dpo.current_staking_reward_pool);
modify( dpo, [&]( dynamic_global_property_object& _dpo )
{
_dpo.current_staking_reward_pool -= reward_pay;
} );
share_type vote_pay = reward_pay * wit.commission_rate / 1000;
vote_pay = std::min(reward_pay,vote_pay);
modify(wit, [&](witness_object &obj) {
obj.vote_reward_pool += vote_pay;
});
share_type witness_pay = reward_pay - vote_pay;
deposit_witness_pay( wit, witness_pay );
}
}
}
//distribute the dividend to each voting account
const auto& staking_objects = get_index_type<staking_index>().indices();
//backup witness vote_reward_pool and total_vote_weights
map<witness_id_type,share_type> wit_reward_pools;
map<witness_id_type,share_type> wit_total_vote_weights;
for(auto wit_obj:witness_objects){
wit_reward_pools[wit_obj.id] = wit_obj.vote_reward_pool;
wit_total_vote_weights[wit_obj.id] = wit_obj.total_vote_weights;
}
for (const auto &stak_obj : staking_objects) {
if(stak_obj.is_valid == true){
//calc reward
auto wit_obj_itor = witness_objects.find(stak_obj.trust_node);
if(wit_reward_pools.find(stak_obj.trust_node) != wit_reward_pools.end() &&
wit_total_vote_weights.find(stak_obj.trust_node) != wit_total_vote_weights.end() &&
wit_obj_itor != witness_objects.end() &&
wit_obj_itor->is_valid == true &&
wit_obj_itor->is_banned == false){
share_type voter_pay = wit_reward_pools[stak_obj.trust_node] * stak_obj.amount.amount * stak_obj.weight / wit_total_vote_weights[stak_obj.trust_node];
voter_pay = std::min(voter_pay, wit_obj_itor->vote_reward_pool);
if(voter_pay != 0){ // > 0
deposit_staking_cashback(get(stak_obj.owner),voter_pay);
modify(*wit_obj_itor, [&](witness_object &obj) {
obj.vote_reward_pool -= voter_pay;
});
//distribute the dividend to each voting account
const auto& staking_objects = get_index_type<staking_index>().indices();
//backup witness vote_reward_pool and total_vote_weights
map<witness_id_type,share_type> wit_reward_pools;
map<witness_id_type,share_type> wit_total_vote_weights;
for(auto wit_obj:witness_objects){
wit_reward_pools[wit_obj.id] = wit_obj.vote_reward_pool;
wit_total_vote_weights[wit_obj.id] = wit_obj.total_vote_weights;
}
for (const auto &stak_obj : staking_objects) {
if(stak_obj.is_valid == true){
//calc reward
auto wit_obj_itor = witness_objects.find(stak_obj.trust_node);
if(wit_reward_pools.find(stak_obj.trust_node) != wit_reward_pools.end() &&
wit_total_vote_weights.find(stak_obj.trust_node) != wit_total_vote_weights.end() &&
wit_obj_itor != witness_objects.end() &&
wit_obj_itor->is_valid == true &&
wit_obj_itor->is_banned == false &&
wit_total_vote_weights[stak_obj.trust_node] !=0 ){
share_type voter_pay = wit_reward_pools[stak_obj.trust_node] * stak_obj.amount.amount * stak_obj.weight / wit_total_vote_weights[stak_obj.trust_node];
voter_pay = std::min(voter_pay, wit_obj_itor->vote_reward_pool);
if(voter_pay != 0){ // > 0
staking_cashback(get(stak_obj.owner),voter_pay);
modify(*wit_obj_itor, [&](witness_object &obj) {
obj.vote_reward_pool -= voter_pay;
});
}
//staking expire
if(stak_obj.staking_days * SECONDS_PER_DAY < (head_block_time().sec_since_epoch() - stak_obj.create_date_time.sec_since_epoch())){
modify(stak_obj, [&](staking_object &obj) {
obj.is_valid = false;
});
//reduce witness total_vote_weights;
modify(*wit_obj_itor, [&](witness_object& obj) {
share_type total_vote_weights = stak_obj.amount.amount * stak_obj.weight;
share_type reduce_vote_weights = std::min(total_vote_weights, obj.total_vote_weights);
obj.total_vote_weights -= reduce_vote_weights;
});
}
}
//staking expire
if(stak_obj.staking_days * SECONDS_PER_DAY < (head_block_time().sec_since_epoch() - stak_obj.create_date_time.sec_since_epoch())){
modify(stak_obj, [&](staking_object &obj) {
obj.is_valid = false;
});
//reduce witness total_vote_weights;
modify(*wit_obj_itor, [&](witness_object& obj) {
share_type total_vote_weights = stak_obj.amount.amount * stak_obj.weight;
share_type reduse_vote_weights = std::min(total_vote_weights, obj.total_vote_weights);
obj.total_vote_weights -= reduse_vote_weights;
});
}
}
}
}
}
}
}
else {
perform_account_maintenance(std::tie(
Expand Down
6 changes: 3 additions & 3 deletions libraries/chain/db_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ void database::update_signing_witness(const witness_object& signing_witness, con
{
_dpo.witness_budget -= witness_pay;
} );
if (head_block_time() > HARDFORK_1025_TIME && get_vote_params().switch_vote_one == true){
share_type witness_rewards = witness_pay * get_vote_params().witness_award_proportion / 1000;
if (head_block_time() > HARDFORK_1025_TIME && get_vote_params().staking_mode_on == true){
share_type witness_rewards = witness_pay * get_vote_params().witness_reward_proportion / 1000;
witness_rewards = std::min(witness_rewards,witness_pay);
modify( dpo, [&]( dynamic_global_property_object& _dpo )
{
_dpo.current_staking_awards_pools += (witness_pay - witness_rewards);
_dpo.current_staking_reward_pool += (witness_pay - witness_rewards);
} );
deposit_witness_pay( signing_witness, witness_rewards );
} else {
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ namespace graphene { namespace chain {
// to handle contract calling fees
void deposit_contract_call_cashback(const account_object& acct, share_type amount);
// helper to handle staking rewards
void deposit_staking_cashback(const account_object& acct, share_type amount);
void staking_cashback(const account_object& acct, share_type amount);
// helper to handle witness pay
void deposit_witness_pay(const witness_object& wit, share_type amount);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ namespace graphene { namespace chain {

uint32_t last_irreversible_block_num = 0;

share_type current_staking_awards_pools;
share_type current_staking_reward_pool;

enum dynamic_flag_bits
{
Expand Down Expand Up @@ -140,7 +140,7 @@ FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_object, (graphene::
(recent_slots_filled)
(dynamic_flags)
(last_irreversible_block_num)
(current_staking_awards_pools)
(current_staking_reward_pool)
)

FC_REFLECT_DERIVED( graphene::chain::global_property_object, (graphene::db::object),
Expand Down
14 changes: 7 additions & 7 deletions libraries/chain/include/graphene/chain/protocol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ namespace graphene { namespace chain {
struct staking_params_t {
vector< pair<fc::string, staking_weight_t> > params;
};
struct vote_params_t {
bool switch_vote_one = false;
struct vote_params_t {
bool staking_mode_on = false;
uint32_t set_commission_interval = 60*60*24*7; // 1 week
uint32_t staking_rewards_vesting_seconds = 60*60; // 1 h
uint32_t missed_limit = 100000;
uint32_t max_num_mortgages = 10;
uint32_t witness_award_proportion = 500;
uint32_t missed_block_limit = 100000;
uint32_t max_staking_count = 10;
uint32_t witness_reward_proportion = 500;
uint32_t valid_nodes_number = 35;
uint64_t min_staking = GRAPHENE_BLOCKCHAIN_PRECISION;
uint64_t min_staking_amount = GRAPHENE_BLOCKCHAIN_PRECISION;
};

typedef fc::ecc::private_key private_key_type;
Expand Down Expand Up @@ -705,7 +705,7 @@ FC_REFLECT(graphene::chain::vm_cpu_limit_t, (trx_cpu_limit)(block_cpu_limit))
FC_REFLECT(graphene::chain::asset_symbol_t, (symbol))
FC_REFLECT(graphene::chain::trust_node_pledge_t, (amount))
FC_REFLECT(graphene::chain::inter_contract_calling_params_t, (max_inter_contract_depth)(contract_basic_fee_vesting_period_seconds)(max_inline_action_size))
FC_REFLECT(graphene::chain::vote_params_t, (switch_vote_one)(set_commission_interval)(staking_rewards_vesting_seconds)(missed_limit)(max_num_mortgages)(witness_award_proportion)(valid_nodes_number)(min_staking))
FC_REFLECT(graphene::chain::vote_params_t, (staking_mode_on)(set_commission_interval)(staking_rewards_vesting_seconds)(missed_block_limit)(max_staking_count)(witness_reward_proportion)(valid_nodes_number)(min_staking_amount))


FC_REFLECT_ENUM(graphene::chain::asset_issuer_permission_flags,
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/include/graphene/chain/witness_evaluator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace graphene { namespace chain {
void_result do_apply(const witness_update_operation& o, int32_t billed_cpu_time_us = 0);
};

class wit_commission_set_evaluator : public evaluator<wit_commission_set_evaluator>
class witness_set_commission_evaluator : public evaluator<witness_set_commission_evaluator>
{
public:
typedef witness_set_commission_operation operation_type;
Expand All @@ -54,7 +54,7 @@ namespace graphene { namespace chain {
void_result do_apply(const witness_set_commission_operation& o, int32_t billed_cpu_time_us = 0);
};

class wit_banned_remove_evaluator : public evaluator<wit_banned_remove_evaluator>
class witness_unbanned_evaluator : public evaluator<witness_unbanned_evaluator>
{
public:
typedef witness_unbanned_operation operation_type;
Expand Down
4 changes: 2 additions & 2 deletions libraries/chain/staking_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void_result staking_create_evaluator::do_evaluate(const staking_create_operation
// gxc assets
FC_ASSERT(op.amount.asset_id == GRAPHENE_GXS_ASSET, "staking asset must be GXC");
FC_ASSERT(op.amount <= _db.get_balance(op.owner, GRAPHENE_GXS_ASSET), "account balance not enough");
FC_ASSERT(op.amount.amount >= _db.get_vote_params().min_staking, "staking amount must > ${amount}",("amount",_db.get_vote_params().min_staking));
FC_ASSERT(op.amount.amount >= _db.get_vote_params().min_staking_amount, "staking amount must > ${amount}",("amount",_db.get_vote_params().min_staking_amount));

// Check the staking time, such as 7 days, 30 days, 60 days, 90 days, with global parameters

Expand All @@ -53,7 +53,7 @@ void_result staking_create_evaluator::do_evaluate(const staking_create_operation
FC_ASSERT(staking_days == op.staking_days, "input staking days invalid");

auto staking_ranges = _db.get_index_type<staking_index>().indices().get<by_owner>().equal_range(op.owner);
FC_ASSERT(std::distance(staking_ranges.first, staking_ranges.second) < _db.get_vote_params().max_num_mortgages, "mortgages have reached their maximum number");
FC_ASSERT(std::distance(staking_ranges.first, staking_ranges.second) < _db.get_vote_params().max_staking_count, "mortgages have reached their maximum number");

// check trust_node account
const auto& witness_objects = _db.get_index_type<witness_index>().indices();
Expand Down
8 changes: 4 additions & 4 deletions libraries/chain/witness_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void_result witness_update_evaluator::do_apply(const witness_update_operation& o
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result wit_commission_set_evaluator::do_evaluate( const witness_set_commission_operation& op )
void_result witness_set_commission_evaluator::do_evaluate( const witness_set_commission_operation& op )
{ try {
database& _db = db();
FC_ASSERT(_db.get(op.witness).witness_account == op.witness_account);
Expand All @@ -110,7 +110,7 @@ void_result wit_commission_set_evaluator::do_evaluate( const witness_set_commiss
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result wit_commission_set_evaluator::do_apply(const witness_set_commission_operation& op, int32_t billed_cpu_time_us)
void_result witness_set_commission_evaluator::do_apply(const witness_set_commission_operation& op, int32_t billed_cpu_time_us)
{ try {
database& _db = db();
_db.modify(
Expand All @@ -127,15 +127,15 @@ void_result wit_commission_set_evaluator::do_apply(const witness_set_commission_
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result wit_banned_remove_evaluator::do_evaluate( const witness_unbanned_operation& op )
void_result witness_unbanned_evaluator::do_evaluate( const witness_unbanned_operation& op )
{ try {
database& _db = db();
trust_node_pledge_helper::do_evaluate(_db, op);
FC_ASSERT(_db.get(op.witness).witness_account == op.witness_account);
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

void_result wit_banned_remove_evaluator::do_apply(const witness_unbanned_operation& op, int32_t billed_cpu_time_us)
void_result witness_unbanned_evaluator::do_apply(const witness_unbanned_operation& op, int32_t billed_cpu_time_us)
{ try {
database& _db = db();
_db.modify(
Expand Down

0 comments on commit 616a0b8

Please sign in to comment.