Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#801 remove children_rshares2 from consensus #1027

Merged
merged 4 commits into from Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/app/database_api.cpp
Expand Up @@ -1526,7 +1526,7 @@ vector<discussion> database_api::get_discussions_by_cashout( const discussion_qu
const auto& tidx = my->_db.get_index<tags::tag_index>().indices().get<tags::by_cashout>();
auto tidx_itr = tidx.lower_bound( boost::make_tuple( tag, fc::time_point::now() - fc::minutes(60) ) );

return get_discussions( query, tag, parent, tidx, tidx_itr, query.truncate_body, []( const comment_api_obj& c ){ return c.children_rshares2 <= 0; } );
return get_discussions( query, tag, parent, tidx, tidx_itr, query.truncate_body, []( const comment_api_obj& c ){ return c.net_rshares < 0; });
});
}

Expand Down
13 changes: 5 additions & 8 deletions libraries/app/include/steemit/app/steem_api_objects.hpp
Expand Up @@ -72,7 +72,6 @@ struct comment_api_obj
last_payout( o.last_payout ),
depth( o.depth ),
children( o.children ),
children_rshares2( o.children_rshares2 ),
net_rshares( o.net_rshares ),
abs_rshares( o.abs_rshares ),
vote_rshares( o.vote_rshares ),
Expand Down Expand Up @@ -118,8 +117,6 @@ struct comment_api_obj
uint8_t depth = 0;
uint32_t children = 0;

uint128_t children_rshares2;

share_type net_rshares;
share_type abs_rshares;
share_type vote_rshares;
Expand Down Expand Up @@ -173,20 +170,20 @@ struct tag_api_obj
{
tag_api_obj( const tags::tag_stats_object& o ) :
name( o.tag ),
total_children_rshares2(o.total_children_rshares2),
total_payouts(o.total_payout),
net_votes(o.net_votes),
top_posts(o.top_posts),
comments(o.comments) {}
comments(o.comments),
trending(o.total_trending) {}

tag_api_obj() {}

string name;
fc::uint128_t total_children_rshares2;
asset total_payouts;
int32_t net_votes = 0;
uint32_t top_posts = 0;
uint32_t comments = 0;
fc::uint128 trending = 0;
};

struct account_api_obj
Expand Down Expand Up @@ -503,7 +500,7 @@ FC_REFLECT( steemit::app::comment_api_obj,
(id)(author)(permlink)
(category)(parent_author)(parent_permlink)
(title)(body)(json_metadata)(last_update)(created)(active)(last_payout)
(depth)(children)(children_rshares2)
(depth)(children)
(net_rshares)(abs_rshares)(vote_rshares)
(children_abs_rshares)(cashout_time)(max_cashout_time)
(total_vote_weight)(reward_weight)(total_payout_value)(curator_payout_value)(author_rewards)(net_votes)(root_comment)
Expand Down Expand Up @@ -567,11 +564,11 @@ FC_REFLECT( steemit::app::feed_history_api_obj,

FC_REFLECT( steemit::app::tag_api_obj,
(name)
(total_children_rshares2)
(total_payouts)
(net_votes)
(top_posts)
(comments)
(trending)
)

FC_REFLECT( steemit::app::witness_api_obj,
Expand Down
28 changes: 0 additions & 28 deletions libraries/chain/database.cpp
Expand Up @@ -1359,34 +1359,13 @@ void database::clear_null_account_balance()
adjust_supply( -total_sbd );
}

void update_children_rshares2( database& db, const comment_object& c, const fc::uint128_t& old_rshares2, const fc::uint128_t& new_rshares2 )
{
// Iteratively updates the children_rshares2 of this comment and all of its ancestors

const comment_object* current_comment = &c;
while( true )
{
db.modify( *current_comment, [&]( comment_object& comment )
{
comment.children_rshares2 -= old_rshares2;
comment.children_rshares2 += new_rshares2;
} );

if( current_comment->depth == 0 )
break;

current_comment = &db.get_comment( current_comment->parent_author, current_comment->parent_permlink );
}
}

/**
* This method updates total_reward_shares2 on DGPO, and children_rshares2 on comments, when a comment's rshares2 changes
* from old_rshares2 to new_rshares2. Maintaining invariants that children_rshares2 is the sum of all descendants' rshares2,
* and dgpo.total_reward_shares2 is the total number of rshares2 outstanding.
*/
void database::adjust_rshares2( const comment_object& c, fc::uint128_t old_rshares2, fc::uint128_t new_rshares2 )
{
update_children_rshares2( *this, c, old_rshares2, new_rshares2 );

const auto& dgpo = get_dynamic_global_properties();
modify( dgpo, [&]( dynamic_global_property_object& p )
Expand Down Expand Up @@ -3974,7 +3953,6 @@ void database::apply_hardfork( uint32_t hardfork )
modify( *itr, [&]( comment_object& c )
{
c.cashout_time = std::max( c.created + STEEMIT_CASHOUT_WINDOW_SECONDS, c.cashout_time );
c.children_rshares2 = 0;
});
}

Expand All @@ -3983,7 +3961,6 @@ void database::apply_hardfork( uint32_t hardfork )
modify( *itr, [&]( comment_object& c )
{
c.cashout_time = std::max( calculate_discussion_payout_time( c ), c.created + STEEMIT_CASHOUT_WINDOW_SECONDS );
c.children_rshares2 = 0;
});
}
}
Expand Down Expand Up @@ -4107,9 +4084,7 @@ void database::validate_invariants()const
else
FC_ASSERT( false, "found savings withdraw that is not SBD or STEEM" );
}

