Merge branch 'qa_gpos_18.04' into BLOCKBACK-155
This commit is contained in:
commit
8269c94601
7 changed files with 102 additions and 30 deletions
|
|
@ -851,7 +851,7 @@ void rolling_period_start(database& db)
|
|||
auto vesting_period = db.get_global_properties().parameters.gpos_period();
|
||||
|
||||
auto now = db.head_block_time();
|
||||
if(now.sec_since_epoch() > (period_start + vesting_period))
|
||||
if(now.sec_since_epoch() >= (period_start + vesting_period))
|
||||
{
|
||||
// roll
|
||||
db.modify(db.get_global_properties(), [now](global_property_object& p) {
|
||||
|
|
@ -1408,10 +1408,10 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
|
|||
distribute_fba_balances(*this);
|
||||
create_buyback_orders(*this);
|
||||
|
||||
process_dividend_assets(*this);
|
||||
|
||||
rolling_period_start(*this);
|
||||
|
||||
process_dividend_assets(*this);
|
||||
|
||||
struct vote_tally_helper {
|
||||
database& d;
|
||||
const global_property_object& props;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// GPOS HARDFORK Friday, March 15, 2019 11:57:28 PM
|
||||
// GPOS HARDFORK Tuesday, October 22, 2019 05:00:00 AM GMT
|
||||
#ifndef HARDFORK_GPOS_TIME
|
||||
#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1552694248 ))
|
||||
#endif
|
||||
#define HARDFORK_GPOS_TIME (fc::time_point_sec( 1571720400 ))
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -28,6 +28,16 @@ namespace graphene { namespace chain {
|
|||
|
||||
enum class vesting_balance_type { normal, gpos };
|
||||
|
||||
inline std::string get_vesting_balance_type(vesting_balance_type type) {
|
||||
switch (type) {
|
||||
case vesting_balance_type::normal:
|
||||
return "NORMAL";
|
||||
case vesting_balance_type::gpos:
|
||||
default:
|
||||
return "GPOS";
|
||||
}
|
||||
}
|
||||
|
||||
struct linear_vesting_policy_initializer
|
||||
{
|
||||
/** while vesting begins on begin_timestamp, none may be claimed before vesting_cliff_seconds have passed */
|
||||
|
|
|
|||
|
|
@ -145,7 +145,8 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan
|
|||
|
||||
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 ), "", ("now", now)("op", op)("vbo", vbo) );
|
||||
FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "${balance_type} Vested Balance cannont be withdrwan during the locking period",
|
||||
("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 ); */
|
||||
|
|
|
|||
|
|
@ -1265,6 +1265,12 @@ class wallet_api
|
|||
*/
|
||||
witness_object get_witness(string owner_account);
|
||||
|
||||
/** Returns true if the account is witness, false otherwise
|
||||
* @param owner_account the name or id of the witness account owner, or the id of the witness
|
||||
* @returns true if account is witness, false otherwise
|
||||
*/
|
||||
bool is_witness(string owner_account);
|
||||
|
||||
/** Returns information about the given committee_member.
|
||||
* @param owner_account the name or id of the committee_member account owner, or the id of the committee_member
|
||||
* @returns the information about the committee_member stored in the block chain
|
||||
|
|
@ -1969,6 +1975,7 @@ FC_API( graphene::wallet::wallet_api,
|
|||
(whitelist_account)
|
||||
(create_committee_member)
|
||||
(get_witness)
|
||||
(is_witness)
|
||||
(get_committee_member)
|
||||
(list_witnesses)
|
||||
(list_committee_members)
|
||||
|
|
|
|||
|
|
@ -1720,6 +1720,42 @@ public:
|
|||
FC_CAPTURE_AND_RETHROW( (owner_account) )
|
||||
}
|
||||
|
||||
bool is_witness(string owner_account)
|
||||
{
|
||||
try
|
||||
{
|
||||
fc::optional<witness_id_type> witness_id = maybe_id<witness_id_type>(owner_account);
|
||||
if (witness_id)
|
||||
{
|
||||
std::vector<witness_id_type> ids_to_get;
|
||||
ids_to_get.push_back(*witness_id);
|
||||
std::vector<fc::optional<witness_object>> witness_objects = _remote_db->get_witnesses(ids_to_get);
|
||||
if (witness_objects.front())
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// then maybe it's the owner account
|
||||
try
|
||||
{
|
||||
account_id_type owner_account_id = get_account_id(owner_account);
|
||||
fc::optional<witness_object> witness = _remote_db->get_witness_by_account(owner_account_id);
|
||||
if (witness)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
catch (const fc::exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
FC_CAPTURE_AND_RETHROW( (owner_account) )
|
||||
}
|
||||
|
||||
committee_member_object get_committee_member(string owner_account)
|
||||
{
|
||||
try
|
||||
|
|
@ -1969,9 +2005,14 @@ public:
|
|||
fc::optional<vesting_balance_id_type> vbid = maybe_id<vesting_balance_id_type>(witness_name);
|
||||
if( !vbid )
|
||||
{
|
||||
witness_object wit = get_witness( witness_name );
|
||||
FC_ASSERT( wit.pay_vb );
|
||||
vbid = wit.pay_vb;
|
||||
if (is_witness(witness_name))
|
||||
{
|
||||
witness_object wit = get_witness( witness_name );
|
||||
FC_ASSERT( wit.pay_vb, "Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", witness_name));
|
||||
vbid = wit.pay_vb;
|
||||
}
|
||||
else
|
||||
FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", witness_name));
|
||||
}
|
||||
|
||||
vesting_balance_object vbo = get_object< vesting_balance_object >( *vbid );
|
||||
|
|
@ -2011,12 +2052,8 @@ public:
|
|||
acct_id = get_account( account_name ).id;
|
||||
|
||||
vbos = _remote_db->get_vesting_balances( *acct_id );
|
||||
if( vbos.size() == 0 )
|
||||
{
|
||||
witness_object wit = get_witness( account_name );
|
||||
FC_ASSERT( wit.pay_vb );
|
||||
vbid = wit.pay_vb;
|
||||
}
|
||||
if( vbos.size() == 0 )
|
||||
FC_THROW("Account ${account} has no core TOKEN vested and thus its not allowed to withdraw.", ("account", account_name));
|
||||
}
|
||||
|
||||
//whether it is a witness or user, keep it in a container and iterate over to process all vesting balances and types
|
||||
|
|
@ -2080,7 +2117,7 @@ public:
|
|||
|
||||
vbo_iter = std::find_if(vbo_info.begin(), vbo_info.end(), [](vesting_balance_object_with_info const& obj){return obj.balance_type == vesting_balance_type::gpos;});
|
||||
if( vbo_info.size() == 0 || vbo_iter == vbo_info.end())
|
||||
FC_THROW("Account *** ${account} *** have insufficient or 0 vested balance(GPOS) to vote", ("account", voting_account));
|
||||
FC_THROW("Account ${account} has no core Token vested and thus she will not be allowed to vote for the committee member", ("account", voting_account));
|
||||
|
||||
account_object voting_account_object = get_account(voting_account);
|
||||
account_id_type committee_member_owner_account_id = get_account_id(committee_member);
|
||||
|
|
@ -2133,7 +2170,7 @@ public:
|
|||
|
||||
vbo_iter = std::find_if(vbo_info.begin(), vbo_info.end(), [](vesting_balance_object_with_info const& obj){return obj.balance_type == vesting_balance_type::gpos;});
|
||||
if( vbo_info.size() == 0 || vbo_iter == vbo_info.end())
|
||||
FC_THROW("Account *** ${account} *** have insufficient or 0 vested balance(GPOS) to vote", ("account", voting_account));
|
||||
FC_THROW("Account ${account} has no core Token vested and thus she will not be allowed to vote for the witness", ("account", voting_account));
|
||||
|
||||
account_object voting_account_object = get_account(voting_account);
|
||||
account_id_type witness_owner_account_id = get_account_id(witness);
|
||||
|
|
@ -2156,12 +2193,15 @@ public:
|
|||
FC_THROW("Account ${account} was already voting for witness ${witness} in the current GPOS sub-period", ("account", voting_account)("witness", witness));
|
||||
else
|
||||
update_vote_time = true; //Allow user to vote in each sub-period(Update voting time, which is reference in calculating VF)
|
||||
|
||||
if (!insert_result.second)
|
||||
FC_THROW("Account ${account} has already voted for witness ${witness}", ("account", voting_account)("witness", witness));
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned votes_removed = voting_account_object.options.votes.erase(witness_obj->vote_id);
|
||||
if (!votes_removed)
|
||||
FC_THROW("Account ${account} is already not voting for witness ${witness}", ("account", voting_account)("witness", witness));
|
||||
FC_THROW("Account ${account} has not voted for witness ${witness}", ("account", voting_account)("witness", witness));
|
||||
}
|
||||
|
||||
account_update_operation account_update_op;
|
||||
|
|
@ -4098,6 +4138,11 @@ witness_object wallet_api::get_witness(string owner_account)
|
|||
return my->get_witness(owner_account);
|
||||
}
|
||||
|
||||
bool wallet_api::is_witness(string owner_account)
|
||||
{
|
||||
return my->is_witness(owner_account);
|
||||
}
|
||||
|
||||
committee_member_object wallet_api::get_committee_member(string owner_account)
|
||||
{
|
||||
return my->get_committee_member(owner_account);
|
||||
|
|
|
|||
|
|
@ -95,6 +95,15 @@ struct gpos_fixture: database_fixture
|
|||
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), vesting_subperiod);
|
||||
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), period_start.sec_since_epoch());
|
||||
}
|
||||
|
||||
void update_maintenance_interval(uint32_t new_interval)
|
||||
{
|
||||
db.modify(db.get_global_properties(), [new_interval](global_property_object& p) {
|
||||
p.parameters.maintenance_interval = new_interval;
|
||||
});
|
||||
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, new_interval);
|
||||
}
|
||||
|
||||
void vote_for(const account_id_type account_id, const vote_id_type vote_for, const fc::ecc::private_key& key)
|
||||
{
|
||||
account_update_operation op;
|
||||
|
|
@ -526,26 +535,26 @@ BOOST_AUTO_TEST_CASE( rolling_period_start )
|
|||
// period start rolls automatically after HF
|
||||
try {
|
||||
// advance to HF
|
||||
generate_blocks(HARDFORK_GPOS_TIME);
|
||||
generate_block();
|
||||
|
||||
// update default gpos global parameters to make this thing faster
|
||||
auto now = db.head_block_time();
|
||||
update_gpos_global(518400, 86400, now);
|
||||
update_gpos_global(518400, 86400, HARDFORK_GPOS_TIME);
|
||||
generate_blocks(HARDFORK_GPOS_TIME);
|
||||
update_maintenance_interval(3600); //update maintenance interval to 1hr to evaluate sub-periods
|
||||
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, 3600);
|
||||
|
||||
auto vesting_period_1 = db.get_global_properties().parameters.gpos_period_start();
|
||||
|
||||
auto now = db.head_block_time();
|
||||
// moving outside period:
|
||||
while( db.head_block_time() <= now + fc::days(6) )
|
||||
{
|
||||
generate_block();
|
||||
}
|
||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
||||
|
||||
// rolling is here so getting the new now
|
||||
now = db.head_block_time();
|
||||
generate_block();
|
||||
|
||||
// period start rolled
|
||||
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch());
|
||||
auto vesting_period_2 = db.get_global_properties().parameters.gpos_period_start();
|
||||
|
||||
//difference between start of two consecutive vesting periods should be 6 days
|
||||
BOOST_CHECK_EQUAL(vesting_period_1 + 518400, vesting_period_2);
|
||||
}
|
||||
catch (fc::exception &e) {
|
||||
edump((e.to_detail_string()));
|
||||
|
|
|
|||
Loading…
Reference in a new issue