Skip to content

Commit

Permalink
Freezing comments and second payout are not properly being calculated…
Browse files Browse the repository at this point in the history
… at the discussion level steemit#177
  • Loading branch information
Michael Vandeberg committed Jul 20, 2016
1 parent f25b642 commit 3767aef
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 14 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
15 changes: 8 additions & 7 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,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 = db().has_hardfork( STEEMIT_HARDFORK_0_12__177 ) ?
db().head_block_time() + STEEMIT_CASHOUT_WINDOW_SECONDS :
db().head_block_time() + STEEMIT_CASHOUT_WINDOW_SECONDS_PRE_HF12;
com.max_cashout_time = fc::time_point_sec::maximum();
com.reward_weight = reward_weight;

Expand All @@ -334,6 +331,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 @@ -342,6 +342,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 @@ -389,7 +390,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 @@ -816,14 +817,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
151 changes: 151 additions & 0 deletions tests/tests/operation_time_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2166,5 +2166,156 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards )
FC_LOG_AND_RETHROW();
}

BOOST_AUTO_TEST_CASE( comment_freeze )
{
try
{
ACTORS( (alice)(bob)(sam)(dave) )
fund( "alice", 10000 );
fund( "bob", 10000 );
fund( "sam", 10000 );
fund( "dave", 10000 );

vest( "alice", 10000 );
vest( "bob", 10000 );
vest( "sam", 10000 );
vest( "dave", 10000 );

auto exchange_rate = price( ASSET( "1.250 TESTS" ), ASSET( "1.000 TBD" ) );
set_price_feed( exchange_rate );

signed_transaction tx;

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

tx.operations.push_back( comment );
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 );

comment.body = "test2";

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

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

vote_operation vote;
vote.weight = STEEMIT_100_PERCENT;
vote.voter = "bob";
vote.author = "alice";
vote.permlink = "test";

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

tx.operations.push_back( vote );
tx.sign( bob_private_key, db.get_chain_id() );
db.push_transaction( tx, 0 );

BOOST_REQUIRE( db.get_comment( "alice", "test" ).last_payout == fc::time_point_sec::min() );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).cashout_time != fc::time_point_sec::min() );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).cashout_time != fc::time_point_sec::maximum() );

generate_blocks( db.get_comment( "alice", "test" ).cashout_time, true );

BOOST_REQUIRE( db.get_comment( "alice", "test" ).last_payout == db.head_block_time() );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).cashout_time == db.head_block_time() + STEEMIT_SECOND_CASHOUT_WINDOW );

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

tx.operations.push_back( vote );
tx.set_expiration( db.head_block_time() + STEEMIT_MAX_TIME_UNTIL_EXPIRATION );
tx.sign( bob_private_key, db.get_chain_id() );
STEEMIT_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception );

vote.voter = "sam";

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

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

comment.body = "test3";

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

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

generate_blocks( db.get_comment( "alice", "test" ).cashout_time, true );

BOOST_REQUIRE( db.get_comment( "alice", "test" ).last_payout == db.head_block_time() );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).cashout_time == fc::time_point_sec::maximum() );

vote.voter = "sam";

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

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

BOOST_REQUIRE( db.get_comment( "alice", "test" ).cashout_time == fc::time_point_sec::maximum() );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).net_rshares.value == 0 );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).abs_rshares.value == 0 );

vote.voter = "bob";
vote.weight = STEEMIT_100_PERCENT * -1;

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

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

BOOST_REQUIRE( db.get_comment( "alice", "test" ).cashout_time == fc::time_point_sec::maximum() );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).net_rshares.value == 0 );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).abs_rshares.value == 0 );

vote.voter = "dave";
vote.weight = 0;

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

tx.operations.push_back( vote );
tx.set_expiration( db.head_block_time() + STEEMIT_MAX_TIME_UNTIL_EXPIRATION );
tx.sign( dave_private_key, db.get_chain_id() );

db.push_transaction( tx, 0 );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).cashout_time == fc::time_point_sec::maximum() );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).net_rshares.value == 0 );
BOOST_REQUIRE( db.get_comment( "alice", "test" ).abs_rshares.value == 0 );

comment.body = "test4";

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

tx.operations.push_back( comment );
tx.sign( alice_private_key, db.get_chain_id() );
STEEMIT_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception );
}
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_SUITE_END()
#endif

0 comments on commit 3767aef

Please sign in to comment.