From 1197e2f5feb7f76fa137102c26536a3571d8858a Mon Sep 17 00:00:00 2001 From: Michael Vandeberg Date: Mon, 2 Jul 2018 21:39:07 -0700 Subject: [PATCH] Fix negative vesting withdrawals --- libraries/chain/database.cpp | 12 ++++++++++++ libraries/chain/steem_evaluator.cpp | 17 +++++++++++++++++ .../include/steemit/protocol/config.hpp | 2 +- tests/tests/operation_tests.cpp | 14 ++++++++++++-- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 4bc29b99bf..3436e5c273 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -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) ) } diff --git a/libraries/chain/steem_evaluator.cpp b/libraries/chain/steem_evaluator.cpp index a8b53d06e7..8ac5c7c013 100644 --- a/libraries/chain/steem_evaluator.cpp +++ b/libraries/chain/steem_evaluator.cpp @@ -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." ); diff --git a/libraries/protocol/include/steemit/protocol/config.hpp b/libraries/protocol/include/steemit/protocol/config.hpp index 0ef54206b3..f8baf7d85d 100644 --- a/libraries/protocol/include/steemit/protocol/config.hpp +++ b/libraries/protocol/include/steemit/protocol/config.hpp @@ -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 diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 7168e3ee66..6f6ab67eb8 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -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() );