Dramatically accelerate chain_test, fix core asset burn bug
When generating blocks until a timestamp, we now generate one block immediately, then skip blocks until the timestamp, and generate a final block then. Also, this exposed a bug in the witness budget handling which caused the undesired burning of core asset. This bug is now fixed.
This commit is contained in:
parent
c9328cc7f4
commit
8f739ac767
5 changed files with 13 additions and 8 deletions
|
|
@ -272,8 +272,7 @@ void database::process_budget()
|
||||||
});
|
});
|
||||||
modify(dpo, [&]( dynamic_global_property_object& _dpo )
|
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;
|
_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_maintenance_time = time_point_sec() +
|
||||||
(((next_block.timestamp.sec_since_epoch() / maintenance_interval) + 1) * maintenance_interval);
|
(((next_block.timestamp.sec_since_epoch() / maintenance_interval) + 1) * maintenance_interval);
|
||||||
else
|
else
|
||||||
next_maintenance_time += maintenance_interval;
|
// It's possible we have missed blocks for at least a maintenance interval.
|
||||||
assert( next_maintenance_time > next_block.timestamp );
|
// 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) {
|
modify(get_dynamic_global_properties(), [next_maintenance_time](dynamic_global_property_object& d) {
|
||||||
|
|
|
||||||
|
|
@ -274,8 +274,9 @@ void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_i
|
||||||
{
|
{
|
||||||
if( miss_intermediate_blocks )
|
if( miss_intermediate_blocks )
|
||||||
{
|
{
|
||||||
|
generate_block();
|
||||||
auto slots_to_miss = db.get_slot_at_time(timestamp) - 1;
|
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);
|
generate_block(~0, generate_private_key("genesis"), slots_to_miss);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ struct database_fixture {
|
||||||
* @brief Generates blocks until the head block time matches or exceeds timestamp
|
* @brief Generates blocks until the head block time matches or exceeds timestamp
|
||||||
* @param timestamp target time to generate blocks until
|
* @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(
|
account_create_operation make_account(
|
||||||
const std::string& name = "nathan",
|
const std::string& name = "nathan",
|
||||||
|
|
|
||||||
|
|
@ -568,7 +568,7 @@ BOOST_FIXTURE_TEST_CASE( short_order_expiration, database_fixture )
|
||||||
BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 );
|
BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 );
|
||||||
auto id = short_itr->id;
|
auto id = short_itr->id;
|
||||||
|
|
||||||
generate_blocks(op.expiration);
|
generate_blocks(op.expiration, false);
|
||||||
test = &get_asset("TEST");
|
test = &get_asset("TEST");
|
||||||
core = &asset_id_type()(db);
|
core = &asset_id_type()(db);
|
||||||
nathan = &get_account("nathan");
|
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 );
|
BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 );
|
||||||
auto id = limit_itr->id;
|
auto id = limit_itr->id;
|
||||||
|
|
||||||
generate_blocks(op.expiration);
|
generate_blocks(op.expiration, false);
|
||||||
test = &get_asset("TEST");
|
test = &get_asset("TEST");
|
||||||
core = &asset_id_type()(db);
|
core = &asset_id_type()(db);
|
||||||
nathan = &get_account("nathan");
|
nathan = &get_account("nathan");
|
||||||
|
|
|
||||||
|
|
@ -671,9 +671,12 @@ BOOST_AUTO_TEST_CASE( refund_worker_test )
|
||||||
}
|
}
|
||||||
|
|
||||||
// auto supply = asset_id_type()(db).dynamic_data(db).current_supply;
|
// auto supply = asset_id_type()(db).dynamic_data(db).current_supply;
|
||||||
|
verify_asset_supplies();
|
||||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
||||||
|
verify_asset_supplies();
|
||||||
BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get<refund_worker_type>().total_burned.value, 1000);
|
BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get<refund_worker_type>().total_burned.value, 1000);
|
||||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
||||||
|
verify_asset_supplies();
|
||||||
BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get<refund_worker_type>().total_burned.value, 2000);
|
BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get<refund_worker_type>().total_burned.value, 2000);
|
||||||
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
|
||||||
BOOST_CHECK(!db.get(worker_id_type()).is_active(db.head_block_time()));
|
BOOST_CHECK(!db.get(worker_id_type()).is_active(db.head_block_time()));
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue