Skip to content
This repository has been archived by the owner on Oct 4, 2019. It is now read-only.

Commit

Permalink
Curation rewards percent setting by post author #324
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Oct 29, 2018
1 parent 05fae2b commit 6758618
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 19 deletions.
2 changes: 2 additions & 0 deletions libraries/api/chain_api_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ namespace golos { namespace api {
auction_window_size = src.auction_window_size;
max_delegated_vesting_interest_rate = src.max_delegated_vesting_interest_rate;
custom_ops_bandwidth_multiplier = src.custom_ops_bandwidth_multiplier;
min_curation_percent = src.min_curation_percent;
max_curation_percent = src.max_curation_percent;
}
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/api/discussion_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ namespace golos { namespace api {

uint128_t reward_tokens = uint128_t(payout);

share_type curation_tokens = ((reward_tokens * db.get_curation_rewards_percent())
share_type curation_tokens = ((reward_tokens * d.curation_rewards_percent)
/ STEEMIT_100_PERCENT).to_uint64();
auto crs_unclaimed = get_curator_unclaimed_rewards(d, curation_tokens);
auto crs_claim = curation_tokens - crs_unclaimed;
Expand Down
6 changes: 5 additions & 1 deletion libraries/api/include/golos/api/chain_api_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace golos { namespace api {
fc::optional<uint16_t> max_delegated_vesting_interest_rate;

fc::optional<uint16_t> custom_ops_bandwidth_multiplier;

fc::optional<uint16_t> min_curation_percent;
fc::optional<uint16_t> max_curation_percent;
};

} } // golos::api
Expand All @@ -46,4 +49,5 @@ FC_REFLECT(
(create_account_delegation_time)(min_delegation)
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee)
(comments_window)(comments_per_window)(votes_window)(votes_per_window)(auction_window_size)
(max_delegated_vesting_interest_rate)(custom_ops_bandwidth_multiplier))
(max_delegated_vesting_interest_rate)(custom_ops_bandwidth_multiplier)
(min_curation_percent)(max_curation_percent))
3 changes: 2 additions & 1 deletion libraries/api/include/golos/api/comment_api_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace golos { namespace api {
bool allow_replies = 0;
bool allow_votes = 0;
bool allow_curation_rewards = 0;
uint16_t curation_rewards_percent = 0;

vector< protocol::beneficiary_route_type > beneficiaries;
};
Expand All @@ -91,6 +92,6 @@ FC_REFLECT(
(mode)(auction_window_reward_destination)
(auction_window_size)(auction_window_weight)(votes_in_auction_window_weight)
(root_comment)(root_title)(max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)
(allow_curation_rewards)(beneficiaries))
(allow_curation_rewards)(curation_rewards_percent)(beneficiaries))

#endif //GOLOS_COMMENT_API_OBJ_H
22 changes: 13 additions & 9 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,17 @@ namespace golos { namespace chain {
median_props.*items = active[median]->props.*items;
};

auto calc_median_min_max = [&](auto&& min, auto&& max) {
std::nth_element(
active.begin(), active.begin() + median, active.end(),
[&](const auto* a, const auto* b) {
return std::tie(a->props.*min, a->props.*max) < std::tie(b->props.*min, b->props.*max);
}
);
median_props.*min = active[median]->props.*min;
median_props.*max = active[median]->props.*max;
};

calc_median(&chain_properties_17::account_creation_fee);
calc_median(&chain_properties_17::maximum_block_size);
calc_median(&chain_properties_17::sbd_interest_rate);
Expand All @@ -1917,6 +1928,7 @@ namespace golos { namespace chain {
calc_median_battery(&chain_properties_19::votes_window, &chain_properties_19::votes_per_window);
calc_median(&chain_properties_19::max_delegated_vesting_interest_rate);
calc_median(&chain_properties_19::custom_ops_bandwidth_multiplier);
calc_median_min_max(&chain_properties_19::min_curation_percent, &chain_properties_19::max_curation_percent);

const auto& dynamic_global_properties = get_dynamic_global_properties();

Expand Down Expand Up @@ -2425,7 +2437,7 @@ namespace golos { namespace chain {
asset total_payout;
if (reward_tokens > 0) {
share_type curation_tokens = ((reward_tokens *
get_curation_rewards_percent()) /
comment.curation_rewards_percent) /
STEEMIT_100_PERCENT).to_uint64();

share_type author_tokens = reward_tokens.to_uint64() - curation_tokens;
Expand Down Expand Up @@ -2778,14 +2790,6 @@ namespace golos { namespace chain {
}
}

uint16_t database::get_curation_rewards_percent() const {
if (has_hardfork(STEEMIT_HARDFORK_0_8__116)) {
return STEEMIT_1_PERCENT * 25;
} else {
return STEEMIT_1_PERCENT * 50;
}
}

uint128_t database::get_content_constant_s() const {
return uint128_t(uint64_t(2000000000000ll)); // looking good for posters
}
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/hardfork.d/0_19.hf
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define STEEMIT_HARDFORK_0_19__971 (STEEMIT_HARDFORK_0_19) // Withdraw vests to another account resests on account recover
#define STEEMIT_HARDFORK_0_19__924 (STEEMIT_HARDFORK_0_19) // Bandwidth for custom_json operations
#define STEEMIT_HARDFORK_0_19__952 (STEEMIT_HARDFORK_0_19) // Stop the GBG emission if its count is more than 10%
#define STEEMIT_HARDFORK_0_19__324 (STEEMIT_HARDFORK_0_19) // Add curation rewards percent setting by post author

#ifdef STEEMIT_BUILD_TESTNET
#define STEEMIT_HARDFORK_0_19_TIME 1534755600 // 20 aug 2018 12:00:00 MSK
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/golos/chain/comment_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace golos {
bool allow_replies = true; /// allows a post to disable replies.
bool allow_votes = true; /// allows a post to receive votes;
bool allow_curation_rewards = true;
uint16_t curation_rewards_percent = STEEMIT_MIN_CURATION_PERCENT;

bip::vector <protocol::beneficiary_route_type, allocator<protocol::beneficiary_route_type>> beneficiaries;
};
Expand Down
2 changes: 0 additions & 2 deletions libraries/chain/include/golos/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,6 @@ namespace golos { namespace chain {
asset get_curation_reward() const;
asset get_pow_reward() const;

uint16_t get_curation_rewards_percent() const;

uint128_t get_content_constant_s() const;

uint128_t calculate_vshares(uint128_t rshares) const;
Expand Down
24 changes: 24 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,24 @@ namespace golos { namespace chain {
c.auction_window_reward_destination = cawrd.destination;
});
}

void operator()(const comment_curation_rewards_percent& ccrp) const {
ASSERT_REQ_HF(STEEMIT_HARDFORK_0_19__324, "comment curation rewards percent option");

const auto& mprops = _db.get_witness_schedule_object().median_props;

auto percent = ccrp.percent; // Workaround for correct param name in GOLOS_CHECK_PARAM

GOLOS_CHECK_PARAM(percent, {
GOLOS_CHECK_VALUE(mprops.min_curation_percent <= ccrp.percent && ccrp.percent <= mprops.max_curation_percent,
"Curation rewards percent must be between ${min} and ${max}.",
("min", mprops.min_curation_percent)("max", mprops.max_curation_percent));
});

_db.modify(_c, [&](comment_object& c) {
c.curation_rewards_percent = ccrp.percent;
});
}
};

void comment_options_evaluator::do_apply(const comment_options_operation &o) {
Expand Down Expand Up @@ -779,6 +797,12 @@ namespace golos { namespace chain {
referrer_to_delete = true;
}
}

if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__324)) {
com.curation_rewards_percent = mprops.min_curation_percent;
} else {
com.curation_rewards_percent = STEEMIT_MIN_CURATION_PERCENT;
}
});

if (referrer_to_delete) {
Expand Down
6 changes: 6 additions & 0 deletions libraries/protocol/include/golos/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@
#define STEEMIT_MIN_POW_REWARD STEEMIT_MINING_REWARD
#define STEEMIT_MIN_POW_REWARD_PRE_HF_16 STEEMIT_MINING_REWARD_PRE_HF_16

#define STEEMIT_MIN_CURATION_PERCENT (25*STEEMIT_1_PERCENT) // 25%
#define STEEMIT_MAX_CURATION_PERCENT (90*STEEMIT_1_PERCENT) // 90%

#define STEEMIT_ACTIVE_CHALLENGE_FEE asset(2000, STEEM_SYMBOL)
#define STEEMIT_OWNER_CHALLENGE_FEE asset(30000, STEEM_SYMBOL)
#define STEEMIT_ACTIVE_CHALLENGE_COOLDOWN fc::days(1)
Expand Down Expand Up @@ -374,6 +377,9 @@
#define STEEMIT_MIN_POW_REWARD STEEMIT_MINING_REWARD
#define STEEMIT_MIN_POW_REWARD_PRE_HF_16 STEEMIT_MINING_REWARD_PRE_HF_16

#define STEEMIT_MIN_CURATION_PERCENT (25*STEEMIT_1_PERCENT) // 25%
#define STEEMIT_MAX_CURATION_PERCENT (90*STEEMIT_1_PERCENT) // 90%

#define STEEMIT_ACTIVE_CHALLENGE_FEE asset(2000, STEEM_SYMBOL)
#define STEEMIT_OWNER_CHALLENGE_FEE asset(30000, STEEM_SYMBOL)
#define STEEMIT_ACTIVE_CHALLENGE_COOLDOWN fc::days(1)
Expand Down
29 changes: 27 additions & 2 deletions libraries/protocol/include/golos/protocol/steem_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,23 @@ namespace golos { namespace protocol {
void validate() const;
};

struct comment_curation_rewards_percent {
comment_curation_rewards_percent() {
}

comment_curation_rewards_percent(uint16_t perc)
: percent(perc) {
}

uint16_t percent = STEEMIT_MIN_CURATION_PERCENT;

void validate() const;
};

typedef static_variant <
comment_payout_beneficiaries,
comment_auction_window_reward_destination
comment_auction_window_reward_destination,
comment_curation_rewards_percent
> comment_options_extension;

typedef flat_set <comment_options_extension> comment_options_extensions_type;
Expand Down Expand Up @@ -589,6 +603,16 @@ namespace golos { namespace protocol {
*/
uint16_t custom_ops_bandwidth_multiplier = STEEMIT_CUSTOM_OPS_BANDWIDTH_MULTIPLIER;

/**
* Minimum rate of all curation rewards in total payment
*/
uint16_t min_curation_percent = STEEMIT_MIN_CURATION_PERCENT;

/**
* Maximum rate of all curation rewards in total payment
*/
uint16_t max_curation_percent = STEEMIT_MIN_CURATION_PERCENT; // Min is for compatibility if no voted percents

void validate() const;

chain_properties_19& operator=(const chain_properties_17& src) {
Expand Down Expand Up @@ -1301,7 +1325,7 @@ FC_REFLECT_DERIVED(
(golos::protocol::chain_properties_19), ((golos::protocol::chain_properties_18)),
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee)
(comments_window)(comments_per_window)(votes_window)(votes_per_window)(auction_window_size)
(max_delegated_vesting_interest_rate)(custom_ops_bandwidth_multiplier))
(max_delegated_vesting_interest_rate)(custom_ops_bandwidth_multiplier)(min_curation_percent)(max_curation_percent))

FC_REFLECT_TYPENAME((golos::protocol::versioned_chain_properties))

Expand Down Expand Up @@ -1356,6 +1380,7 @@ FC_REFLECT((golos::protocol::beneficiary_route_type), (account)(weight))
FC_REFLECT_ENUM(golos::protocol::auction_window_reward_destination_type, (to_reward_fund)(to_curators)(to_author))
FC_REFLECT((golos::protocol::comment_payout_beneficiaries), (beneficiaries));
FC_REFLECT((golos::protocol::comment_auction_window_reward_destination), (destination));
FC_REFLECT((golos::protocol::comment_curation_rewards_percent), (percent));
FC_REFLECT_TYPENAME((golos::protocol::comment_options_extension));
FC_REFLECT((golos::protocol::comment_options_operation), (author)(permlink)(max_accepted_payout)(percent_steem_dollars)(allow_votes)(allow_curation_rewards)(extensions))

Expand Down
14 changes: 14 additions & 0 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ namespace golos { namespace protocol {
void operator()( const comment_auction_window_reward_destination& cawrd ) const {
cawrd.validate();
}

void operator()(const comment_curation_rewards_percent& ccrp) const {
ccrp.validate();
}
};

void comment_payout_beneficiaries::validate() const {
Expand Down Expand Up @@ -167,6 +171,14 @@ namespace golos { namespace protocol {
});
}

void comment_curation_rewards_percent::validate() const {
GOLOS_CHECK_PARAM(percent, {
GOLOS_CHECK_VALUE(STEEMIT_MIN_CURATION_PERCENT <= percent && percent <= STEEMIT_MAX_CURATION_PERCENT,
"Curation rewards percent must be between ${min} and ${max}.",
("min", STEEMIT_MIN_CURATION_PERCENT)("max", STEEMIT_MAX_CURATION_PERCENT));
});
}

void comment_options_operation::validate() const {
GOLOS_CHECK_PARAM_ACCOUNT(author);
GOLOS_CHECK_PARAM(percent_steem_dollars, GOLOS_CHECK_VALUE_LE(percent_steem_dollars, STEEMIT_100_PERCENT));
Expand Down Expand Up @@ -274,6 +286,8 @@ namespace golos { namespace protocol {
GOLOS_CHECK_VALUE_LEGE(votes_per_window, 1, votes_window);
GOLOS_CHECK_VALUE_LE(max_delegated_vesting_interest_rate, STEEMIT_MAX_DELEGATED_VESTING_INTEREST_RATE);
GOLOS_CHECK_VALUE_GE(custom_ops_bandwidth_multiplier, 1);
GOLOS_CHECK_VALUE_LEGE(min_curation_percent, STEEMIT_MIN_CURATION_PERCENT, max_curation_percent);
GOLOS_CHECK_VALUE_LEGE(max_curation_percent, min_curation_percent, STEEMIT_MAX_CURATION_PERCENT);
}

void witness_update_operation::validate() const {
Expand Down
5 changes: 4 additions & 1 deletion libraries/wallet/include/golos/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ namespace golos { namespace wallet {
fc::optional<uint16_t> max_delegated_vesting_interest_rate;

fc::optional<uint32_t> custom_ops_bandwidth_multiplier;

fc::optional<uint16_t> min_curation_percent;
fc::optional<uint16_t> max_curation_percent;
};

struct optional_private_box_query {
Expand Down Expand Up @@ -1547,7 +1550,7 @@ FC_REFLECT((golos::wallet::optional_chain_props),
(create_account_delegation_time)(min_delegation)
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee)
(comments_window)(comments_per_window)(votes_window)(votes_per_window)(auction_window_size)
(max_delegated_vesting_interest_rate)(custom_ops_bandwidth_multiplier))
(max_delegated_vesting_interest_rate)(custom_ops_bandwidth_multiplier)(min_curation_percent)(max_curation_percent))

FC_REFLECT(
(golos::wallet::message_body),
Expand Down
7 changes: 6 additions & 1 deletion libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ namespace golos { namespace wallet {
result["auction_window_size"] = median_props.auction_window_size;
result["max_delegated_vesting_interest_rate"] = median_props.max_delegated_vesting_interest_rate;
result["custom_ops_bandwidth_multiplier"] = median_props.custom_ops_bandwidth_multiplier;
result["min_curation_percent"] = median_props.min_curation_percent;
result["max_curation_percent"] = median_props.max_curation_percent;
}

return result;
Expand Down Expand Up @@ -2278,7 +2280,8 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
if (hf >= hardfork_version(0, STEEMIT_HARDFORK_0_19) || !!props.max_referral_interest_rate
|| !!props.max_referral_term_sec || !!props.max_referral_break_fee || !!props.comments_window
|| !!props.comments_per_window || !!props.votes_window || !!props.votes_per_window
|| !!props.auction_window_size || !!props.max_delegated_vesting_interest_rate || !!props.custom_ops_bandwidth_multiplier) {
|| !!props.auction_window_size || !!props.max_delegated_vesting_interest_rate || !!props.custom_ops_bandwidth_multiplier
|| !!props.min_curation_percent || !!props.max_curation_percent) {
chain_properties_19 p19;
p19 = p;
SET_PROP(p19, max_referral_interest_rate);
Expand All @@ -2291,6 +2294,8 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
SET_PROP(p19, auction_window_size);
SET_PROP(p19, max_delegated_vesting_interest_rate);
SET_PROP(p19, custom_ops_bandwidth_multiplier);
SET_PROP(p19, min_curation_percent);
SET_PROP(p19, max_curation_percent);
op.props = p19;
}
#undef SET_PROP
Expand Down
2 changes: 1 addition & 1 deletion tests/common/comment_reward.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ namespace golos { namespace chain {

void calculate_rewards() {
comment_rewards_ = fund_.claim_comment_reward(comment_).amount.value;
vote_rewards_fund_ = comment_rewards_ * STEEMIT_1_PERCENT * 25 / STEEMIT_100_PERCENT;
vote_rewards_fund_ = comment_rewards_ * comment_.curation_rewards_percent / STEEMIT_100_PERCENT;
}

void calculate_vote_payouts() {
Expand Down
Loading

0 comments on commit 6758618

Please sign in to comment.