diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 55a531ab..5c09b395 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -272,8 +272,7 @@ void database::process_budget() }); modify(dpo, [&]( dynamic_global_property_object& _dpo ) { - // Should this be +=? - _dpo.witness_budget = witness_budget; + _dpo.witness_budget += witness_budget; _dpo.last_budget_time = now; }); @@ -406,8 +405,10 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g next_maintenance_time = time_point_sec() + (((next_block.timestamp.sec_since_epoch() / maintenance_interval) + 1) * maintenance_interval); else - next_maintenance_time += maintenance_interval; - assert( next_maintenance_time > next_block.timestamp ); + // It's possible we have missed blocks for at least a maintenance interval. + // In this case, we'll need to bump the next maintenance time more than once. + do next_maintenance_time += maintenance_interval; + while( next_maintenance_time < head_block_time() ); } modify(get_dynamic_global_properties(), [next_maintenance_time](dynamic_global_property_object& d) { diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index d396826b..fcecaa43 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -274,8 +274,9 @@ void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_i { if( miss_intermediate_blocks ) { + generate_block(); auto slots_to_miss = db.get_slot_at_time(timestamp) - 1; - assert(slots_to_miss > 0); + if( slots_to_miss <= 0 ) return; generate_block(~0, generate_private_key("genesis"), slots_to_miss); return; } diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index f17e7cd2..649df558 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -126,7 +126,7 @@ struct database_fixture { * @brief Generates blocks until the head block time matches or exceeds timestamp * @param timestamp target time to generate blocks until */ - void generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks = false); + void generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks = true); account_create_operation make_account( const std::string& name = "nathan", diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 169fb2f7..0fed7963 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -568,7 +568,7 @@ BOOST_FIXTURE_TEST_CASE( short_order_expiration, database_fixture ) BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 ); auto id = short_itr->id; - generate_blocks(op.expiration); + generate_blocks(op.expiration, false); test = &get_asset("TEST"); core = &asset_id_type()(db); nathan = &get_account("nathan"); @@ -611,7 +611,7 @@ BOOST_FIXTURE_TEST_CASE( limit_order_expiration, database_fixture ) BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 ); auto id = limit_itr->id; - generate_blocks(op.expiration); + generate_blocks(op.expiration, false); test = &get_asset("TEST"); core = &asset_id_type()(db); nathan = &get_account("nathan"); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 7e72bbbf..aaebbdc1 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -671,9 +671,12 @@ BOOST_AUTO_TEST_CASE( refund_worker_test ) } // auto supply = asset_id_type()(db).dynamic_data(db).current_supply; + verify_asset_supplies(); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + verify_asset_supplies(); BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().total_burned.value, 1000); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); + verify_asset_supplies(); BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().total_burned.value, 2000); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); BOOST_CHECK(!db.get(worker_id_type()).is_active(db.head_block_time()));