Merge pull request #253 from peerplays-network/GPOS-1
GPOS-1, Testnet sync issue fix
This commit is contained in:
commit
b7cd99c35f
4 changed files with 35 additions and 49 deletions
|
|
@ -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) )
|
||||
|
|
|
|||
|
|
@ -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) ) }
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -1057,9 +1057,9 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance )
|
|||
transfer( committee_account, bob_id, core.amount( 99 ) );
|
||||
|
||||
// add some vesting to Alice, Bob
|
||||
vesting_balance_object vbo;
|
||||
create_vesting(alice_id, core.amount(150), vesting_balance_type::gpos);
|
||||
create_vesting(bob_id, core.amount(99), vesting_balance_type::gpos);
|
||||
vesting_balance_object vbo1, vbo2;
|
||||
vbo1 = create_vesting(alice_id, core.amount(150), vesting_balance_type::gpos);
|
||||
vbo2 = create_vesting(bob_id, core.amount(99), vesting_balance_type::gpos);
|
||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
||||
|
||||
generate_block();
|
||||
|
|
@ -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(vbo1.id, alice_id, core.amount(50), /*vesting_balance_type::gpos, */alice_private_key);
|
||||
withdraw_gpos_vesting(vbo2.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);
|
||||
|
|
@ -1076,8 +1076,8 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance )
|
|||
|
||||
// Add more 50 and 73 vesting objects and withdraw 90 from
|
||||
// total vesting balance of user
|
||||
create_vesting(alice_id, core.amount(50), vesting_balance_type::gpos);
|
||||
create_vesting(alice_id, core.amount(73), vesting_balance_type::gpos);
|
||||
vbo1 = create_vesting(alice_id, core.amount(50), vesting_balance_type::gpos);
|
||||
vbo2 = create_vesting(alice_id, core.amount(73), vesting_balance_type::gpos);
|
||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
||||
|
||||
generate_block();
|
||||
|
|
@ -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(vbo1.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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue