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

Commit b6e5162

Browse files
authored
Merge pull request #453 from GolosChain/452-recalculate-rshares2-on-switch-to-hf17
Recalculate rshares2 on switch to hf17 #452
2 parents 7fa1893 + fcee292 commit b6e5162

File tree

9 files changed

+38
-57
lines changed

9 files changed

+38
-57
lines changed

libraries/chain/database.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,8 +1991,7 @@ namespace golos {
19911991
claim_rshare_reward(
19921992
comment.net_rshares,
19931993
comment.reward_weight,
1994-
to_steem(comment.max_accepted_payout),
1995-
comment.curve));
1994+
to_steem(comment.max_accepted_payout)));
19961995

19971996
asset total_payout;
19981997
if (reward_tokens > 0) {
@@ -2061,7 +2060,7 @@ namespace golos {
20612060

20622061
}
20632062

2064-
fc::uint128_t old_rshares2 = calculate_vshares(comment.net_rshares.value, comment.curve);
2063+
fc::uint128_t old_rshares2 = calculate_vshares(comment.net_rshares.value);
20652064
adjust_rshares2(comment, old_rshares2, 0);
20662065
}
20672066

@@ -2430,14 +2429,11 @@ namespace golos {
24302429
return (rshares + s) * (rshares + s) - s * s;
24312430
}
24322431

