Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BLOCKBACK-183 GPOS: Votes consideration on GPOS activation #237

Merged
merged 4 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions libraries/chain/account_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,6 @@ void_result account_update_evaluator::do_evaluate( const account_update_operatio
FC_ASSERT( !o.extensions.value.owner_special_authority.valid() );
FC_ASSERT( !o.extensions.value.active_special_authority.valid() );
}
if( d.head_block_time() < HARDFORK_GPOS_TIME )
FC_ASSERT( !o.extensions.value.update_last_voting_time.valid() );

try
{
Expand Down
12 changes: 11 additions & 1 deletion libraries/chain/db_maint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1560,11 +1560,19 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g

if(d.head_block_time() >= HARDFORK_GPOS_TIME)
{
if (itr == vesting_amounts.end())
if (itr == vesting_amounts.end() && d.head_block_time() >= (HARDFORK_GPOS_TIME + props.parameters.gpos_subperiod()/2))
return;

auto vesting_factor = d.calculate_vesting_factor(stake_account);
voting_stake = (uint64_t)floor(voting_stake * vesting_factor);

//Include votes(based on stake) for the period of gpos_subperiod()/2 as system has zero votes on GPOS activation
if(d.head_block_time() < (HARDFORK_GPOS_TIME + props.parameters.gpos_subperiod()/2))
{
voting_stake += stats.total_core_in_orders.value
+ (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.amount.value : 0)
+ d.get_balance(stake_account.get_id(), asset_id_type()).amount.value;
}
}
else
{
Expand Down Expand Up @@ -1644,6 +1652,8 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
p.pending_parameters->extensions.value.permitted_betting_odds_increments = p.parameters.extensions.value.permitted_betting_odds_increments;
if( !p.pending_parameters->extensions.value.live_betting_delay_time.valid() )
p.pending_parameters->extensions.value.live_betting_delay_time = p.parameters.extensions.value.live_betting_delay_time;
if( !p.pending_parameters->extensions.value.gpos_period_start.valid() )
p.pending_parameters->extensions.value.gpos_period_start = p.parameters.extensions.value.gpos_period_start;
if( !p.pending_parameters->extensions.value.gpos_period.valid() )
p.pending_parameters->extensions.value.gpos_period = p.parameters.extensions.value.gpos_period;
if( !p.pending_parameters->extensions.value.gpos_subperiod.valid() )
Expand Down
2 changes: 1 addition & 1 deletion libraries/fc
Submodule fc updated 1 files
+5 −0 src/rpc/cli.cpp
99 changes: 97 additions & 2 deletions tests/tests/gpos_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,94 @@ BOOST_AUTO_TEST_CASE( gpos_basic_dividend_distribution_to_core_asset )
}
}

BOOST_AUTO_TEST_CASE( votes_on_gpos_activation )
{
ACTORS((alice)(bob));
try {
const auto& core = asset_id_type()(db);

// send some asset to alice and bob
transfer( committee_account, alice_id, core.amount( 1000 ) );
transfer( committee_account, bob_id, core.amount( 1000 ) );
generate_block();

// update default gpos
auto now = db.head_block_time();
// 5184000 = 60x60x24x6 = 6 days
// 864000 = 60x60x24x1 = 1 days
update_gpos_global(518400, 86400, HARDFORK_GPOS_TIME);

BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period(), 518400);
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_subperiod(), 86400);
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch());
// no votes for witness 1
auto witness1 = witness_id_type(1)(db);
BOOST_CHECK_EQUAL(witness1.total_votes, 0);

// no votes for witness 2
auto witness2 = witness_id_type(2)(db);
BOOST_CHECK_EQUAL(witness2.total_votes, 0);

// vote for witness1 and witness2 - this before GPOS period starts
vote_for(alice_id, witness1.vote_id, alice_private_key);
vote_for(bob_id, witness2.vote_id, bob_private_key);

// go to maint
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

// vote is the same as amount in the first subperiod since voting
witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
BOOST_CHECK_EQUAL(witness1.total_votes, 1000);
BOOST_CHECK_EQUAL(witness2.total_votes, 1000);

update_maintenance_interval(3600); //update maintenance interval to 1hr to evaluate sub-periods
BOOST_CHECK_EQUAL(db.get_global_properties().parameters.maintenance_interval, 3600);

// move to hardfork
generate_blocks( HARDFORK_GPOS_TIME );
generate_block();

witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
BOOST_CHECK_EQUAL(witness1.total_votes, 1000);
BOOST_CHECK_EQUAL(witness2.total_votes, 1000);

// add some vesting to alice and don't add anything for Bob
create_vesting(alice_id, core.amount(99), vesting_balance_type::gpos);
generate_block();
vote_for(alice_id, witness1.vote_id, alice_private_key);
generate_block();

advance_x_maint(1);
witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
//System needs to consider votes based on both regular balance + GPOS balance for 1/2 sub-period on GPOS activation
BOOST_CHECK_EQUAL(witness1.total_votes, 1000);
BOOST_CHECK_EQUAL(witness2.total_votes, 1000);

advance_x_maint(6);
witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
BOOST_CHECK_EQUAL(witness1.total_votes, 1000);
BOOST_CHECK_EQUAL(witness2.total_votes, 1000);

advance_x_maint(5);
generate_block();
witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
//Since Alice has votes, votes should be based on GPOS balance i.e 99
//Since Bob not voted after GPOS activation, witness2 votes should be 0 after crossing 1/2 sub-period(12 maintanence intervals in this case)
BOOST_CHECK_EQUAL(witness1.total_votes, 99);
BOOST_CHECK_EQUAL(witness2.total_votes, 0);

}
catch (fc::exception &e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_CASE( voting )
{
ACTORS((alice)(bob));
Expand Down Expand Up @@ -570,13 +658,20 @@ BOOST_AUTO_TEST_CASE( voting )
// go to maint
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

// vote is the same as amount in the first subperiod since voting
// need to consider both gpos and regular balance for first 1/2 sub period
witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
BOOST_CHECK_EQUAL(witness1.total_votes, 1000);
BOOST_CHECK_EQUAL(witness2.total_votes, 1000);

advance_x_maint(6);

witness1 = witness_id_type(1)(db);
witness2 = witness_id_type(2)(db);
BOOST_CHECK_EQUAL(witness1.total_votes, 100);
BOOST_CHECK_EQUAL(witness2.total_votes, 100);

advance_x_maint(10);
advance_x_maint(4);

//Bob votes for witness2 - sub-period 2
vote_for(bob_id, witness2.vote_id, bob_private_key);
Expand Down