From 6b77bdb324c0e858146411a3503e9e0cd8a33a2b Mon Sep 17 00:00:00 2001 From: maslenitsa93 Date: Mon, 17 Sep 2018 10:05:39 +0300 Subject: [PATCH] Fix #533 --- libraries/chain/database.cpp | 17 ++++++++--------- libraries/chain/steem_evaluator.cpp | 12 ++++++------ 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index d2d1b00fec..a8a0b92821 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1892,13 +1892,14 @@ namespace golos { namespace chain { std::nth_element( active.begin(), active.begin() + active.size() / 2, active.end(), [&](const auto* a, const auto* b) { - return a->props.*window / a->props.*items < - b->props.*window / b->props.*items; + 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); } ); - auto* median = active[active.size() / 2]; - std::tie(median_props.*window, median_props.*items) = - std::tie(median->props.*window, median->props.*items); + median_props.*window = active[active.size() / 2]->props.*window; + median_props.*items = active[active.size() / 2]->props.*items; }; calc_median(&chain_properties_17::account_creation_fee); @@ -1911,10 +1912,8 @@ 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_battery(&chain_properties_19::comments_window, - &chain_properties_19::comments_per_window); - calc_median_battery(&chain_properties_19::votes_window, - &chain_properties_19::votes_per_window); + calc_median_battery(&chain_properties_19::comments_window, &chain_properties_19::comments_per_window); + calc_median_battery(&chain_properties_19::votes_window, &chain_properties_19::votes_per_window); modify(wso, [&](witness_schedule_object &_wso) { _wso.median_props = median_props; diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index db727772b3..fedfc062cd 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 = mprops.comments_window / mprops.comments_per_window; + auto consumption = uint16_t(mprops.comments_window / mprops.comments_per_window); - auto regenerated_capacity = std::min(mprops.comments_window, uint16_t(elapsed_seconds)); - auto current_capacity = std::min(uint16_t(auth.comments_capacity + regenerated_capacity), mprops.comments_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)); if (o.parent_author == STEEMIT_ROOT_POST_PARENT) { GOLOS_CHECK_BANDWIDTH(now, band->last_bandwidth_update + STEEMIT_MIN_ROOT_COMMENT_INTERVAL, @@ -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 = mprops.comments_window / mprops.comments_per_window; + auto consumption = uint16_t(mprops.comments_window / mprops.comments_per_window); - auto regenerated_capacity = std::min(mprops.votes_window, uint16_t(elapsed_seconds)); - auto current_capacity = std::min(uint16_t(voter.voting_capacity + regenerated_capacity), mprops.comments_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)); GOLOS_CHECK_BANDWIDTH(current_capacity, consumption, bandwidth_exception::vote_bandwidth,