From 40f601869ad6d631de3eeb4177461657aca50dcb Mon Sep 17 00:00:00 2001 From: maslenitsa93 Date: Mon, 17 Sep 2018 13:57:55 +0300 Subject: [PATCH] Fix #533 --- libraries/chain/database.cpp | 15 ++++++++------- libraries/chain/steem_evaluator.cpp | 12 ++++++------ libraries/protocol/steem_operations.cpp | 4 ++-- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index a8a0b92821..555995c7a1 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1878,28 +1878,29 @@ namespace golos { namespace chain { chain_properties_19 median_props; + auto median = active.size() / 2; + auto calc_median = [&](auto&& param) { std::nth_element( - active.begin(), active.begin() + active.size() / 2, active.end(), + active.begin(), active.begin() + median, active.end(), [&](const auto* a, const auto* b) { return a->props.*param < b->props.*param; } ); - median_props.*param = active[active.size() / 2]->props.*param; + median_props.*param = active[median]->props.*param; }; auto calc_median_battery = [&](auto&& window, auto&& items) { std::nth_element( - active.begin(), active.begin() + active.size() / 2, active.end(), + active.begin(), active.begin() + median, active.end(), [&](const auto* a, const auto* b) { auto a_consumption = a->props.*window / a->props.*items; auto b_consumption = b->props.*window / b->props.*items; - return std::tie(a_consumption, a->props.*items) < - std::tie(b_consumption, b->props.*items); + return std::tie(a_consumption, a->props.*items) < std::tie(b_consumption, b->props.*items); } ); - median_props.*window = active[active.size() / 2]->props.*window; - median_props.*items = active[active.size() / 2]->props.*items; + median_props.*window = active[median]->props.*window; + median_props.*items = active[median]->props.*items; }; calc_median(&chain_properties_17::account_creation_fee); diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index fedfc062cd..c1e44110d7 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -575,10 +575,10 @@ namespace golos { namespace chain { auto elapsed_seconds = (now - auth.last_post).to_seconds(); if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__533)) { - auto consumption = uint16_t(mprops.comments_window / mprops.comments_per_window); + auto consumption = mprops.comments_window / mprops.comments_per_window; auto regenerated_capacity = std::min(uint32_t(mprops.comments_window), uint32_t(elapsed_seconds)); - auto current_capacity = std::min(uint32_t(auth.comments_capacity + regenerated_capacity), uint32_t(mprops.comments_window)); + auto current_capacity = std::min(uint16_t(auth.comments_capacity + regenerated_capacity), mprops.comments_window); if (o.parent_author == STEEMIT_ROOT_POST_PARENT) { GOLOS_CHECK_BANDWIDTH(now, band->last_bandwidth_update + STEEMIT_MIN_ROOT_COMMENT_INTERVAL, @@ -592,7 +592,7 @@ namespace golos { namespace chain { } db().modify(auth, [&](account_object &a) { - a.comments_capacity = uint16_t(current_capacity - consumption); + a.comments_capacity = current_capacity - consumption; }); } else if (_db.has_hardfork(STEEMIT_HARDFORK_0_12__176)) { if (o.parent_author == STEEMIT_ROOT_POST_PARENT) @@ -1238,10 +1238,10 @@ namespace golos { namespace chain { auto elapsed_seconds = (_db.head_block_time() - voter.last_vote_time).to_seconds(); if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__533)) { - auto consumption = uint16_t(mprops.comments_window / mprops.comments_per_window); + auto consumption = mprops.votes_window / mprops.votes_per_window; auto regenerated_capacity = std::min(uint32_t(mprops.votes_window), uint32_t(elapsed_seconds)); - auto current_capacity = std::min(uint32_t(voter.voting_capacity + regenerated_capacity), uint32_t(mprops.comments_window)); + auto current_capacity = std::min(uint16_t(voter.voting_capacity + regenerated_capacity), mprops.votes_window); GOLOS_CHECK_BANDWIDTH(current_capacity, consumption, bandwidth_exception::vote_bandwidth, @@ -1249,7 +1249,7 @@ namespace golos { namespace chain { ("votes_per_window", mprops.votes_per_window)("votes_window", mprops.votes_window)); _db.modify(voter, [&](account_object &a) { - a.voting_capacity = uint16_t(current_capacity - consumption); + a.voting_capacity = current_capacity - consumption; }); } else { GOLOS_CHECK_BANDWIDTH(_db.head_block_time(), voter.last_vote_time + STEEMIT_MIN_VOTE_INTERVAL_SEC-1, diff --git a/libraries/protocol/steem_operations.cpp b/libraries/protocol/steem_operations.cpp index deb5fb9ff3..7b1db6d89f 100644 --- a/libraries/protocol/steem_operations.cpp +++ b/libraries/protocol/steem_operations.cpp @@ -231,9 +231,9 @@ namespace golos { namespace protocol { GOLOS_CHECK_VALUE_LE(max_referral_interest_rate, GOLOS_MAX_REFERRAL_INTEREST_RATE); GOLOS_CHECK_VALUE_LE(max_referral_term_sec, GOLOS_MAX_REFERRAL_TERM_SEC); GOLOS_CHECK_VALUE_LEGE(max_referral_break_fee.amount, 0, GOLOS_MAX_REFERRAL_BREAK_FEE.amount); - GOLOS_CHECK_VALUE_GE(comments_window, 1); + GOLOS_CHECK_VALUE_LEGE(comments_window, 1, std::numeric_limits::max() / 2); GOLOS_CHECK_VALUE_LEGE(comments_per_window, 1, comments_window); - GOLOS_CHECK_VALUE_GE(votes_window, 1); + GOLOS_CHECK_VALUE_LEGE(votes_window, 1, std::numeric_limits::max() / 2); GOLOS_CHECK_VALUE_LEGE(votes_per_window, 1, votes_window); }