-
Notifications
You must be signed in to change notification settings - Fork 36
New limits algorithm for comments and votes #533 #825 #951
New limits algorithm for comments and votes #533 #825 #951
Conversation
573a29a
to
6c04cdc
Compare
594a779
to
aec2ec2
Compare
libraries/chain/database.cpp
Outdated
std::nth_element( | ||
active.begin(), active.begin() + active.size() / 2, active.end(), | ||
[&](const auto* a, const auto* b) { | ||
return a->props.*sort_by < b->props.*sort_by; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use std::tie()
in this place.
aec2ec2
to
208c949
Compare
libraries/chain/database.cpp
Outdated
active.begin(), active.begin() + active.size() / 2, active.end(), | ||
[&](const auto* a, const auto* b) { | ||
return std::tie(a->props.*window, a->props.*items) < | ||
std::tie(b->props.*window, b->props.*items); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix sorting of items.
Example:
10 10
25 5
50 1 <----
75 75
100 100
window 50
and items 1
is a very bad case in comparing with others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afalaleev Which case is good for this example?
What if sort by consumption (window / items) and use median?
libraries/chain/steem_evaluator.cpp
Outdated
GOLOS_CHECK_BANDWIDTH(current_capacity, consumption, | ||
bandwidth_exception::vote_bandwidth, | ||
"Can only vote ${vpw} times in ${vw} seconds.", | ||
("cpw", mprops.votes_per_window)("cw", mprops.votes_window)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Give items normal names, they are used by clients to detect errors.
You should figure out how the errors subsystem works.
libraries/wallet/wallet.cpp
Outdated
@@ -2194,6 +2198,10 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st | |||
SET_PROP(max_referral_interest_rate); | |||
SET_PROP(max_referral_term_sec); | |||
SET_PROP(max_referral_break_fee); | |||
SET_PROP(comments_window); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here should be different types of chain_properties.
You will merge changes in other commit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afalaleev Yes, will fix conflicts after all work.
libraries/chain/database.cpp
Outdated
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 < |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix sorting function, you should use std::tie()
.
Example from issue:
window | items
-------------------
20 | 1
200 | 10
These two settings are not the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afalaleev Which of these 2 settings should be selected? What behaviour do you want in result?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afalaleev Here is window / items
(let's write "/" only with spaces - otherwise it could be misleaded with OR), not std::tie
.
How could I use tie if it gives bad result here: https://pastebin.com/VwB470nz
libraries/chain/database.cpp
Outdated
); | ||
auto* median = active[active.size() / 2]; | ||
std::tie(median_props.*window, median_props.*items) = | ||
std::tie(median->props.*window, median->props.*items); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coping of values is more simple for understand.
libraries/chain/database.cpp
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change typing to one line.
libraries/chain/steem_evaluator.cpp
Outdated
if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__533)) { | ||
auto consumption = mprops.comments_window / mprops.comments_per_window; | ||
|
||
auto regenerated_capacity = std::min(mprops.votes_window, uint16_t(elapsed_seconds)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After 4,5 hours there will be an overflow.
libraries/chain/steem_evaluator.cpp
Outdated
if (_db.has_hardfork(STEEMIT_HARDFORK_0_19__533)) { | ||
auto consumption = mprops.comments_window / mprops.comments_per_window; | ||
|
||
auto regenerated_capacity = std::min(mprops.comments_window, uint16_t(elapsed_seconds)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After 4,5 hours there will be an overflow.
libraries/chain/database.cpp
Outdated
[&](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) < |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To one line.
libraries/chain/steem_evaluator.cpp
Outdated
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments?
libraries/chain/steem_evaluator.cpp
Outdated
auto consumption = uint16_t(mprops.comments_window / mprops.comments_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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as for comments.
libraries/chain/steem_evaluator.cpp
Outdated
auto consumption = uint16_t(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)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto consumption = mprops.comments_window / mprops.comments_per_window;
auto regenerated_capacity = std::min(uint32_t(mprops.comments_window), elapsed_seconds);
auto current_capacity = std::min(uint16_t(auth.comments_capacity + regenerated_capacity), mprops.comments_window);
libraries/chain/steem_evaluator.cpp
Outdated
} | ||
|
||
db().modify(auth, [&](account_object &a) { | ||
a.comments_capacity = uint16_t(current_capacity - consumption); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
current_capacity is already uint16_t
, see comment above
libraries/chain/steem_evaluator.cpp
Outdated
|
||
GOLOS_CHECK_BANDWIDTH(_db.head_block_time(), voter.last_vote_time + STEEMIT_MIN_VOTE_INTERVAL_SEC-1, | ||
_db.modify(voter, [&](account_object &a) { | ||
a.voting_capacity = uint16_t(current_capacity - consumption); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same as for comments.
@@ -231,6 +231,10 @@ 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_per_window, 1, comments_window); | |||
GOLOS_CHECK_VALUE_GE(votes_window, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add upper limit on std::numeric_limits<uint16_t>::max() / 2
@@ -231,6 +231,10 @@ 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add upper limit on std::numeric_limits<uint16_t>::max() / 2
libraries/chain/database.cpp
Outdated
@@ -1888,6 +1888,20 @@ namespace golos { namespace chain { | |||
median_props.*param = active[active.size() / 2]->props.*param; | |||
}; | |||
|
|||
auto calc_median_battery = [&](auto&& window, auto&& items) { | |||
std::nth_element( | |||
active.begin(), active.begin() + active.size() / 2, active.end(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be add median = active.size() / 2
? It is used 3 times in this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Rebase to one commit.
c092dcb
to
b7b83f0
Compare
Rebased, conflicts fixed. |
b7b83f0
to
db4e008
Compare
libraries/wallet/wallet.cpp
Outdated
@@ -2228,7 +2232,7 @@ fc::ecc::private_key wallet_api::derive_private_key(const std::string& prefix_st | |||
signed_transaction tx; | |||
chain_properties_update_operation op; | |||
chain_api_properties ap; | |||
chain_properties_18 p; | |||
chain_properties p; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You break compatibility with old nodes with daemon version less HF19.
Return back the previous implementation.
libraries/wallet/wallet.cpp
Outdated
SET_PROP(p19, max_referral_break_fee); | ||
op.props = p19; | ||
} | ||
#define SET_PROP(X) {if (!!props.X) p.X = *(props.X); else if (!!ap.X) p.X = *(ap.X);} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return back the previous implementation:
if (hf >= hardfork_version(0, STEEMIT_HARDFORK_0_19) || !!props.max_referral_interest_rate || !!props.max_referral_term_sec || !!props.max_referral_break_fee) {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@afalaleev Okay. But I forgot - should I add also checks on 533's properties into this if
or not?
If should - why we not implemented it in this branch and you approved without it...
db4e008
to
c0b818d
Compare
c0b818d
to
e649b1d
Compare
#533 #825
Checklists:
Use testnet.
Run daemon.
Wait for hardfork 19.
Run following script for comments:
Or this one for votes:
It will fail with bandwidth_exception. Wait for few seconds and run again - it will end successfully.