From 78787c2a14a18ba06efb9ebbcbf611c1b5e7f271 Mon Sep 17 00:00:00 2001
From: pbattu123
Date: Thu, 24 Oct 2019 14:39:01 -0300
Subject: [PATCH] eliminate time gap between two consecutive vesting periods
---
libraries/chain/db_maint.cpp | 6 +++---
tests/tests/gpos_tests.cpp | 31 ++++++++++++++++++++-----------
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp
index 182c04fc..c983efe8 100644
--- a/libraries/chain/db_maint.cpp
+++ b/libraries/chain/db_maint.cpp
@@ -833,7 +833,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) {
@@ -1390,10 +1390,10 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g
distribute_fba_balances(*this);
create_buyback_orders(*this);
- rolling_period_start(*this);
-
process_dividend_assets(*this);
+ rolling_period_start(*this);
+
struct vote_tally_helper {
database& d;
const global_property_object& props;
diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp
index 5b089685..615e76c4 100644
--- a/tests/tests/gpos_tests.cpp
+++ b/tests/tests/gpos_tests.cpp
@@ -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;
@@ -497,26 +506,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()));