Skip to content

Commit

Permalink
Merge pull request #2583 from steemit/20180702-fix-vesting-withdrawal…
Browse files Browse the repository at this point in the history
…-stable

Fix negative vesting withdrawals
  • Loading branch information
Michael Vandeberg authored Jul 3, 2018
2 parents dc3b417 + 1197e2f commit ecb2a90
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 3 deletions.
12 changes: 12 additions & 0 deletions libraries/chain/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ void database::open( const fc::path& data_dir, const fc::path& shared_mem_dir, u
{
init_hardforks(); // Writes to local state, but reads from db
});

auto account = find< account_object, by_name >( "nijeah" );
if( account != nullptr && account->to_withdraw < 0 )
{
auto session = start_undo_session( true );
modify( *account, []( account_object& a )
{
a.to_withdraw = 0;
a.next_vesting_withdrawal = fc::time_point_sec::maximum();
});
session.squash();
}
}
FC_CAPTURE_LOG_AND_RETHROW( (data_dir)(shared_mem_dir)(shared_file_size) )
}
Expand Down
17 changes: 17 additions & 0 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,23 @@ void withdraw_vesting_evaluator::do_apply( const withdraw_vesting_operation& o )
{
const auto& account = _db.get_account( o.account );

if( o.vesting_shares.amount < 0 )
{
// TODO: Update this to a HF 20 check
#ifndef IS_TEST_NET
if( _db.head_block_num() > 23847548 )
{
#endif
FC_ASSERT( false, "Cannot withdraw negative VESTS. account: ${account}, vests:${vests}",
("account", o.account)("vests", o.vesting_shares) );
#ifndef IS_TEST_NET
}
#endif

// else, no-op
return;
}

FC_ASSERT( account.vesting_shares >= asset( 0, VESTS_SYMBOL ), "Account does not have sufficient Steem Power for withdraw." );
FC_ASSERT( account.vesting_shares - account.delegated_vesting_shares >= o.vesting_shares, "Account does not have sufficient Steem Power for withdraw." );

Expand Down
2 changes: 1 addition & 1 deletion libraries/protocol/include/steemit/protocol/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
#pragma once

#define STEEMIT_BLOCKCHAIN_VERSION ( version(0, 19, 3) )
#define STEEMIT_BLOCKCHAIN_VERSION ( version(0, 19, 5) )
#define STEEMIT_BLOCKCHAIN_HARDFORK_VERSION ( hardfork_version( STEEMIT_BLOCKCHAIN_VERSION ) )

#ifdef IS_TEST_NET
Expand Down
14 changes: 12 additions & 2 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,18 +1444,28 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_apply )
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );

BOOST_TEST_MESSAGE( "--- Test withdraw of existing VESTS" );
BOOST_TEST_MESSAGE( "--- Test failure withdrawing negative VESTS" );

{
const auto& alice = db.get_account( "alice" );

withdraw_vesting_operation op;
op.account = "alice";
op.vesting_shares = asset( -1, VESTS_SYMBOL );

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() );
STEEMIT_REQUIRE_THROW( db.push_transaction( tx, 0 ), fc::assert_exception );


BOOST_TEST_MESSAGE( "--- Test withdraw of existing VESTS" );
op.vesting_shares = asset( alice.vesting_shares.amount / 2, VESTS_SYMBOL );

auto old_vesting_shares = alice.vesting_shares;

signed_transaction tx;
tx.clear();
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() );
Expand Down

1 comment on commit ecb2a90

@LKNX
Copy link

@LKNX LKNX commented on ecb2a90 Jul 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these quick changes.

Please sign in to comment.