From 86f48e5da3a48a63e677349a549efff12eabc8b4 Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Tue, 6 Aug 2024 21:15:53 -0300 Subject: [PATCH] Check price queue is empty when switching to v3 --- src/config_wrapper.cpp | 1 + tests/gas_fee_tests.cpp | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/config_wrapper.cpp b/src/config_wrapper.cpp index 66da7bec..274c6203 100644 --- a/src/config_wrapper.cpp +++ b/src/config_wrapper.cpp @@ -219,6 +219,7 @@ uint64_t config_wrapper::get_evm_version_and_maybe_promote() { void config_wrapper::set_evm_version(uint64_t new_version) { eosio::check(new_version <= eosevm::max_eos_evm_version, "Unsupported version"); + eosio::check(new_version != 3 || _cached_config.queue_front_block.value() == 0, "price queue must be empty"); auto current_version = get_evm_version_and_maybe_promote(); eosio::check(new_version > current_version, "new version must be greater than the active one"); _cached_config.evm_version->update([&](auto& v) { diff --git a/tests/gas_fee_tests.cpp b/tests/gas_fee_tests.cpp index 6698c4a6..3572d910 100644 --- a/tests/gas_fee_tests.cpp +++ b/tests/gas_fee_tests.cpp @@ -413,11 +413,6 @@ try { auto cfg = get_config(); BOOST_CHECK_EQUAL(cfg.queue_front_block.value(), 0); - eosevm::block_mapping bm(cfg.genesis_time.sec_since_epoch()); - - setversion(3, evm_account_name); - produce_blocks(2); - const auto one_gwei = 1'000'000'000ull; const auto ten_gwei = 10'000'000'000ull; @@ -434,6 +429,24 @@ try { transfer_token("alice"_n, evm_account_name, make_asset(1), evm_account_name.to_string()); }; + eosevm::block_mapping bm(cfg.genesis_time.sec_since_epoch()); + + setversion(2, evm_account_name); + produce_blocks(2); + + // Price queue must be empty before switching to v3 + setfeeparams({.gas_price = ten_gwei}); + BOOST_REQUIRE_EXCEPTION(setversion(3, evm_account_name), + eosio_assert_message_exception, + eosio_assert_message_is("price queue must be empty")); + produce_blocks(400); + trigger_prices_queue_processing(); + cfg = get_config(); + BOOST_CHECK_EQUAL(cfg.queue_front_block.value(), 0); + + setversion(3, evm_account_name); + produce_blocks(2); + // Queue change of gas_prices to overhead_price=10Gwei storage_price=1Gwei setgasprices({.overhead_price = ten_gwei, .storage_price = one_gwei}); auto t1 = (control->pending_block_time()+fc::seconds(prices_queue_grace_period)).time_since_epoch().count();