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

Commit

Permalink
Fix #533
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Sep 11, 2018
1 parent 6c04cdc commit 7356334
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 15 deletions.
4 changes: 4 additions & 0 deletions libraries/api/chain_api_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ namespace golos { namespace api {
max_referral_interest_rate = src.max_referral_interest_rate;
max_referral_term_sec = src.max_referral_term_sec;
max_referral_break_fee = src.max_referral_break_fee;
comments_capacity_100 = src.comments_capacity_100;
comment_consumption = src.comment_consumption;
voting_capacity_100 = src.voting_capacity_100;
voting_consumption = src.voting_consumption;
}
}

Expand Down
8 changes: 7 additions & 1 deletion libraries/api/include/golos/api/chain_api_properties.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ namespace golos { namespace api {
fc::optional<uint16_t> max_referral_interest_rate;
fc::optional<uint32_t> max_referral_term_sec;
fc::optional<asset> max_referral_break_fee;

fc::optional<uint16_t> comments_capacity_100;
fc::optional<uint16_t> comment_consumption;
fc::optional<uint16_t> voting_capacity_100;
fc::optional<uint16_t> voting_consumption;
};

} } // golos::api
Expand All @@ -33,4 +38,5 @@ FC_REFLECT(
(account_creation_fee)(maximum_block_size)(sbd_interest_rate)
(create_account_min_golos_fee)(create_account_min_delegation)
(create_account_delegation_time)(min_delegation)
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee))
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee)
(comments_capacity_100)(comment_consumption)(voting_capacity_100)(voting_consumption))
4 changes: 4 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1898,6 +1898,10 @@ namespace golos { namespace chain {
calc_median(&chain_properties_19::max_referral_interest_rate);
calc_median(&chain_properties_19::max_referral_term_sec);
calc_median(&chain_properties_19::max_referral_break_fee);
calc_median(&chain_properties_19::comments_capacity_100);
calc_median(&chain_properties_19::comment_consumption);
calc_median(&chain_properties_19::voting_capacity_100);
calc_median(&chain_properties_19::voting_consumption);

modify(wso, [&](witness_schedule_object &_wso) {
_wso.median_props = median_props;
Expand Down
32 changes: 20 additions & 12 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,8 @@ namespace golos { namespace chain {
logic_exception::cannot_update_comment_because_nothing_changed,
"Cannot update comment because nothing appears to be changing.");

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

const auto &by_permlink_idx = _db.get_index<comment_index>().indices().get<by_permlink>();
auto itr = by_permlink_idx.find(boost::make_tuple(o.author, o.permlink));

Expand Down Expand Up @@ -571,19 +573,20 @@ namespace golos { namespace chain {
}

int64_t elapsed_seconds = (now - auth.last_post).to_seconds();
int64_t regenerated_capacity = std::min(int64_t(STEEMIT_COMMENTS_CAPACITY_100), int64_t(elapsed_seconds));
int64_t current_capacity = std::min(int64_t(auth.comments_capacity + regenerated_capacity), int64_t(STEEMIT_COMMENTS_CAPACITY_100));
int64_t regenerated_capacity = std::min(int64_t(mprops.comments_capacity_100), int64_t(elapsed_seconds));
int64_t current_capacity = std::min(int64_t(auth.comments_capacity + regenerated_capacity),
int64_t(mprops.comments_capacity_100));

if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__533)) {
if (o.parent_author == STEEMIT_ROOT_POST_PARENT) {
GOLOS_CHECK_BANDWIDTH(now, band->last_bandwidth_update + STEEMIT_MIN_ROOT_COMMENT_INTERVAL,
bandwidth_exception::post_bandwidth,
"You may only post once every 5 minutes.");
} else {
GOLOS_CHECK_BANDWIDTH(current_capacity, STEEMIT_COMMENT_CONSUMPTION,
GOLOS_CHECK_BANDWIDTH(current_capacity, mprops.comment_consumption,
bandwidth_exception::comment_bandwidth,
"You may only comment " + std::to_string(STEEMIT_COMMENTS_CAPACITY_100 / STEEMIT_COMMENT_CONSUMPTION)
+ " times in " + std::to_string(STEEMIT_COMMENTS_CAPACITY_100) + " seconds.");
"You may only comment " + std::to_string(mprops.comments_capacity_100 / mprops.comment_consumption)
+ " times in " + std::to_string(mprops.comments_capacity_100) + " seconds.");
}
} else if (_db.has_hardfork(STEEMIT_HARDFORK_0_12__176)) {
if (o.parent_author == STEEMIT_ROOT_POST_PARENT)
Expand Down Expand Up @@ -639,7 +642,10 @@ namespace golos { namespace chain {
db().modify(auth, [&](account_object &a) {
a.last_post = now;
a.post_count++;
a.comments_capacity = uint16_t(current_capacity - STEEMIT_COMMENT_CONSUMPTION);
if (o.parent_author != STEEMIT_ROOT_POST_PARENT) {
a.comment_count++;
}
a.comments_capacity = uint16_t(current_capacity - mprops.comment_consumption);
});

_db.create<comment_object>([&](comment_object &com) {
Expand Down Expand Up @@ -1185,6 +1191,8 @@ namespace golos { namespace chain {
const auto& comment = _db.get_comment(o.author, o.permlink);
const auto& voter = _db.get_account(o.voter);

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

GOLOS_CHECK_LOGIC(!(voter.owner_challenged || voter.active_challenged),
logic_exception::account_is_currently_challenged,
"Account \"${account}\" is currently challenged", ("account", voter.name));
Expand Down Expand Up @@ -1222,14 +1230,14 @@ namespace golos { namespace chain {
auto itr = comment_vote_idx.find(std::make_tuple(comment.id, voter.id));

int64_t elapsed_seconds = (_db.head_block_time() - voter.last_vote_time).to_seconds();
int64_t regenerated_capacity = std::min(int64_t(STEEMIT_VOTING_CAPACITY_100), int64_t(elapsed_seconds));
int64_t current_capacity = std::min(int64_t(voter.voting_capacity + regenerated_capacity), int64_t(STEEMIT_VOTING_CAPACITY_100));
int64_t regenerated_capacity = std::min(int64_t(mprops.voting_capacity_100), int64_t(elapsed_seconds));
int64_t current_capacity = std::min(int64_t(voter.voting_capacity + regenerated_capacity), int64_t(mprops.voting_capacity_100));

if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__533)) {
GOLOS_CHECK_BANDWIDTH(current_capacity, STEEMIT_VOTING_CONSUMPTION,
GOLOS_CHECK_BANDWIDTH(current_capacity, mprops.voting_consumption,
bandwidth_exception::vote_bandwidth,
"Can only vote " + std::to_string(STEEMIT_VOTING_CAPACITY_100 / STEEMIT_VOTING_CONSUMPTION)
+ " times in " + std::to_string(STEEMIT_VOTING_CAPACITY_100) + " seconds.");
"Can only vote " + std::to_string(mprops.voting_capacity_100 / mprops.voting_consumption)
+ " times in " + std::to_string(mprops.voting_capacity_100) + " seconds.");
} else {
GOLOS_CHECK_BANDWIDTH(_db.head_block_time(), voter.last_vote_time + STEEMIT_MIN_VOTE_INTERVAL_SEC-1,
bandwidth_exception::vote_bandwidth, "Can only vote once every 3 seconds.");
Expand Down Expand Up @@ -1298,7 +1306,7 @@ namespace golos { namespace chain {
_db.modify(voter, [&](account_object &a) {
a.voting_power = current_power - used_power;
a.last_vote_time = _db.head_block_time();
a.voting_capacity = uint16_t(current_capacity - STEEMIT_VOTING_CONSUMPTION);
a.voting_capacity = uint16_t(current_capacity - mprops.voting_consumption);
});

/// if the current net_rshares is less than 0, the post is getting 0 rewards so it is not factored into total rshares^2
Expand Down
23 changes: 22 additions & 1 deletion libraries/protocol/include/golos/protocol/steem_operations.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,26 @@ namespace golos { namespace protocol {
*/
asset max_referral_break_fee = GOLOS_DEFAULT_REFERRAL_BREAK_FEE;

/**
* Total bandwidth battery capacity for comments
*/
uint16_t comments_capacity_100 = STEEMIT_COMMENTS_CAPACITY_100;

/**
* Consumption of bandwidth battery by each comment
*/
uint16_t comment_consumption = STEEMIT_COMMENT_CONSUMPTION;

/**
* Total bandwidth battery capacity for votes
*/
uint16_t voting_capacity_100 = STEEMIT_VOTING_CAPACITY_100;

/**
* Consumption of bandwidth battery by each vote
*/
uint16_t voting_consumption = STEEMIT_VOTING_CONSUMPTION;

void validate() const;

chain_properties_19& operator=(const chain_properties_17& src) {
Expand Down Expand Up @@ -1178,7 +1198,8 @@ FC_REFLECT_DERIVED(
(create_account_delegation_time)(min_delegation))
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))
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee)
(comments_capacity_100)(comment_consumption)(voting_capacity_100)(voting_consumption))

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

Expand Down
8 changes: 7 additions & 1 deletion libraries/wallet/include/golos/wallet/wallet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ namespace golos { namespace wallet {
fc::optional<uint16_t> max_referral_interest_rate;
fc::optional<uint32_t> max_referral_term_sec;
fc::optional<asset> max_referral_break_fee;

fc::optional<uint16_t> comments_capacity_100;
fc::optional<uint16_t> comment_consumption;
fc::optional<uint16_t> voting_capacity_100;
fc::optional<uint16_t> voting_consumption;
};

struct optional_private_box_query {
Expand Down Expand Up @@ -1493,7 +1498,8 @@ FC_REFLECT((golos::wallet::optional_chain_props),
(account_creation_fee)(maximum_block_size)(sbd_interest_rate)
(create_account_min_golos_fee)(create_account_min_delegation)
(create_account_delegation_time)(min_delegation)
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee))
(max_referral_interest_rate)(max_referral_term_sec)(max_referral_break_fee)
(comments_capacity_100)(comment_consumption)(voting_capacity_100)(voting_consumption))

FC_REFLECT(
(golos::wallet::message_body),
Expand Down
8 changes: 8 additions & 0 deletions libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ namespace golos { namespace wallet {
result["max_referral_interest_rate"] = median_props.max_referral_interest_rate;
result["max_referral_term_sec"] = median_props.max_referral_term_sec;
result["max_referral_break_fee"] = median_props.max_referral_break_fee;
result["comments_capacity_100"] = median_props.comments_capacity_100;
result["comment_consumption"] = median_props.comment_consumption;
result["voting_capacity_100"] = median_props.voting_capacity_100;
result["voting_consumption"] = median_props.voting_consumption;
}

return result;
Expand Down Expand Up @@ -2194,6 +2198,10 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st
SET_PROP(max_referral_interest_rate);
SET_PROP(max_referral_term_sec);
SET_PROP(max_referral_break_fee);
SET_PROP(comments_capacity_100);
SET_PROP(comment_consumption);
SET_PROP(voting_capacity_100);
SET_PROP(voting_consumption);
#undef SET_PROP

op.owner = witness_account_name;
Expand Down

0 comments on commit 7356334

Please sign in to comment.