Skip to content

Commit

Permalink
Merge branch '177-new-cashout-times' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Jul 20, 2016
2 parents 8b43755 + 3767aef commit 5018a34
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 12 deletions.
16 changes: 9 additions & 7 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1873,11 +1873,13 @@ void database::cashout_comment_helper( const comment_object& comment )
c.total_vote_weight = 0;
c.max_cashout_time = fc::time_point_sec::maximum();

if( has_hardfork( STEEMIT_HARDFORK_0_12__177 ) && c.last_payout == fc::time_point_sec::min() )
c.cashout_time = head_block_time() + STEEMIT_SECOND_CASHOUT_WINDOW;
else
c.cashout_time = fc::time_point_sec::maximum();

if( c.parent_author.size() == 0 )
{
if( has_hardfork( STEEMIT_HARDFORK_0_12__177 ) && c.last_payout == fc::time_point_sec::min() )
c.cashout_time = head_block_time() + STEEMIT_SECOND_CASHOUT_WINDOW;
else
c.cashout_time = fc::time_point_sec::maximum();
}
c.last_payout = head_block_time();
} );

Expand All @@ -1887,7 +1889,7 @@ void database::cashout_comment_helper( const comment_object& comment )
{
const auto& cur_vote = *vote_itr;
++vote_itr;
if( !has_hardfork( STEEMIT_HARDFORK_0_12__177 ) || comment.cashout_time != fc::time_point_sec::maximum() )
if( !has_hardfork( STEEMIT_HARDFORK_0_12__177 ) || calculate_discussion_payout_time( comment ) != fc::time_point_sec::maximum() )
{
modify( cur_vote, [&]( comment_vote_object& cvo )
{
Expand Down Expand Up @@ -3523,7 +3525,7 @@ void database::apply_hardfork( uint32_t hardfork )
{
// At the hardfork time, all paid comments are still within their 30 day second cashout window.
// If it has been paid, set the second cashout time.
if( itr->last_payout > fc::time_point_sec() )
if( itr->parent_author.size() == 0 && itr->last_payout > fc::time_point_sec() )
{
modify( *itr, [&]( comment_object& c )
{
Expand Down
13 changes: 8 additions & 5 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ void comment_evaluator::do_apply( const comment_operation& o )
com.created = com.last_update;
com.active = com.last_update;
com.last_payout = fc::time_point_sec::min();
com.cashout_time = fc::time_point_sec::maximum();
com.max_cashout_time = fc::time_point_sec::maximum();
com.reward_weight = reward_weight;

Expand All @@ -342,6 +341,9 @@ void comment_evaluator::do_apply( const comment_operation& o )
com.parent_permlink = o.parent_permlink;
com.category = o.parent_permlink;
com.root_comment = com.id;
com.cashout_time = db().has_hardfork( STEEMIT_HARDFORK_0_12__177 ) ?
db().head_block_time() + STEEMIT_CASHOUT_WINDOW_SECONDS :
fc::time_point_sec::maximum();
}
else
{
Expand All @@ -350,6 +352,7 @@ void comment_evaluator::do_apply( const comment_operation& o )
com.depth = parent->depth + 1;
com.category = parent->category;
com.root_comment = parent->root_comment;
com.cashout_time = fc::time_point_sec::maximum();
}

#ifndef IS_LOW_MEM
Expand Down Expand Up @@ -397,7 +400,7 @@ void comment_evaluator::do_apply( const comment_operation& o )
const auto& comment = *itr;

if( db().has_hardfork( STEEMIT_HARDFORK_0_12__177 ) )
FC_ASSERT( comment.last_payout != fc::time_point_sec::maximum() );
FC_ASSERT( db().calculate_discussion_payout_time( comment ) != fc::time_point_sec::maximum() );
else if( db().has_hardfork( STEEMIT_HARDFORK_0_10 ) )
FC_ASSERT( comment.last_payout == fc::time_point_sec::min() );

Expand Down Expand Up @@ -824,14 +827,14 @@ void vote_evaluator::do_apply( const vote_operation& o )
const auto& comment = db().get_comment( o.author, o.permlink );
const auto& voter = db().get_account( o.voter );

if( db().has_hardfork( STEEMIT_HARDFORK_0_12__177 ) && comment.cashout_time == fc::time_point_sec::maximum() )
return;

if( db().has_hardfork( STEEMIT_HARDFORK_0_10 ) )
FC_ASSERT( !(voter.owner_challenged || voter.active_challenged ) );

if( o.weight > 0 ) FC_ASSERT( comment.allow_votes );

if( db().has_hardfork( STEEMIT_HARDFORK_0_12__177 ) && db().calculate_discussion_payout_time( comment ) == fc::time_point_sec::maximum() )
return;

const auto& comment_vote_idx = db().get_index_type< comment_vote_index >().indices().get< by_comment_voter >();
auto itr = comment_vote_idx.find( std::make_tuple( comment.id, voter.id ) );

Expand Down
96 changes: 96 additions & 0 deletions tests/tests/operation_time_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2262,5 +2262,101 @@ BOOST_AUTO_TEST_CASE( post_rate_limit )
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE( post_rate_limit )
{
try
{
ACTORS( (alice) )

fund( "alice", 10000 );
vest( "alice", 10000 );

comment_operation op;
op.author = "alice";
op.permlink = "test1";
op.parent_author = "";
op.parent_permlink = "test";
op.body = "test";

signed_transaction tx;

tx.operations.push_back( op );
tx.set_expiration( db.head_block_time() + STEEMIT_MAX_TIME_UNTIL_EXPIRATION );
tx.sign( alice_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

uint64_t alice_post_bandwidth = STEEMIT_100_PERCENT;

BOOST_REQUIRE( alice.post_bandwidth == alice_post_bandwidth );
BOOST_REQUIRE( db.get_comment( "alice", "test1" ).reward_weight == STEEMIT_100_PERCENT );

tx.operations.clear();
tx.signatures.clear();

generate_blocks( db.head_block_time() + STEEMIT_MIN_ROOT_COMMENT_INTERVAL + fc::seconds( STEEMIT_BLOCK_INTERVAL ), true );

op.permlink = "test2";

tx.operations.push_back( op );
tx.sign( alice_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

alice_post_bandwidth = STEEMIT_100_PERCENT + ( alice_post_bandwidth * ( STEEMIT_POST_AVERAGE_WINDOW - STEEMIT_MIN_ROOT_COMMENT_INTERVAL.to_seconds() - STEEMIT_BLOCK_INTERVAL ) / STEEMIT_POST_AVERAGE_WINDOW );

BOOST_REQUIRE( db.get_account( "alice" ).post_bandwidth == alice_post_bandwidth );
BOOST_REQUIRE( db.get_comment( "alice", "test2" ).reward_weight == STEEMIT_100_PERCENT );

generate_blocks( db.head_block_time() + STEEMIT_MIN_ROOT_COMMENT_INTERVAL + fc::seconds( STEEMIT_BLOCK_INTERVAL ), true );

tx.operations.clear();
tx.signatures.clear();

op.permlink = "test3";

tx.operations.push_back( op );
tx.sign( alice_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

alice_post_bandwidth = STEEMIT_100_PERCENT + ( alice_post_bandwidth * ( STEEMIT_POST_AVERAGE_WINDOW - STEEMIT_MIN_ROOT_COMMENT_INTERVAL.to_seconds() - STEEMIT_BLOCK_INTERVAL ) / STEEMIT_POST_AVERAGE_WINDOW );

BOOST_REQUIRE( db.get_account( "alice" ).post_bandwidth == alice_post_bandwidth );
BOOST_REQUIRE( db.get_comment( "alice", "test3" ).reward_weight == STEEMIT_100_PERCENT );

generate_blocks( db.head_block_time() + STEEMIT_MIN_ROOT_COMMENT_INTERVAL + fc::seconds( STEEMIT_BLOCK_INTERVAL ), true );

tx.operations.clear();
tx.signatures.clear();

op.permlink = "test4";

tx.operations.push_back( op );
tx.sign( alice_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

alice_post_bandwidth = STEEMIT_100_PERCENT + ( alice_post_bandwidth * ( STEEMIT_POST_AVERAGE_WINDOW - STEEMIT_MIN_ROOT_COMMENT_INTERVAL.to_seconds() - STEEMIT_BLOCK_INTERVAL ) / STEEMIT_POST_AVERAGE_WINDOW );

BOOST_REQUIRE( db.get_account( "alice" ).post_bandwidth == alice_post_bandwidth );
BOOST_REQUIRE( db.get_comment( "alice", "test4" ).reward_weight == STEEMIT_100_PERCENT );

generate_blocks( db.head_block_time() + STEEMIT_MIN_ROOT_COMMENT_INTERVAL + fc::seconds( STEEMIT_BLOCK_INTERVAL ), true );

tx.operations.clear();
tx.signatures.clear();

op.permlink = "test5";

tx.operations.push_back( op );
tx.sign( alice_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

alice_post_bandwidth = STEEMIT_100_PERCENT + ( alice_post_bandwidth * ( STEEMIT_POST_AVERAGE_WINDOW - STEEMIT_MIN_ROOT_COMMENT_INTERVAL.to_seconds() - STEEMIT_BLOCK_INTERVAL ) / STEEMIT_POST_AVERAGE_WINDOW );
auto reward_weight = ( STEEMIT_POST_WEIGHT_CONSTANT * STEEMIT_100_PERCENT ) / ( alice_post_bandwidth * alice_post_bandwidth );

BOOST_REQUIRE( db.get_account( "alice" ).post_bandwidth == alice_post_bandwidth );
BOOST_REQUIRE( db.get_comment( "alice", "test5" ).reward_weight == reward_weight );
}
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_SUITE_END()
#endif

0 comments on commit 5018a34

Please sign in to comment.