diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 11a2b426..5b3e605f 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -800,7 +800,11 @@ uint32_t database::get_gpos_current_subperiod() // variables needed const fc::time_point_sec period_end = period_start + vesting_period; const auto number_of_subperiods = vesting_period / vesting_subperiod; - const auto now = this->head_block_time(); + auto now = this->head_block_time(); + // This might happen due to missing blocks, we really don't want to cause assert failures + if(now > period_end) { + now = period_end; + } auto seconds_since_period_start = now.sec_since_epoch() - period_start.sec_since_epoch(); FC_ASSERT(period_start <= now && now <= period_end); @@ -926,8 +930,8 @@ void rolling_period_start(database& db) if(now.sec_since_epoch() >= (period_start + vesting_period)) { // roll - db.modify(db.get_global_properties(), [now](global_property_object& p) { - p.parameters.extensions.value.gpos_period_start = now.sec_since_epoch(); + db.modify(db.get_global_properties(), [period_start, vesting_period](global_property_object& p) { + p.parameters.extensions.value.gpos_period_start = period_start + vesting_period; }); } } diff --git a/tests/tests/gpos_tests.cpp b/tests/tests/gpos_tests.cpp index aa9969ee..6ec880a9 100644 --- a/tests/tests/gpos_tests.cpp +++ b/tests/tests/gpos_tests.cpp @@ -630,6 +630,7 @@ BOOST_AUTO_TEST_CASE( voting ) generate_blocks( HARDFORK_GPOS_TIME ); generate_block(); + auto now = HARDFORK_GPOS_TIME; const auto& core = asset_id_type()(db); // send some asset to alice and bob @@ -651,7 +652,6 @@ BOOST_AUTO_TEST_CASE( voting ) BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch()); // update default gpos for test speed - auto now = db.head_block_time(); // 5184000 = 60x60x24x60 = 60 days // 864000 = 60x60x24x10 = 10 days update_gpos_global(5184000, 864000, now); @@ -754,7 +754,7 @@ BOOST_AUTO_TEST_CASE( voting ) advance_x_maint(5); // a new GPOS period is in but vote from user is before the start. Whoever votes in 6th sub-period, votes will carry now = db.head_block_time(); - BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), now.sec_since_epoch()); + BOOST_CHECK_EQUAL(db.get_global_properties().parameters.gpos_period_start(), HARDFORK_GPOS_TIME.sec_since_epoch()+db.get_global_properties().parameters.gpos_period()); generate_block();