fc::uint128_t total_rshares2;
fc::uint128_t total_children_rshares2;

const auto& comment_idx = get_index< comment_index >().indices();

Expand All @@ -4120,8 +4095,6 @@ void database::validate_invariants()const
auto delta = util::calculate_claims( itr->net_rshares.value );
total_rshares2 += delta;
}
if( itr->parent_author == STEEMIT_ROOT_POST_PARENT )
total_children_rshares2 += itr->children_rshares2;
}

const auto& reward_idx = get_index< reward_fund_index, by_id >();
Expand Down Expand Up @@ -4184,7 +4157,6 @@ void database::perform_vesting_share_split( uint32_t magnitude )
c.net_rshares *= magnitude;
c.abs_rshares *= magnitude;
c.vote_rshares *= magnitude;
c.children_rshares2 = 0;
} );
}

Expand Down
9 changes: 1 addition & 8 deletions libraries/chain/include/steemit/chain/comment_object.hpp
Expand Up @@ -126,13 +126,6 @@ namespace steemit { namespace chain {
uint16_t depth = 0; ///< used to track max nested depth
uint32_t children = 0; ///< used to track the total number of children, grandchildren, etc...

/**
* Used to track the total rshares^2 of all children, this is used for indexing purposes. A discussion
* that has a nested comment of high value should promote the entire discussion so that the comment can
* be reviewed.
*/
fc::uint128_t children_rshares2;

/// index on pending_payout for "things happning now... needs moderation"
/// TRENDING = UNCLAIMED + PENDING
share_type net_rshares; // reward is proportional to rshares^2, this is the sum of all votes (positive and negative)
Expand Down Expand Up @@ -312,7 +305,7 @@ FC_REFLECT( steemit::chain::comment_object,
(id)(author)(permlink)
(category)(parent_author)(parent_permlink)
(title)(body)(json_metadata)(last_update)(created)(active)(last_payout)
(depth)(children)(children_rshares2)
(depth)(children)
(net_rshares)(abs_rshares)(vote_rshares)
(children_abs_rshares)(cashout_time)(max_cashout_time)
(total_vote_weight)(reward_weight)(total_payout_value)(curator_payout_value)(beneficiary_payout_value)(author_rewards)(net_votes)(root_comment)
Expand Down
2 changes: 1 addition & 1 deletion libraries/chain/steem_evaluator.cpp
Expand Up @@ -1466,7 +1466,6 @@ void vote_evaluator::do_apply( const vote_operation& o )
c.total_vote_weight += max_vote_weight;
});
}

if( !_db.has_hardfork( STEEMIT_HARDFORK_0_17__774) )
_db.adjust_rshares2( comment, old_rshares, new_rshares );
}
Expand Down Expand Up @@ -1559,6 +1558,7 @@ void vote_evaluator::do_apply( const vote_operation& o )
new_rshares = util::calculate_claims( new_rshares );
old_rshares = util::calculate_claims( old_rshares );