2433-
uint128_t database::calculate_vshares(uint128_t rshares, reward_curve curve) const {
2434-
switch (curve) {
2435-
case reward_curve::linear:
2436-
return calculate_vshares_linear(rshares);
2437-
2438-
case reward_curve::quadratic:
2439-
default:
2440-
return calculate_vshares_quadratic(rshares, get_content_constant_s());
2432+
uint128_t database::calculate_vshares(uint128_t rshares) const {
2433+
if (has_hardfork(STEEMIT_HARDFORK_0_17__433)) {
2434+
return calculate_vshares_linear(rshares);
2435+
} else {
2436+
return calculate_vshares_quadratic(rshares, get_content_constant_s());
24412437
}
24422438
}
24432439

@@ -2510,9 +2506,7 @@ namespace golos {
25102506
* This method reduces the rshare^2 supply and returns the number of tokens are
25112507
* redeemed.
25122508
*/
2513-
share_type database::claim_rshare_reward(
2514-
share_type rshares, uint16_t reward_weight, asset max_steem, reward_curve curve
2515-
) {
2509+
share_type database::claim_rshare_reward(share_type rshares, uint16_t reward_weight, asset max_steem) {
25162510
try {
25172511
FC_ASSERT(rshares > 0);
25182512

@@ -2522,7 +2516,7 @@ namespace golos {
25222516
u256 rf(props.total_reward_fund_steem.amount.value);
25232517
u256 total_rshares2 = to256(props.total_reward_shares2);
25242518

2525-
u256 rs2 = to256(calculate_vshares(rshares.value, curve));
2519+
u256 rs2 = to256(calculate_vshares(rshares.value));
25262520
rs2 = (rs2 * reward_weight) / STEEMIT_100_PERCENT;
25272521

25282522
u256 payout_u256 = (rf * rs2) / total_rshares2;
@@ -4260,6 +4254,15 @@ namespace golos {
42604254
const auto &by_root_idx = get_index<comment_index, by_root>();
42614255
const auto max_cashout_time = head_block_time();
42624256

4257+
auto recalc_rshares2 = [&](const comment_object &c) {
4258+
if (c.net_rshares.value > 0) {
4259+
auto old_rshares2 = calculate_vshares_quadratic(
4260+
c.net_rshares.value, get_content_constant_s());
4261+
auto new_rshares2 = calculate_vshares_linear(c.net_rshares.value);
4262+
adjust_rshares2(c, old_rshares2, new_rshares2);
4263+
}
4264+
};
4265+
42634266
std::vector<comment_object::id_type> root_posts;
42644267
root_posts.reserve(STEEMIT_HF_17_NUM_POSTS);
42654268

@@ -4279,12 +4282,16 @@ namespace golos {
42794282
c.cashout_time = std::max(c.created + STEEMIT_CASHOUT_WINDOW_SECONDS, max_cashout_time);
42804283
});
42814284

4285+
recalc_rshares2(*itr);
4286+
42824287
auto reply_itr = by_root_idx.lower_bound(id);
42834288
for (; reply_itr != by_root_idx.end() && reply_itr->root_comment == id; ++reply_itr) {
42844289
modify(*reply_itr, [&](comment_object &c) {
42854290
// limit second cashout window to 1 week, or a current block time
42864291
c.cashout_time = std::max(c.created + STEEMIT_CASHOUT_WINDOW_SECONDS, max_cashout_time);
42874292
});
4293+
4294+
recalc_rshares2(*reply_itr);
42884295
}
42894296
}}
42904297
break;
@@ -4411,7 +4418,7 @@ namespace golos {
44114418
for (auto itr = comment_idx.begin();
44124419
itr != comment_idx.end(); ++itr) {
44134420
if (itr->net_rshares.value > 0) {
4414-
auto delta = calculate_vshares(itr->net_rshares.value, itr->curve);
4421+
auto delta = calculate_vshares(itr->net_rshares.value);
44154422
total_rshares2 += delta;
44164423
}
44174424
if (itr->parent_author == STEEMIT_ROOT_POST_PARENT) {
@@ -4486,7 +4493,7 @@ namespace golos {
44864493

44874494
for (const auto &c : comments) {
44884495
if (c.net_rshares.value > 0) {
4489-
adjust_rshares2(c, 0, calculate_vshares(c.net_rshares.value, c.curve));
4496+
adjust_rshares2(c, 0, calculate_vshares(c.net_rshares.value));
44904497
}
44914498
}
44924499

libraries/chain/include/golos/chain/comment_object.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <golos/chain/steem_object_types.hpp>
77
#include <golos/chain/witness_objects.hpp>
8-
#include <golos/chain/reward_curve.hpp>
98

109
#include <boost/multi_index/composite_key.hpp>
1110

@@ -163,7 +162,6 @@ namespace golos {
163162
int32_t net_votes = 0;
164163

165164
id_type root_comment;
166-
reward_curve curve;
167165

168166
comment_mode mode = first_payout;
169167

@@ -342,7 +340,7 @@ FC_REFLECT((golos::chain::comment_object),
342340
(net_rshares)(abs_rshares)(vote_rshares)
343341
(children_abs_rshares)(cashout_time)(max_cashout_time)
344342
(total_vote_weight)(reward_weight)(total_payout_value)(curator_payout_value)(beneficiary_payout_value)
345-
(author_rewards)(net_votes)(root_comment)(curve)(mode)
343+
(author_rewards)(net_votes)(root_comment)(mode)
346344
(max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)(allow_curation_rewards)
347345
(beneficiaries)
348346
)

libraries/chain/include/golos/chain/database.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ namespace golos {
402402

403403
void update_median_feed();
404404

405-
share_type claim_rshare_reward(share_type rshares, uint16_t reward_weight, asset max_steem, reward_curve);
405+
share_type claim_rshare_reward(share_type rshares, uint16_t reward_weight, asset max_steem);
406406

407407
asset get_liquidity_reward() const;
408408

@@ -418,7 +418,7 @@ namespace golos {
418418

419419
uint128_t get_content_constant_s() const;
420420

421-
uint128_t calculate_vshares(uint128_t rshares, reward_curve curve) const;
421+
uint128_t calculate_vshares(uint128_t rshares) const;
422422

423423
void pay_liquidity_reward();
424424

libraries/chain/include/golos/chain/reward_curve.hpp

Lines changed: 0 additions & 14 deletions
This file was deleted.

libraries/chain/include/golos/chain/steem_object_types.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#include <golos/protocol/types.hpp>
1212
#include <golos/protocol/authority.hpp>
13-
#include <golos/chain/reward_curve.hpp>
1413

1514

1615
namespace golos {

libraries/chain/steem_evaluator.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -552,12 +552,6 @@ namespace golos {
552552
com.cashout_time = com.created + STEEMIT_CASHOUT_WINDOW_SECONDS;
553553
}
554554

555-
if (_db.has_hardfork(STEEMIT_HARDFORK_0_17__433)) {
556-
com.curve = reward_curve::linear;
557-
} else {
558-
com.curve = reward_curve::quadratic;
559-
}
560-
561555
#ifndef IS_LOW_MEM
562556
from_string(com.title, o.title);
563557
if (o.body.size() < 1024 * 1024 * 128) {
@@ -1305,8 +1299,8 @@ namespace golos {
13051299
fc::uint128_t new_rshares = std::max(comment.net_rshares.value, int64_t(0));
13061300

13071301
/// calculate rshares2 value
1308-
new_rshares = _db.calculate_vshares(new_rshares, comment.curve);
1309-
old_rshares = _db.calculate_vshares(old_rshares, comment.curve);
1302+
new_rshares = _db.calculate_vshares(new_rshares);
1303+
old_rshares = _db.calculate_vshares(old_rshares);
13101304

13111305
const auto &cat = _db.get_category(comment.category);
13121306
_db.modify(cat, [&](category_object &c) {
@@ -1515,8 +1509,8 @@ namespace golos {
15151509
fc::uint128_t new_rshares = std::max(comment.net_rshares.value, int64_t(0));
15161510

15171511
/// calculate rshares2 value
1518-
new_rshares = _db.calculate_vshares(new_rshares, comment.curve);
1519-
old_rshares = _db.calculate_vshares(old_rshares, comment.curve);
1512+
new_rshares = _db.calculate_vshares(new_rshares);
1513+
old_rshares = _db.calculate_vshares(old_rshares);
15201514

15211515
_db.modify(comment, [&](comment_object &c) {
15221516
c.total_vote_weight -= itr->weight;

plugins/social_network/include/golos/plugins/social_network/api_object/comment_api_object.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace golos {
2222
total_vote_weight(o.total_vote_weight), reward_weight(o.reward_weight),
2323
total_payout_value(o.total_payout_value), curator_payout_value(o.curator_payout_value),
2424
author_rewards(o.author_rewards), net_votes(o.net_votes), root_comment(o.root_comment),
25-
curve(o.curve), max_accepted_payout(o.max_accepted_payout),
25+
max_accepted_payout(o.max_accepted_payout),
2626
percent_steem_dollars(o.percent_steem_dollars), allow_replies(o.allow_replies),
2727
allow_votes(o.allow_votes), allow_curation_rewards(o.allow_curation_rewards) {
2828

@@ -74,8 +74,6 @@ namespace golos {
7474

7575
comment_object::id_type root_comment;
7676

77-
reward_curve curve;
78-
7977
protocol::asset max_accepted_payout;
8078
uint16_t percent_steem_dollars;
8179
bool allow_replies;
@@ -94,6 +92,6 @@ FC_REFLECT((golos::plugins::social_network::comment_api_object),
9492
created)(active)(last_payout)(depth)(children)(children_rshares2)(net_rshares)(abs_rshares)(
9593
vote_rshares)(children_abs_rshares)(cashout_time)(max_cashout_time)(total_vote_weight)(
9694
reward_weight)(total_payout_value)(curator_payout_value)(author_rewards)(net_votes)(root_comment)(
97-
curve)(max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)(
95+
max_accepted_payout)(percent_steem_dollars)(allow_replies)(allow_votes)(
9896
allow_curation_rewards)(beneficiaries))
9997
#endif //GOLOS_COMMENT_API_OBJ_H

plugins/social_network/social_network.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,7 @@ namespace golos {
376376
u256 total_r2 = to256(props.total_reward_shares2);
377377
378378
if (props.total_reward_shares2 > 0) {
379-
auto vshares = database().calculate_vshares(
380-
d.net_rshares.value > 0 ? d.net_rshares.value : 0, d.curve);
379+
auto vshares = database().calculate_vshares(d.net_rshares.value > 0 ? d.net_rshares.value : 0);
381380
382381
//int64_t abs_net_rshares = llabs(d.net_rshares.value);
383382

tests/tests/operation_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,19 @@ BOOST_FIXTURE_TEST_SUITE(operation_tests, clean_database_fixture)
529529
db->modify(mod_sam_comment, [&](comment_object &com) {
530530
com.net_rshares = 10;
531531
com.abs_rshares = 10;
532-
com.children_rshares2 = db->calculate_vshares(10, com.curve);
532+
com.children_rshares2 = db->calculate_vshares(10);
533533
});
534534

535535
db->modify(mod_bob_comment, [&](comment_object &com) {
536-
com.children_rshares2 = db->calculate_vshares(10, com.curve);
536+
com.children_rshares2 = db->calculate_vshares(10);
537537
});
538538

539539
db->modify(mod_alice_comment, [&](comment_object &com) {
540-
com.children_rshares2 = db->calculate_vshares(10, com.curve);
540+
com.children_rshares2 = db->calculate_vshares(10);
541541
});
542542

543543
db->modify(db->get_dynamic_global_properties(), [&](dynamic_global_property_object &o) {
544-
o.total_reward_shares2 = db->calculate_vshares(10, mod_alice_comment.curve);
544+
o.total_reward_shares2 = db->calculate_vshares(10);
545545
});
546546

547547
tx.signatures.clear();

0 commit comments

Comments
 (0)