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

Commit

Permalink
changing limits for comments and votes #533
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Sep 10, 2018
1 parent 0d44ab9 commit 36ef088
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 14 deletions.
2 changes: 2 additions & 0 deletions libraries/chain/include/golos/chain/account_object.hpp
Expand Up @@ -50,6 +50,8 @@ class account_object

bool can_vote = true;
uint16_t voting_power = STEEMIT_100_PERCENT; ///< current voting power of this account, it falls after every vote
uint16_t comments_capacity = STEEMIT_COMMENTS_CAPACITY_100;
uint16_t voting_capacity = STEEMIT_VOTING_CAPACITY_100;
time_point_sec last_vote_time; ///< used to increase the voting power of this account the longer it goes without voting.

asset balance = asset(0, STEEM_SYMBOL); ///< total liquid shares held by this account
Expand Down
41 changes: 27 additions & 14 deletions libraries/chain/steem_evaluator.cpp
Expand Up @@ -569,29 +569,36 @@ namespace golos { namespace chain {
b.type = bandwidth_type::post;
});
}

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));

if (_db.has_hardfork(STEEMIT_HARDFORK_0_12__176)) {
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.");
bandwidth_exception::post_bandwidth,
"You may only post once every 5 minutes.");
else
GOLOS_CHECK_BANDWIDTH(now, auth.last_post + STEEMIT_MIN_REPLY_INTERVAL,
golos::bandwidth_exception::comment_bandwidth,
"You may only comment once every 20 seconds.");
GOLOS_CHECK_BANDWIDTH(current_capacity, STEEMIT_COMMENT_CONSUMPTION,
golos::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.");
} else if (_db.has_hardfork(STEEMIT_HARDFORK_0_6__113)) {
if (o.parent_author == STEEMIT_ROOT_POST_PARENT)
GOLOS_CHECK_BANDWIDTH(now, auth.last_post + STEEMIT_MIN_ROOT_COMMENT_INTERVAL,
bandwidth_exception::post_bandwidth,
"You may only post once every 5 minutes.");
else
GOLOS_CHECK_BANDWIDTH(now, auth.last_post + STEEMIT_MIN_REPLY_INTERVAL,
bandwidth_exception::post_bandwidth,
"You may only post once every 5 minutes.");
else {
GOLOS_CHECK_BANDWIDTH(current_capacity, STEEMIT_COMMENT_CONSUMPTION,
bandwidth_exception::comment_bandwidth,
"You may only comment once every 20 seconds.");
"You may only comment " + std::to_string(STEEMIT_COMMENTS_CAPACITY_100 / STEEMIT_COMMENT_CONSUMPTION) +
" times in " + std::to_string(STEEMIT_COMMENTS_CAPACITY_100) + " seconds.");
}
} else {
GOLOS_CHECK_BANDWIDTH(now, auth.last_post + 60,
bandwidth_exception::post_bandwidth,
"You may only post once per minute.");
bandwidth_exception::post_bandwidth,
"You may only post once per minute.");
}

uint16_t reward_weight = STEEMIT_100_PERCENT;
Expand Down Expand Up @@ -624,6 +631,7 @@ 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);
});

_db.create<comment_object>([&](comment_object &com) {
Expand Down Expand Up @@ -1206,9 +1214,13 @@ 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));

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.");
GOLOS_CHECK_BANDWIDTH(current_capacity, STEEMIT_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.");

int64_t regenerated_power =
(STEEMIT_100_PERCENT * elapsed_seconds) /
Expand Down Expand Up @@ -1273,6 +1285,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);
});

/// 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
10 changes: 10 additions & 0 deletions libraries/protocol/include/golos/protocol/config.hpp
Expand Up @@ -80,6 +80,11 @@
#define STEEMIT_POST_MAX_BANDWIDTH (4*STEEMIT_100_PERCENT) // 2 posts per 1 days, average 1 every 12 hours
#define STEEMIT_POST_WEIGHT_CONSTANT (uint64_t(STEEMIT_POST_MAX_BANDWIDTH) * STEEMIT_POST_MAX_BANDWIDTH)

#define STEEMIT_COMMENTS_CAPACITY_100 200
#define STEEMIT_COMMENT_CONSUMPTION 20
#define STEEMIT_VOTING_CAPACITY_100 30
#define STEEMIT_VOTING_CONSUMPTION 10

#define STEEMIT_MAX_ACCOUNT_WITNESS_VOTES 30

#define STEEMIT_100_PERCENT 10000
Expand Down Expand Up @@ -295,6 +300,11 @@
#define STEEMIT_POST_MAX_BANDWIDTH (4*STEEMIT_100_PERCENT) // 2 posts per 1 days, average 1 every 12 hours
#define STEEMIT_POST_WEIGHT_CONSTANT (uint64_t(STEEMIT_POST_MAX_BANDWIDTH) * STEEMIT_POST_MAX_BANDWIDTH)

#define STEEMIT_COMMENTS_CAPACITY_100 200
#define STEEMIT_COMMENT_CONSUMPTION 20
#define STEEMIT_VOTING_CAPACITY_100 30
#define STEEMIT_VOTING_CONSUMPTION 10

#define STEEMIT_MAX_ACCOUNT_WITNESS_VOTES 30

#define STEEMIT_100_PERCENT 10000
Expand Down

0 comments on commit 36ef088

Please sign in to comment.