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

Commit

Permalink
Fix #533
Browse files Browse the repository at this point in the history
  • Loading branch information
maslenitsa93 committed Sep 17, 2018
1 parent 6b77bdb commit 40f6018
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
15 changes: 8 additions & 7 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -1238,18 +1238,18 @@ 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,
"Can only vote ${votes_per_window} times in ${votes_window} seconds.",
("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,
Expand Down
4 changes: 2 additions & 2 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>::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<uint16_t>::max() / 2);
GOLOS_CHECK_VALUE_LEGE(votes_per_window, 1, votes_window);
}

Expand Down

0 comments on commit 40f6018

Please sign in to comment.