_db.modify( comment, [&]( comment_object& c )
{
c.total_vote_weight -= itr->weight;
Expand Down
28 changes: 5 additions & 23 deletions libraries/plugins/tags/include/steemit/tags/tags_plugin.hpp
Expand Up @@ -87,13 +87,6 @@ class tag_object : public object< tag_object_type, tag_object >
double trending = 0;
share_type promoted_balance = 0;

/**
* Used to track the total rshares^2 of all children, this is used for indexing purposes. A discussion
* that has a nested comment of high value should promote the entire discussion so that the comment can
* be reviewed.
*/
fc::uint128_t children_rshares2;

account_id_type author;
comment_id_type parent;
comment_id_type comment;
Expand All @@ -111,13 +104,11 @@ struct by_parent_active;
struct by_parent_promoted;
struct by_parent_net_rshares; /// all top level posts by direct pending payout
struct by_parent_net_votes; /// all top level posts by direct votes
struct by_parent_children_rshares2; /// all top level posts by total cumulative payout (aka payout)
struct by_parent_trending;
struct by_parent_children; /// all top level posts with the most discussion (replies at all levels)
struct by_parent_hot;
struct by_author_parent_created; /// all blog posts by author with tag
struct by_author_comment;
struct by_mode_parent_children_rshares2;
struct by_reward_fund_net_rshares;
struct by_comment;
struct by_tag;
Expand Down Expand Up @@ -199,15 +190,6 @@ typedef multi_index_container<
>,
composite_key_compare< std::less<tag_name_type>, std::less<comment_id_type>, std::greater< double >, std::less< tag_id_type > >
>,
ordered_unique< tag< by_parent_children_rshares2 >,
composite_key< tag_object,
member< tag_object, tag_name_type, &tag_object::tag >,
member< tag_object, comment_id_type, &tag_object::parent >,
member< tag_object, fc::uint128_t, &tag_object::children_rshares2 >,
member< tag_object, tag_id_type, &tag_object::id >
>,
composite_key_compare< std::less<tag_name_type>, std::less<comment_id_type>, std::greater< fc::uint128_t >, std::less< tag_id_type > >
>,
ordered_unique< tag< by_parent_trending >,
composite_key< tag_object,
member< tag_object, tag_name_type, &tag_object::tag >,
Expand Down Expand Up @@ -273,11 +255,11 @@ class tag_stats_object : public object< tag_stats_object_type, tag_stats_object
id_type id;

tag_name_type tag;
fc::uint128_t total_children_rshares2;
asset total_payout = asset( 0, SBD_SYMBOL );
int32_t net_votes = 0;
uint32_t top_posts = 0;
uint32_t comments = 0;
fc::uint128 total_trending = 0;
};

typedef oid< tag_stats_object > tag_stats_id_type;
Expand Down Expand Up @@ -309,10 +291,10 @@ typedef multi_index_container<
*/
ordered_non_unique< tag< by_trending >,
composite_key< tag_stats_object,
member< tag_stats_object, fc::uint128_t, &tag_stats_object::total_children_rshares2 >,
member< tag_stats_object, fc::uint128 , &tag_stats_object::total_trending >,
member< tag_stats_object, tag_name_type, &tag_stats_object::tag >
>,
composite_key_compare< std::greater< uint128_t >, std::less< tag_name_type > >
composite_key_compare< std::greater< fc::uint128 >, std::less< tag_name_type > >
>
>,
allocator< tag_stats_object >
Expand Down Expand Up @@ -516,11 +498,11 @@ class tag_api : public std::enable_shared_from_this<tag_api> {
FC_API( steemit::tags::tag_api, (get_tags) );

FC_REFLECT( steemit::tags::tag_object,
(id)(tag)(created)(active)(cashout)(net_rshares)(net_votes)(hot)(trending)(promoted_balance)(children)(children_rshares2)(author)(parent)(comment) )
(id)(tag)(created)(active)(cashout)(net_rshares)(net_votes)(hot)(trending)(promoted_balance)(children)(author)(parent)(comment) )
CHAINBASE_SET_INDEX_TYPE( steemit::tags::tag_object, steemit::tags::tag_index )

FC_REFLECT( steemit::tags::tag_stats_object,
(id)(tag)(total_children_rshares2)(total_payout)(net_votes)(top_posts)(comments) );
(id)(tag)(total_payout)(net_votes)(top_posts)(comments)(total_trending) );
CHAINBASE_SET_INDEX_TYPE( steemit::tags::tag_stats_object, steemit::tags::tag_stats_index )

FC_REFLECT( steemit::tags::peer_stats_object,
Expand Down
6 changes: 2 additions & 4 deletions libraries/plugins/tags/tags_plugin.cpp
Expand Up @@ -57,22 +57,22 @@ struct operation_visitor {
void remove_stats( const tag_object& tag, const tag_stats_object& stats )const {
_db.modify( stats, [&]( tag_stats_object& s ) {
if( tag.parent == comment_id_type() ) {
s.total_children_rshares2 -= tag.children_rshares2;
s.top_posts--;
} else {
s.comments--;
}
s.total_trending -= static_cast<uint32_t>(tag.trending);
s.net_votes -= tag.net_votes;
});
}
void add_stats( const tag_object& tag, const tag_stats_object& stats )const {
_db.modify( stats, [&]( tag_stats_object& s ) {
if( tag.parent == comment_id_type() ) {
s.total_children_rshares2 += tag.children_rshares2;
s.top_posts++;
} else {
s.comments++;
}
s.total_trending += static_cast<uint32_t>(tag.trending);
s.net_votes += tag.net_votes;
});
}
Expand Down Expand Up @@ -155,7 +155,6 @@ struct operation_visitor {
obj.children = comment.children;
obj.net_rshares = comment.net_rshares.value;
obj.net_votes = comment.net_votes;
obj.children_rshares2 = comment.children_rshares2;
obj.hot = hot;
obj.trending = trending;
if( obj.cashout == fc::time_point_sec() )
Expand Down Expand Up @@ -185,7 +184,6 @@ struct operation_visitor {
obj.net_votes = comment.net_votes;
obj.children = comment.children;
obj.net_rshares = comment.net_rshares.value;
obj.children_rshares2 = comment.children_rshares2;
obj.author = author;
obj.hot = hot;
obj.trending = trending;
Expand Down
14 changes: 0 additions & 14 deletions tests/tests/operation_tests.cpp
Expand Up @@ -541,17 +541,6 @@ BOOST_AUTO_TEST_CASE( comment_apply )
{
com.net_rshares = 10;
com.abs_rshares = 10;
com.children_rshares2 = steemit::chain::util::calculate_claims( 10 );
});

db.modify( mod_bob_comment, [&]( comment_object& com)
{
com.children_rshares2 = steemit::chain::util::calculate_claims( 10 );
});

db.modify( mod_alice_comment, [&]( comment_object& com)
{
com.children_rshares2 = steemit::chain::util::calculate_claims( 10 );
});

db.modify( db.get_dynamic_global_properties(), [&]( dynamic_global_property_object& o)
Expand Down Expand Up @@ -830,8 +819,6 @@ BOOST_AUTO_TEST_CASE( vote_apply )
tx.sign( sam_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

auto old_rshares2 = db.get_comment( "alice", string( "foo" ) ).children_rshares2;

op.weight = STEEMIT_100_PERCENT;
op.voter = "alice";
op.author = "sam";
Expand All @@ -844,7 +831,6 @@ BOOST_AUTO_TEST_CASE( vote_apply )

auto new_rshares = ( ( fc::uint128_t( db.get_account( "alice" ).vesting_shares.amount.value ) * used_power ) / STEEMIT_100_PERCENT ).to_uint64();

BOOST_REQUIRE( db.get_comment( "alice", string( "foo" ) ).children_rshares2 == db.get_comment( "sam", string( "foo" ) ).children_rshares2 + old_rshares2 );
BOOST_REQUIRE( db.get_comment( "alice", string( "foo" ) ).cashout_time == db.get_comment( "alice", string( "foo" ) ).created + STEEMIT_CASHOUT_WINDOW_SECONDS );

validate_database();
Expand Down