diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 18e9a10d..2531e80c 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -273,6 +273,23 @@ void database::update_active_committee_members() }); } FC_CAPTURE_AND_RETHROW() } +void database::handling_expired_staking(const staking_object& staking_obj,const witness_id_type& witness_id){ + //staking expire + const auto& witness_objects = get_index_type().indices(); + auto wit_obj_itor = witness_objects.find(witness_id); + if(staking_obj.staking_days * SECONDS_PER_DAY < (head_block_time().sec_since_epoch() - staking_obj.create_date_time.sec_since_epoch())&& + wit_obj_itor != witness_objects.end()){ + modify(staking_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 = staking_obj.amount.amount * staking_obj.weight; + share_type reduce_vote_weights = std::min(total_vote_weights, obj.total_vote_weights); + obj.total_vote_weights -= reduce_vote_weights; + }); + } +} void database::initialize_budget_record( fc::time_point_sec now, budget_record& rec )const { const dynamic_global_property_object& dpo = get_dynamic_global_properties(); @@ -764,19 +781,13 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g 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; - }); - } + if(head_block_time() <= HARDFORK_1026_TIME){ + handling_expired_staking(stak_obj,stak_obj.trust_node); + } } + if(head_block_time() > HARDFORK_1026_TIME){ + handling_expired_staking(stak_obj,stak_obj.trust_node); + } } } } diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index c86d1d8d..f034542b 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -458,6 +458,7 @@ namespace graphene { namespace chain { void update_active_witnesses(); void update_active_committee_members(); void update_worker_votes(); + void handling_expired_staking(const staking_object& staking_obj,const witness_id_type& witness_id); template void perform_account_maintenance(std::tuple helpers); diff --git a/libraries/chain/include/graphene/chain/hardfork.hpp b/libraries/chain/include/graphene/chain/hardfork.hpp index b37dc99a..90570f57 100644 --- a/libraries/chain/include/graphene/chain/hardfork.hpp +++ b/libraries/chain/include/graphene/chain/hardfork.hpp @@ -136,6 +136,11 @@ #define HARDFORK_1025_TIME (fc::time_point_sec( 1579147200 )) // for testnet, 2020-01-16T04:00:00(UTC) #endif +#ifndef HARDFORK_1026_TIME +// for testnet after this time fix staking_object expire check logic +#define HARDFORK_1026_TIME (fc::time_point_sec( 1580810400 )) // for testnet, 2020-02-04T10:00:00(UTC) +#endif + // #413 Add operation to claim asset fees #ifndef HARDFORK_413_TIME #define HARDFORK_413_TIME (fc::time_point_sec( 1446652800 ))