From 054f06adc77489ed680c48893838d6a20a72c6cb Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Fri, 20 Dec 2019 21:55:45 -0400
Subject: [PATCH] Beatrice hot fix(sync issue fix)
---
.../graphene/chain/protocol/vesting.hpp | 3 +-
libraries/chain/vesting_balance_evaluator.cpp | 60 ++++++++-----------
libraries/wallet/wallet.cpp | 1 -
tests/tests/gpos_tests.cpp | 10 ++--
4 files changed, 30 insertions(+), 44 deletions(-)
diff --git a/libraries/chain/include/graphene/chain/protocol/vesting.hpp b/libraries/chain/include/graphene/chain/protocol/vesting.hpp
index 7c53b378..4dffb253 100644
--- a/libraries/chain/include/graphene/chain/protocol/vesting.hpp
+++ b/libraries/chain/include/graphene/chain/protocol/vesting.hpp
@@ -112,7 +112,6 @@ namespace graphene { namespace chain {
vesting_balance_id_type vesting_balance;
account_id_type owner; ///< Must be vesting_balance.owner
asset amount;
- vesting_balance_type balance_type;
account_id_type fee_payer()const { return owner; }
void validate()const
@@ -128,7 +127,7 @@ FC_REFLECT( graphene::chain::vesting_balance_create_operation::fee_parameters_ty
FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation::fee_parameters_type, (fee) )
FC_REFLECT( graphene::chain::vesting_balance_create_operation, (fee)(creator)(owner)(amount)(policy)(balance_type) )
-FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation, (fee)(vesting_balance)(owner)(amount)(balance_type) )
+FC_REFLECT( graphene::chain::vesting_balance_withdraw_operation, (fee)(vesting_balance)(owner)(amount))
FC_REFLECT(graphene::chain::linear_vesting_policy_initializer, (begin_timestamp)(vesting_cliff_seconds)(vesting_duration_seconds) )
FC_REFLECT(graphene::chain::cdd_vesting_policy_initializer, (start_claim)(vesting_seconds) )
diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp
index 94e22dca..e81383b6 100644
--- a/libraries/chain/vesting_balance_evaluator.cpp
+++ b/libraries/chain/vesting_balance_evaluator.cpp
@@ -118,19 +118,8 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance
operation_result vesting_balance_withdraw_evaluator::start_evaluate( transaction_evaluation_state& eval_state, const operation& op, bool apply )
{ try {
trx_state = &eval_state;
- database& d = db();
const auto& oper = op.get();
- const time_point_sec now = d.head_block_time();
-
- if(now >= HARDFORK_GPOS_TIME )
- {
- if(oper.fee.amount == 0)
- {
- trx_state->skip_fee_schedule_check = true;
- trx_state->skip_fee = true;
- }
- }
//check_required_authorities(op);
auto result = evaluate( oper );
@@ -143,7 +132,15 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan
const database& d = db();
const time_point_sec now = d.head_block_time();
- if(op.balance_type == vesting_balance_type::gpos)
+ const vesting_balance_object& vbo = op.vesting_balance( d );
+ if(vbo.balance_type == vesting_balance_type::normal)
+ {
+ FC_ASSERT( op.owner == vbo.owner, "", ("op.owner", op.owner)("vbo.owner", vbo.owner) );
+ FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "Account has insufficient ${balance_type} Vested Balance to withdraw",
+ ("balance_type", get_vesting_balance_type(vbo.balance_type))("now", now)("op", op)("vbo", vbo) );
+ assert( op.amount <= vbo.balance ); // is_withdraw_allowed should fail before this check is reached
+ }
+ else if(now > HARDFORK_GPOS_TIME && vbo.balance_type == vesting_balance_type::gpos)
{
const account_id_type account_id = op.owner;
vector vbos;
@@ -162,14 +159,6 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan
}
FC_ASSERT( op.amount <= total_amount, "Account has either insufficient GPOS Vested Balance or lock-in period is not matured");
}
- else
- {
- const vesting_balance_object& vbo = op.vesting_balance( d );
- FC_ASSERT( op.owner == vbo.owner, "", ("op.owner", op.owner)("vbo.owner", vbo.owner) );
- FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "Account has either insufficient ${balance_type} Vested Balance to withdraw",
- ("balance_type", get_vesting_balance_type(vbo.balance_type))("now", now)("op", op)("vbo", vbo) );
- assert( op.amount <= vbo.balance ); // is_withdraw_allowed should fail before this check is reached
- }
/* const account_object& owner_account = op.owner( d ); */
// TODO: Check asset authorizations and withdrawals
@@ -183,7 +172,21 @@ void_result vesting_balance_withdraw_evaluator::do_apply( const vesting_balance_
const time_point_sec now = d.head_block_time();
//Handling all GPOS withdrawls separately from normal and SONs(future extension).
// One request/transaction would be sufficient to withdraw from multiple vesting balance ids
- if(op.balance_type == vesting_balance_type::gpos)
+ const vesting_balance_object& vbo = op.vesting_balance( d );
+ if(vbo.balance_type == vesting_balance_type::normal)
+ {
+ // Allow zero balance objects to stick around, (1) to comply
+ // with the chain's "objects live forever" design principle, (2)
+ // if it's cashback or worker, it'll be filled up again.
+
+ d.modify( vbo, [&]( vesting_balance_object& vbo )
+ {
+ vbo.withdraw( now, op.amount );
+ } );
+
+ d.adjust_balance( op.owner, op.amount );
+ }
+ else if(now > HARDFORK_GPOS_TIME && vbo.balance_type == vesting_balance_type::gpos)
{
const account_id_type account_id = op.owner;
vector ids;
@@ -213,21 +216,6 @@ void_result vesting_balance_withdraw_evaluator::do_apply( const vesting_balance_
}
}
}
- else
- {
- const vesting_balance_object& vbo = op.vesting_balance( d );
-
- // Allow zero balance objects to stick around, (1) to comply
- // with the chain's "objects live forever" design principle, (2)
- // if it's cashback or worker, it'll be filled up again.
-
- d.modify( vbo, [&]( vesting_balance_object& vbo )
- {
- vbo.withdraw( now, op.amount );
- } );
-
- d.adjust_balance( op.owner, op.amount );
- }
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp
index d4d72771..ab6f5bb7 100644
--- a/libraries/wallet/wallet.cpp
+++ b/libraries/wallet/wallet.cpp
@@ -2141,7 +2141,6 @@ public:
vesting_balance_withdraw_op.vesting_balance = vbo.id;
vesting_balance_withdraw_op.owner = vbo.owner;
vesting_balance_withdraw_op.amount = asset_obj.amount_from_string(amount);
- vesting_balance_withdraw_op.balance_type = vesting_balance_type::gpos;
signed_transaction tx;
tx.operations.push_back( vesting_balance_withdraw_op );
diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp
index 436052e7..e9543d60 100644
--- a/tests/tests/gpos_tests.cpp
+++ b/tests/tests/gpos_tests.cpp
@@ -72,13 +72,13 @@ struct gpos_fixture: database_fixture
}
void withdraw_gpos_vesting(const vesting_balance_id_type v_bid, const account_id_type owner, const asset amount,
- const vesting_balance_type type, const fc::ecc::private_key& key)
+ /*const vesting_balance_type type, */const fc::ecc::private_key& key)
{
vesting_balance_withdraw_operation op;
op.vesting_balance = v_bid;
op.owner = owner;
op.amount = amount;
- op.balance_type = type;
+ //op.balance_type = type;
trx.operations.push_back(op);
set_expiration(db, trx);
@@ -1067,8 +1067,8 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance )
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_blocks(db.get_global_properties().parameters.gpos_vesting_lockin_period());
BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 350);
- withdraw_gpos_vesting(vbo.id, alice_id, core.amount(50), vesting_balance_type::gpos, alice_private_key);
- withdraw_gpos_vesting(vbo.id, bob_id, core.amount(99), vesting_balance_type::gpos, bob_private_key);
+ withdraw_gpos_vesting(vbo.id, alice_id, core.amount(50), /*vesting_balance_type::gpos, */alice_private_key);
+ withdraw_gpos_vesting(vbo.id, bob_id, core.amount(99), /*vesting_balance_type::gpos, */bob_private_key);
generate_block();
// verify charles balance
BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 400);
@@ -1095,7 +1095,7 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance )
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_blocks(db.get_global_properties().parameters.gpos_vesting_lockin_period());
BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 277);
- withdraw_gpos_vesting(vbo.id, alice_id, core.amount(90), vesting_balance_type::gpos, alice_private_key);
+ withdraw_gpos_vesting(vbo.id, alice_id, core.amount(90), /*vesting_balance_type::gpos,*/ alice_private_key);
generate_block();
// verify alice balance
BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 367);