Skip to content

Commit

Permalink
Merge pull request #258 from peerplays-network/sync-develop
Browse files Browse the repository at this point in the history
sync develop with beatrice
  • Loading branch information
pbattu123 authored Jan 16, 2020
2 parents b1f2ba5 + 63750ec commit 62b8bde
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 52 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/hardfork.d/GPOS.hf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// GPOS HARDFORK Thursday, October 1, 2020 05:00:00 AM GMT
// GPOS HARDFORK Monday, 6 January 2020 01:00:00 GMT
#ifndef HARDFORK_GPOS_TIME
#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1601528400 ))
#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1578272400 ))
#endif
3 changes: 1 addition & 2 deletions libraries/chain/include/graphene/chain/protocol/vesting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) )
Expand Down
1 change: 0 additions & 1 deletion libraries/chain/proposal_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ bool proposal_object::is_authorized_to_execute(database& db) const
}
catch ( const fc::exception& e )
{
elog( "caught exception ${e} while checking authorization of proposal operations",("e", e.to_detail_string()) );
return false;
}
return true;
Expand Down
60 changes: 24 additions & 36 deletions libraries/chain/vesting_balance_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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) ) }
Expand Down
1 change: 0 additions & 1 deletion libraries/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,6 @@ class wallet_api_impl
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 );
Expand Down
20 changes: 10 additions & 10 deletions tests/tests/gpos_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1057,27 +1057,27 @@ 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();

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);
BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 99);

// 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();
Expand All @@ -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);
Expand Down

0 comments on commit 62b8bde

Please sign in to comment.