Skip to content

Commit

Permalink
#801 Fix trending to use uint128, adjust get_discussion_by_cashout, a…
Browse files Browse the repository at this point in the history
…nd undo regression from removing total_reward_shares2
  • Loading branch information
NateBrune committed Apr 21, 2017
1 parent d82cc14 commit 761e0ca
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
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.net_rshares <= 0; } ); //TODO: Review the change from children_rshares2 to net_rshares.
return get_discussions( query, tag, parent, tidx, tidx_itr, query.truncate_body, []( const comment_api_obj& c ) { return c.cashout_time <= c.created; });
});
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/app/include/steemit/app/steem_api_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct tag_api_obj
int32_t net_votes = 0;
uint32_t top_posts = 0;
uint32_t comments = 0;
uint64_t trending = 0;
fc::uint128 trending = 0;
};

struct account_api_obj
Expand Down
27 changes: 27 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,22 @@ void database::clear_null_account_balance()
adjust_supply( -total_sbd );
}

/**
* 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 )
{

const auto& dgpo = get_dynamic_global_properties();
modify( dgpo, [&]( dynamic_global_property_object& p )
{
p.total_reward_shares2 -= old_rshares2;
p.total_reward_shares2 += new_rshares2;
} );
}

void database::update_owner_authority( const account_object& account, const authority& owner_authority )
{
if( head_block_num() >= STEEMIT_OWNER_AUTH_HISTORY_TRACKING_START_BLOCK_NUM )
Expand Down Expand Up @@ -1632,6 +1648,9 @@ share_type database::cashout_comment_helper( util::comment_reward_context& ctx,
c.total_payouts += to_sbd( asset( claimed_reward, STEEM_SYMBOL ) );
});
}

if( !has_hardfork( STEEMIT_HARDFORK_0_17__774 ) )
adjust_rshares2( comment, util::calculate_claims( comment.net_rshares.value ), 0 );
}

modify( cat, [&]( category_object& c )
Expand Down Expand Up @@ -4065,6 +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;

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

Expand All @@ -4073,6 +4093,7 @@ void database::validate_invariants()const
if( itr->net_rshares.value > 0 )
{
auto delta = util::calculate_claims( itr->net_rshares.value );
total_rshares2 += delta;
}
}

Expand Down Expand Up @@ -4139,6 +4160,12 @@ void database::perform_vesting_share_split( uint32_t magnitude )
} );
}

for( const auto& c : comments )
{
if( c.net_rshares.value > 0 )
adjust_rshares2( c, 0, util::calculate_claims( c.net_rshares.value ) );
}

// Update category rshares
const auto& cat_idx = get_index< category_index >().indices().get< by_name >();
auto cat_itr = cat_idx.begin();
Expand Down
1 change: 1 addition & 0 deletions libraries/chain/include/steemit/chain/database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ namespace steemit { namespace chain {
void adjust_savings_balance( const account_object& a, const asset& delta );
void adjust_reward_balance( const account_object& a, const asset& delta );
void adjust_supply( const asset& delta, bool adjust_vesting = false );
void adjust_rshares2( const comment_object& comment, fc::uint128_t old_rshares2, fc::uint128_t new_rshares2 );
void update_owner_authority( const account_object& account, const authority& owner_authority );

asset get_balance( const account_object& a, asset_symbol_type symbol )const;
Expand Down
19 changes: 19 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,12 @@ void vote_evaluator::do_apply( const vote_operation& o )
}
});

fc::uint128_t new_rshares = std::max( comment.net_rshares.value, int64_t(0));

/// calculate rshares2 value
new_rshares = util::calculate_claims( new_rshares );
old_rshares = util::calculate_claims( old_rshares );

const auto& cat = _db.get_category( comment.category );
_db.modify( cat, [&]( category_object& c ){
c.abs_rshares += abs_rshares;
Expand Down Expand Up @@ -1460,6 +1466,8 @@ 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 );
}
else
{
Expand Down Expand Up @@ -1544,6 +1552,14 @@ void vote_evaluator::do_apply( const vote_operation& o )
}
});


fc::uint128_t new_rshares = std::max( comment.net_rshares.value, int64_t(0));

/// calculate rshares2 value
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 All @@ -1557,6 +1573,9 @@ void vote_evaluator::do_apply( const vote_operation& o )
cv.weight = 0;
cv.num_changes += 1;
});

if( !_db.has_hardfork( STEEMIT_HARDFORK_0_17__774) )
_db.adjust_rshares2( comment, old_rshares, new_rshares );
}

} FC_CAPTURE_AND_RETHROW( (o)) }
Expand Down
6 changes: 3 additions & 3 deletions libraries/plugins/tags/include/steemit/tags/tags_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class tag_stats_object : public object< tag_stats_object_type, tag_stats_object
int32_t net_votes = 0;
uint32_t top_posts = 0;
uint32_t comments = 0;
uint64_t total_trending = 0;
fc::uint128 total_trending = 0;
};

typedef oid< tag_stats_object > tag_stats_id_type;
Expand Down Expand Up @@ -291,10 +291,10 @@ typedef multi_index_container<
*/
ordered_non_unique< tag< by_trending >,
composite_key< tag_stats_object,
member< tag_stats_object, uint64_t , &tag_stats_object::total_trending >,
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< uint64_t >, std::less< tag_name_type > >
composite_key_compare< std::greater< fc::uint128 >, std::less< tag_name_type > >
>
>,
allocator< tag_stats_object >
Expand Down
4 changes: 2 additions & 2 deletions libraries/plugins/tags/tags_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct operation_visitor {
} else {
s.comments--;
}
s.total_trending -= std::round(tag.trending);
s.total_trending -= static_cast<uint32_t>(tag.trending);
s.net_votes -= tag.net_votes;
});
}
Expand All @@ -72,7 +72,7 @@ struct operation_visitor {
} else {
s.comments++;
}
s.total_trending += std::round(tag.trending);
s.total_trending += static_cast<uint32_t>(tag.trending);
s.net_votes += tag.net_votes;
});
}
Expand Down

0 comments on commit 761e0ca

Please sign in to comment.