Beatrice hot fix(sync issue fix)

This commit is contained in:
pbattu123 2019-12-20 21:55:45 -04:00
parent 26886cc7d5
commit 054f06adc7
4 changed files with 30 additions and 44 deletions

View file

@ -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) )

View file

@ -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<vesting_balance_withdraw_operation>();
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<vesting_balance_object> 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<vesting_balance_id_type> 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) ) }

View file

@ -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 );

View file

@ -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);