From 6c04cdc3de90818e67baf39de7f2576cbdf549e8 Mon Sep 17 00:00:00 2001 From: maslenitsa93 Date: Tue, 11 Sep 2018 01:03:39 +0300 Subject: [PATCH] New limits algorithm for comments and votes #533 --- libraries/chain/hardfork.d/0_19.hf | 1 + .../include/golos/chain/account_object.hpp | 2 ++ libraries/chain/steem_evaluator.cpp | 32 +++++++++++++++++-- .../include/golos/protocol/config.hpp | 10 ++++++ 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/libraries/chain/hardfork.d/0_19.hf b/libraries/chain/hardfork.d/0_19.hf index b41daace4d..2faea5e01f 100644 --- a/libraries/chain/hardfork.d/0_19.hf +++ b/libraries/chain/hardfork.d/0_19.hf @@ -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 diff --git a/libraries/chain/include/golos/chain/account_object.hpp b/libraries/chain/include/golos/chain/account_object.hpp index d3ce6b3de5..5a3d813087 100644 --- a/libraries/chain/include/golos/chain/account_object.hpp +++ b/libraries/chain/include/golos/chain/account_object.hpp @@ -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 diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index 98f50681cc..3c337107dd 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -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, @@ -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 &com) { @@ -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) / @@ -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 diff --git a/libraries/protocol/include/golos/protocol/config.hpp b/libraries/protocol/include/golos/protocol/config.hpp index 4efb17976d..2bfe4f00bb 100644 --- a/libraries/protocol/include/golos/protocol/config.hpp +++ b/libraries/protocol/include/golos/protocol/config.hpp @@ -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 @@ -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