Skip to content

Commit

Permalink
fix: fix staking failing to take out when expire
Browse files Browse the repository at this point in the history
  • Loading branch information
RootkitKiller committed Feb 4, 2020
1 parent cb496c9 commit 91f2e5c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
35 changes: 23 additions & 12 deletions libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<witness_index>().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();
Expand Down Expand Up @@ -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);
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/graphene/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<class... Types>
void perform_account_maintenance(std::tuple<Types...> helpers);
Expand Down
5 changes: 5 additions & 0 deletions libraries/chain/include/graphene/chain/hardfork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ))
Expand Down

0 comments on commit 91f2e5c

Please sign in to comment.