From 616a0b843de8ad86c5e979e5274ad546fca3dfed Mon Sep 17 00:00:00 2001 From: RootkitKiller Date: Wed, 15 Jan 2020 10:47:42 +0800 Subject: [PATCH] chore: normalized naming --- libraries/chain/db_balance.cpp | 2 +- libraries/chain/db_init.cpp | 4 +- libraries/chain/db_maint.cpp | 125 +++++++++--------- libraries/chain/db_update.cpp | 6 +- .../chain/include/graphene/chain/database.hpp | 2 +- .../graphene/chain/global_property_object.hpp | 4 +- .../include/graphene/chain/protocol/types.hpp | 14 +- .../graphene/chain/witness_evaluator.hpp | 4 +- libraries/chain/staking_evaluator.cpp | 4 +- libraries/chain/witness_evaluator.cpp | 8 +- 10 files changed, 88 insertions(+), 85 deletions(-) diff --git a/libraries/chain/db_balance.cpp b/libraries/chain/db_balance.cpp index 7c3987a3..6ef7f145 100644 --- a/libraries/chain/db_balance.cpp +++ b/libraries/chain/db_balance.cpp @@ -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; diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index a6bcf66d..85e486e9 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -275,8 +275,8 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); - register_evaluator(); - register_evaluator(); + register_evaluator(); + register_evaluator(); } void database::initialize_indexes() diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index df12416d..18e9a10d 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -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().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; @@ -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().indices(); uint32_t count = witness_objects.size(); @@ -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().indices(); - //backup witness vote_reward_pool and total_vote_weights - map wit_reward_pools; - map 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().indices(); + //backup witness vote_reward_pool and total_vote_weights + map wit_reward_pools; + map 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( diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index ad647517..39e78d2d 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -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 { diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 7609a2ef..c86d1d8d 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -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); diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index 743ca00a..18d04bc6 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -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 { @@ -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), diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index 9f1b6958..a4d3e0e6 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -172,15 +172,15 @@ namespace graphene { namespace chain { struct staking_params_t { vector< pair > 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; @@ -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, diff --git a/libraries/chain/include/graphene/chain/witness_evaluator.hpp b/libraries/chain/include/graphene/chain/witness_evaluator.hpp index 521cdc76..a1b41bfc 100644 --- a/libraries/chain/include/graphene/chain/witness_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/witness_evaluator.hpp @@ -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 + class witness_set_commission_evaluator : public evaluator { public: typedef witness_set_commission_operation operation_type; @@ -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 + class witness_unbanned_evaluator : public evaluator { public: typedef witness_unbanned_operation operation_type; diff --git a/libraries/chain/staking_evaluator.cpp b/libraries/chain/staking_evaluator.cpp index 6645d8fa..f64e0398 100644 --- a/libraries/chain/staking_evaluator.cpp +++ b/libraries/chain/staking_evaluator.cpp @@ -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 @@ -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().indices().get().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().indices(); diff --git a/libraries/chain/witness_evaluator.cpp b/libraries/chain/witness_evaluator.cpp index 431e4b6c..2873f8ba 100644 --- a/libraries/chain/witness_evaluator.cpp +++ b/libraries/chain/witness_evaluator.cpp @@ -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); @@ -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( @@ -127,7 +127,7 @@ 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); @@ -135,7 +135,7 @@ void_result wit_banned_remove_evaluator::do_evaluate( const witness_unbanned_ope 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(