Skip to content

Commit

Permalink
Misc cleanup of 0.19.0 codebase steemit#1149
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Jun 2, 2017
1 parent 68aadb4 commit 55a0e21
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ void database_api::set_pending_payout( discussion& d )const
vshares = d.net_rshares.value > 0 ? steemit::chain::util::evaluate_reward_curve( d.net_rshares.value, rf.author_reward_curve, rf.content_constant ) : 0;
}
else
vshares = steemit::chain::util::evaluate_reward_curve( d.net_rshares.value > 0 ? d.net_rshares.value : 0 );
vshares = d.net_rshares.value > 0 ? steemit::chain::util::evaluate_reward_curve( d.net_rshares.value ) : 0;

u256 r2 = to256(vshares); //to256(abs_net_rshares);
r2 *= pot.amount.value;
Expand Down
24 changes: 17 additions & 7 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,8 @@ void database::clear_witness_votes( const account_object& a )
remove(current);
}

if( has_hardfork( STEEMIT_HARDFORK_0_6__104 ) ) // TODO: this check can be removed after hard fork
#warning( "TODO: Remove this check after HF 19" )
if( has_hardfork( STEEMIT_HARDFORK_0_6__104 ) )
modify( a, [&](account_object& acc )
{
acc.witnesses_voted_for = 0;
Expand Down Expand Up @@ -1622,7 +1623,7 @@ void database::process_comment_cashout()
{
fc::microseconds decay_rate;

// TODO: Remove temp fund after HF 19
#warning( "TODO: Remove temp reward fund after HF 19" )
if( rfo.name == STEEMIT_TEMP_LINEAR_REWARD_FUND_NAME || has_hardfork( STEEMIT_HARDFORK_0_19__1051 ) )
decay_rate = STEEMIT_RECENT_RSHARES_DECAY_RATE_HF19;
else
Expand Down Expand Up @@ -3087,7 +3088,7 @@ void database::update_last_irreversible_block()
witness_time_pairs.push_back( std::make_pair( b->data.witness, b->data.timestamp ) );
}

ilog( "Encountered a block num collision due to a fork. Walking the current fork to determine the correct block. block_num:${n}", ("n", log_head_num + 1) ); // TODO: Delete when we know this code works as intended
ilog( "Encountered a block num collision due to a fork. Walking the current fork to determine the correct block. block_num:${n}", ("n", log_head_num + 1) );
ilog( "Colliding blocks produced by witnesses at times: ${w}", ("w", witness_time_pairs) );

auto next = _fork_db.head();
Expand Down Expand Up @@ -3748,8 +3749,8 @@ void database::apply_hardfork( uint32_t hardfork )
case STEEMIT_HARDFORK_0_17:
{
static_assert(
STEEMIT_MAX_VOTED_WITNESSES_HF0 + STEEMIT_MAX_MINER_WITNESSES_HF0 + STEEMIT_MAX_RUNNER_WITNESSES_HF0 == STEEMIT_MAX_WITNESSES,
"HF0 witness counts must add up to STEEMIT_MAX_WITNESSES" );
STEEMIT_MAX_VOTED_WITNESSES_HF0 + STEEMIT_MAX_MINER_WITNESSES_HF0 + STEEMIT_MAX_RUNNER_WITNESSES_HF0 == STEEMIT_MAX_WITNESSES,
"HF0 witness counts must add up to STEEMIT_MAX_WITNESSES" );
static_assert(
STEEMIT_MAX_VOTED_WITNESSES_HF17 + STEEMIT_MAX_MINER_WITNESSES_HF17 + STEEMIT_MAX_RUNNER_WITNESSES_HF17 == STEEMIT_MAX_WITNESSES,
"HF17 witness counts must add up to STEEMIT_MAX_WITNESSES" );
Expand Down Expand Up @@ -3794,7 +3795,7 @@ void database::apply_hardfork( uint32_t hardfork )
// As a shortcut in payout processing, we use the id as an array index.
// The IDs must be assigned this way. The assertion is a dummy check to ensure this happens.
FC_ASSERT( post_rf.id._id == 0 );
FC_ASSERT( linear_rf.id._id == 1 );
FC_ASSERT( linear_rf.id._id == STEEMIT_TEMP_LINEAR_REWARD_FUND_ID );

modify( gpo, [&]( dynamic_global_property_object& g )
{
Expand Down Expand Up @@ -3860,14 +3861,21 @@ void database::apply_hardfork( uint32_t hardfork )
const auto& linear = get< reward_fund_object, by_name >( STEEMIT_TEMP_LINEAR_REWARD_FUND_NAME );
modify( get< reward_fund_object, by_name >( STEEMIT_POST_REWARD_FUND_NAME ), [&]( reward_fund_object &rfo )
{
#warning( "TODO: Replace with constant after HF 19" )
rfo.recent_claims = linear.recent_claims;
rfo.author_reward_curve = curve_id::linear;
rfo.curation_reward_curve = curve_id::square_root;
});

#warning( "TODO: Remove weight conversion after HF 19" )
const auto& cidx = get_index< comment_index, by_cashout_time >();
const auto& vidx = get_index< comment_vote_index, by_comment_voter >();
for( auto c_itr = cidx.begin(); c_itr != cidx.end() && c_itr->cashout_time != fc::time_point_sec::maximum(); ++c_itr )

/*
* Iterator through all comments that have not yet been paid, setting their total vote weight to the sqrt weight
* and update their votes as well.
*/
for( auto c_itr = cidx.begin(); c_itr != cidx.end() && c_itr->cashout_time < fc::time_point_sec::maximum(); ++c_itr )
{
modify( *c_itr, [&]( comment_object& c )
{
Expand All @@ -3883,6 +3891,8 @@ void database::apply_hardfork( uint32_t hardfork )
}
}

#warning( "TODO: Remove if 0 delegation opjects are not created in pre HF19 consensus" )
/* Remove all 0 delegation objects */
vector< const vesting_delegation_object* > to_remove;
const auto& delegation_idx = get_index< vesting_delegation_index, by_id >();
auto delegation_itr = delegation_idx.begin();
Expand Down
2 changes: 2 additions & 0 deletions libraries/chain/include/steemit/chain/comment_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ namespace steemit { namespace chain {
time_point_sec cashout_time; /// 24 hours from the weighted average of vote time
time_point_sec max_cashout_time;
uint64_t total_vote_weight = 0; /// the total weight of voting rewards, used to calculate pro-rata share of curation payouts
#warning( "Remove total_sqrt_vote_weight after HF 19" )
uint64_t total_sqrt_vote_weight = 0; /// Temporary total weight of votes for post hf19 curation reward curve

uint16_t reward_weight = 0;
Expand Down Expand Up @@ -121,6 +122,7 @@ namespace steemit { namespace chain {
account_id_type voter;
comment_id_type comment;
uint64_t weight = 0; ///< defines the score this vote receives, used by vote payout calc. 0 if a negative vote or changed votes.
#warning( "Remove sqrt_weight after HF 19. It is a temporary field" )
uint64_t sqrt_weight = 0; ///< Temporary vote weight for post hf19 curation curve
int64_t rshares = 0; ///< The number of rshares this vote is responsible for
int16_t vote_percent = 0; ///< The percent weight of the vote
Expand Down
15 changes: 6 additions & 9 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ void account_create_evaluator::do_apply( const account_create_operation& o )
}
else if( _db.has_hardfork( STEEMIT_HARDFORK_0_17__818 ) )
{
#warning( "TODO: Remove after HF19. Entire conditional might be able to be removed." )
if( _db.is_producing() )
FC_ASSERT( false, "account_create_operation is temporarily disabled. Please use account_create_with_delegation_operation instead" );
const witness_schedule_object& wso = _db.get_witness_schedule_object();
Expand Down Expand Up @@ -271,9 +272,7 @@ void account_create_with_delegation_evaluator::do_apply( const account_create_wi
auth.last_owner_update = fc::time_point_sec::min();
});

/* TODO: Check if not creating 0 delegation objects in HF19 passes consensus
* If it does we can remove the apply_hardfork logic for deleting 0 delegation objects
*/
#warning( "TODO: Check if not creating 0 delegation objects in HF19 passes consensus. Expectation is it should work." )
if( ( _db.has_hardfork( STEEMIT_HARDFORK_0_19__997 ) && o.delegation.amount > 0 )
|| !_db.has_hardfork( STEEMIT_HARDFORK_0_19__997 ) )
{
Expand Down Expand Up @@ -384,7 +383,7 @@ void delete_comment_evaluator::do_apply( const delete_comment_operation& o )
if( _db.has_hardfork( STEEMIT_HARDFORK_0_19__876 ) )
FC_ASSERT( comment.cashout_time != fc::time_point_sec::maximum() );

// TODO: remove is_producing after HF 19. Check if we can remove conditional altogether after HF.
#warning( "TODO: Remove is_producing check after HF19. Conditional may be removed entirely after HF." )
if( _db.is_producing() || _db.has_hardfork( STEEMIT_HARDFORK_0_19__977 ) ) {
FC_ASSERT( comment.net_rshares <= 0, "Cannot delete a comment with net positive votes." );
}
Expand Down Expand Up @@ -460,8 +459,6 @@ void comment_options_evaluator::do_apply( const comment_options_operation& o )
if( !o.allow_curation_rewards || !o.allow_votes || o.max_accepted_payout < comment.max_accepted_payout )
FC_ASSERT( comment.abs_rshares == 0, "One of the included comment options requires the comment to have no rshares allocated to it." );

if( !_db.has_hardfork( STEEMIT_HARDFORK_0_17__773) ) // TODO: Remove after hardfork 17
FC_ASSERT( o.extensions.size() == 0, "Operation extensions for the comment_options_operation are not currently supported." );
FC_ASSERT( comment.allow_curation_rewards >= o.allow_curation_rewards, "Curation rewards cannot be re-enabled." );
FC_ASSERT( comment.allow_votes >= o.allow_votes, "Voting cannot be re-enabled." );
FC_ASSERT( comment.max_accepted_payout >= o.max_accepted_payout, "A comment cannot accept a greater payout." );
Expand Down Expand Up @@ -1364,6 +1361,7 @@ void vote_evaluator::do_apply( const vote_operation& o )
uint64_t old_weight = util::evaluate_reward_curve( old_vote_rshares.value, reward_fund.curation_reward_curve, reward_fund.content_constant ).to_uint64();
uint64_t new_weight = util::evaluate_reward_curve( comment.vote_rshares.value, reward_fund.curation_reward_curve, reward_fund.content_constant ).to_uint64();
cv.weight = new_weight - old_weight;
#warning( "TODO: After HF19 caclulate which comment was the first to be paid on sqrt curation and activate the logic based on time" )
if( !_db.has_hardfork( STEEMIT_HARDFORK_0_19__1052 ) )
{
old_weight = util::evaluate_reward_curve( old_vote_rshares.value, curve_id::square_root ).to_uint64();
Expand Down Expand Up @@ -2189,8 +2187,6 @@ void claim_reward_balance_evaluator::do_apply( const claim_reward_balance_operat

void delegate_vesting_shares_evaluator::do_apply( const delegate_vesting_shares_operation& op )
{
FC_ASSERT( _db.has_hardfork( STEEMIT_HARDFORK_0_17__818 ), "delegate_vesting_shares_operation is not enabled until HF 17" ); //TODO: Delete after hardfork

const auto& delegator = _db.get_account( op.delegator );
const auto& delegatee = _db.get_account( op.delegatee );
auto delegation = _db.find< vesting_delegation_object, by_delegation >( boost::make_tuple( op.delegator, op.delegatee ) );
Expand Down Expand Up @@ -2261,7 +2257,8 @@ void delegate_vesting_shares_evaluator::do_apply( const delegate_vesting_shares_
"Delegation must be removed or be a significant change and leave a minimum delegation. min_update: ${min_update}, min_delegation: ${min_delegation}",
("min_update", min_update)("min_delegation", min_delegation) );
}
else // TODO: Check and remove after HF19
#warning( "TODO: Check and remove conditional after HF19" )
else
{
FC_ASSERT( delta >= min_update, "Steem Power increase is not enough of a different. min_update: ${min}", ("min", min_update) );
FC_ASSERT( op.vesting_shares >= min_delegation || op.vesting_shares.amount == 0, "Delegation must be removed or leave minimum delegation amount of ${v}", ("v", min_delegation) );
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/witness_schedule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ void update_witness_schedule4( database& db )

db.modify( wso, [&]( witness_schedule_object& _wso )
{
// active witnesses has exactly STEEMIT_MAX_WITNESSES elements, asserted above
for( size_t i = 0; i < active_witnesses.size(); i++ )
{
_wso.current_shuffled_witnesses[i] = active_witnesses[i];
Expand Down

0 comments on commit 55a0e21

Please sign in to comment.