From c881c09cf6d71f8f70cf6b88c179d0a05f611a9e Mon Sep 17 00:00:00 2001 From: AKorpusenko Date: Thu, 23 Aug 2018 14:02:21 +0300 Subject: [PATCH] Made auction window votable. Fixed rewards calculations. #898 --- libraries/api/discussion_helper.cpp | 4 ++++ .../api/include/golos/api/comment_api_object.hpp | 2 ++ libraries/chain/database.cpp | 10 +++++++++- .../chain/include/golos/chain/comment_object.hpp | 2 ++ libraries/chain/steem_evaluator.cpp | 13 ++++++++++--- .../include/golos/protocol/steem_operations.hpp | 14 ++++++++------ libraries/protocol/steem_operations.cpp | 2 +- 7 files changed, 36 insertions(+), 11 deletions(-) diff --git a/libraries/api/discussion_helper.cpp b/libraries/api/discussion_helper.cpp index a901d7664d..7a97eb309b 100644 --- a/libraries/api/discussion_helper.cpp +++ b/libraries/api/discussion_helper.cpp @@ -112,6 +112,7 @@ namespace golos { namespace api { d.allow_replies = o.allow_replies; d.allow_votes = o.allow_votes; d.allow_curation_rewards = o.allow_curation_rewards; + d.auction_window_weight = o.auction_window_weight; for (auto& route : o.beneficiaries) { d.beneficiaries.push_back(route); @@ -191,6 +192,9 @@ namespace golos { namespace api { break; } } + + auto reward_fund_claim = ((max_rewards.value * d.auction_window_weight) / total_weight).to_uint64(); + unclaimed_rewards -= reward_fund_claim; } } else { unclaimed_rewards = 0; diff --git a/libraries/api/include/golos/api/comment_api_object.hpp b/libraries/api/include/golos/api/comment_api_object.hpp index 10d0bc2336..d06446af1f 100644 --- a/libraries/api/include/golos/api/comment_api_object.hpp +++ b/libraries/api/include/golos/api/comment_api_object.hpp @@ -61,6 +61,8 @@ namespace golos { namespace api { comment_mode mode = not_set; comment_object::id_type root_comment; + + uint64_t auction_window_weight = 0; string root_title; diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 441b471336..e35c958868 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1895,7 +1895,7 @@ namespace golos { namespace chain { calc_median(&chain_properties_18::create_account_min_delegation); calc_median(&chain_properties_18::create_account_delegation_time); calc_median(&chain_properties_18::min_delegation); - calc_median(&chain_properties_19::reverse_auction_window_size); + calc_median(&chain_properties_19::auction_window_size); modify(wso, [&](witness_schedule_object &_wso) { _wso.median_props = median_props; @@ -2285,6 +2285,14 @@ namespace golos { namespace chain { unclaimed_rewards = 0; } + if (c.total_vote_weight > 0 && c.allow_curation_rewards) { + auto reward_fund_claim = ((max_rewards.value * c.auction_window_weight) / total_weight).to_uint64(); + unclaimed_rewards -= reward_fund_claim; + modify(get_dynamic_global_properties(), [&](dynamic_global_property_object &props) { + props.total_reward_fund_steem += asset(reward_fund_claim, STEEM_SYMBOL); + }); + } + return unclaimed_rewards; } FC_CAPTURE_AND_RETHROW() } diff --git a/libraries/chain/include/golos/chain/comment_object.hpp b/libraries/chain/include/golos/chain/comment_object.hpp index 24660d3aba..f96f8753c0 100644 --- a/libraries/chain/include/golos/chain/comment_object.hpp +++ b/libraries/chain/include/golos/chain/comment_object.hpp @@ -89,6 +89,8 @@ namespace golos { id_type root_comment; + uint64_t auction_window_weight = 0; + comment_mode mode = first_payout; asset max_accepted_payout = asset(1000000000, SBD_SYMBOL); /// SBD value of the maximum payout this post will receive diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index 98f50681cc..6b5c761c6f 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -1426,16 +1426,23 @@ namespace golos { namespace chain { if (_db.head_block_time() > fc::time_point_sec(STEEMIT_HARDFORK_0_6_REVERSE_AUCTION_TIME)) /// start enforcing this prior to the hardfork - { + { /// discount weight by time + const witness_schedule_object &wso = _db.get_witness_schedule_object(); + const auto &auction_window = wso.median_props.auction_window_size; + uint128_t w(max_vote_weight); uint64_t delta_t = std::min(uint64_t(( cv.last_update - - comment.created).to_seconds()), uint64_t(STEEMIT_REVERSE_AUCTION_WINDOW_SECONDS)); + comment.created).to_seconds()), uint64_t(auction_window)); w *= delta_t; - w /= STEEMIT_REVERSE_AUCTION_WINDOW_SECONDS; + w /= auction_window; cv.weight = w.to_uint64(); + + _db.modify(comment, [&](comment_object &o) { + o.auction_window_weight += max_vote_weight - w.to_uint64(); + }); } } else { cv.weight = 0; diff --git a/libraries/protocol/include/golos/protocol/steem_operations.hpp b/libraries/protocol/include/golos/protocol/steem_operations.hpp index 49076adde3..9d812ed474 100644 --- a/libraries/protocol/include/golos/protocol/steem_operations.hpp +++ b/libraries/protocol/include/golos/protocol/steem_operations.hpp @@ -493,7 +493,7 @@ namespace golos { namespace protocol { sbd_interest_rate = src.sbd_interest_rate; return *this; } - + chain_properties_18& operator=(const chain_properties_18&) = default; chain_properties_18& operator=(const chain_properties_19& src); @@ -504,7 +504,7 @@ namespace golos { namespace protocol { /** * Голосуемый параметр. Штрафное окно голосования */ - uint32_t reverse_auction_window_size = STEEMIT_REVERSE_AUCTION_WINDOW_SECONDS; + uint32_t auction_window_size = STEEMIT_REVERSE_AUCTION_WINDOW_SECONDS; void validate() const; @@ -517,13 +517,15 @@ namespace golos { namespace protocol { } chain_properties_19& operator=(const chain_properties_18& src) { + // 18 create_account_min_golos_fee = src.create_account_min_golos_fee; create_account_min_delegation = src.create_account_min_delegation; create_account_delegation_time = src.create_account_delegation_time; min_delegation = src.min_delegation; - // account_creation_fee = src.account_creation_fee; - // maximum_block_size = src.maximum_block_size; - // sbd_interest_rate = src.sbd_interest_rate; + // 17 + account_creation_fee = src.account_creation_fee; + maximum_block_size = src.maximum_block_size; + sbd_interest_rate = src.sbd_interest_rate; return *this; } @@ -1189,7 +1191,7 @@ FC_REFLECT_DERIVED( (create_account_delegation_time)(min_delegation)) FC_REFLECT_DERIVED( (golos::protocol::chain_properties_19),((golos::protocol::chain_properties_18)), - (reverse_auction_window_size)) + (auction_window_size)) FC_REFLECT_TYPENAME((golos::protocol::versioned_chain_properties)) diff --git a/libraries/protocol/steem_operations.cpp b/libraries/protocol/steem_operations.cpp index bf5110f608..613ae79b84 100644 --- a/libraries/protocol/steem_operations.cpp +++ b/libraries/protocol/steem_operations.cpp @@ -228,7 +228,7 @@ namespace golos { namespace protocol { void chain_properties_19::validate() const { chain_properties_18::validate(); - GOLOS_CHECK_VALUE_GT(reverse_auction_window_size, 0); + GOLOS_CHECK_VALUE_GT(auction_window_size, 0); } void witness_update_operation::validate() const {