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

Commit

Permalink
New limits algorithm for comments and votes #533
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Sep 11, 2018
1 parent 0d44ab9 commit 6c04cdc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
1 change: 1 addition & 0 deletions libraries/chain/hardfork.d/0_19.hf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef STEEMIT_HARDFORK_0_19
#define STEEMIT_HARDFORK_0_19 19
#define STEEMIT_HARDFORK_0_19__533 (STEEMIT_HARDFORK_0_19) // Leaky algorithm for comment and vote bandwidth

#ifdef STEEMIT_BUILD_TESTNET
#define STEEMIT_HARDFORK_0_19_TIME 1534755600 // 20 aug 2018 12:00:00 MSK
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/golos/chain/account_object.hpp
Original file line number Diff line number Diff line change
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
32 changes: 29 additions & 3 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,22 @@ namespace golos { namespace chain {
});
}

if (_db.has_hardfork(STEEMIT_HARDFORK_0_12__176)) {
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_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,
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_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,
Expand Down Expand Up @@ -624,6 +639,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 +1222,18 @@ 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();

GOLOS_CHECK_BANDWIDTH(_db.head_block_time(), voter.last_vote_time + STEEMIT_MIN_VOTE_INTERVAL_SEC-1,
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));

if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__533)) {
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.");
} 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.");
}

int64_t regenerated_power =
(STEEMIT_100_PERCENT * elapsed_seconds) /
Expand Down Expand Up @@ -1273,6 +1298,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
Original file line number Diff line number Diff line change
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 15
#define STEEMIT_VOTING_CONSUMPTION 3

#define STEEMIT_MAX_ACCOUNT_WITNESS_VOTES 30

#define STEEMIT_100_PERCENT 10000
Expand Down

0 comments on commit 6c04cdc

Please sign in to comment.