From 7ad30b6abf779734ea9d08cbbe98b44924c3d06e Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Mon, 8 Apr 2024 14:27:20 -0300 Subject: [PATCH 1/3] Remove minimum_gas_price from consensus parameters --- include/evm_runtime/config_wrapper.hpp | 5 +-- include/evm_runtime/evm_contract.hpp | 2 +- include/evm_runtime/runtime_config.hpp | 3 +- silkworm | 2 +- src/CMakeLists.txt | 2 +- src/actions.cpp | 7 ++-- src/config_wrapper.cpp | 50 ++++++++------------------ tests/basic_evm_tester.cpp | 4 +-- tests/basic_evm_tester.hpp | 2 +- tests/gas_param_tests.cpp | 10 ++---- 10 files changed, 30 insertions(+), 57 deletions(-) diff --git a/include/evm_runtime/config_wrapper.hpp b/include/evm_runtime/config_wrapper.hpp index 453cff14..7451070c 100644 --- a/include/evm_runtime/config_wrapper.hpp +++ b/include/evm_runtime/config_wrapper.hpp @@ -28,6 +28,7 @@ struct config_wrapper { void set_ingress_bridge_fee(const eosio::asset& ingress_bridge_fee); uint64_t get_gas_price()const; + void set_gas_price(uint64_t gas_price); uint32_t get_miner_cut()const; void set_miner_cut(uint32_t miner_cut); @@ -42,8 +43,8 @@ struct config_wrapper { void set_fee_parameters(const fee_parameters& fee_params, bool allow_any_to_be_unspecified); - void update_consensus_parameters(eosio::asset ram_price_mb, uint64_t minimum_gas_price); - void update_consensus_parameters2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset, std::optional minimum_gas_price); + void update_consensus_parameters(eosio::asset ram_price_mb, uint64_t gas_price); + void update_consensus_parameters2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset); const consensus_parameter_data_type& get_consensus_param(); std::pair get_consensus_param_and_maybe_promote(); diff --git a/include/evm_runtime/evm_contract.hpp b/include/evm_runtime/evm_contract.hpp index 78005139..1a8d67db 100644 --- a/include/evm_runtime/evm_contract.hpp +++ b/include/evm_runtime/evm_contract.hpp @@ -85,7 +85,7 @@ class [[eosio::contract]] evm_contract : public contract [[eosio::action]] void setversion(uint64_t version); - [[eosio::action]] void updtgasparam(eosio::asset ram_price_mb, uint64_t minimum_gas_price); + [[eosio::action]] void updtgasparam(eosio::asset ram_price_mb, uint64_t gas_price); [[eosio::action]] void setgasparam(uint64_t gas_txnewaccount, uint64_t gas_newaccount, uint64_t gas_txcreate, uint64_t gas_codedeposit, uint64_t gas_sset); // Events diff --git a/include/evm_runtime/runtime_config.hpp b/include/evm_runtime/runtime_config.hpp index 7e12985c..2f48fa93 100644 --- a/include/evm_runtime/runtime_config.hpp +++ b/include/evm_runtime/runtime_config.hpp @@ -16,8 +16,7 @@ struct gas_parameter_type { uint64_t gas_sset = 20000; }; struct consensus_parameter_data_v0 { - uint64_t minimum_gas_price = 0; - gas_parameter_type gas_parameter; + gas_parameter_type gas_parameter; }; using consensus_parameter_data_type = std::variant; diff --git a/silkworm b/silkworm index d3e6ead8..ee4b4a03 160000 --- a/silkworm +++ b/silkworm @@ -1 +1 @@ -Subproject commit d3e6ead809e9a5049d169d5eb8dfb0fa86d98db2 +Subproject commit ee4b4a03b07688139b48b329023edcde315d39b4 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7003b9c..c473de02 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -92,5 +92,5 @@ target_compile_options(evm_runtime PUBLIC --no-missing-ricardian-clause) if (WITH_LARGE_STACK) target_link_options(evm_runtime PUBLIC --stack-size=50000000) else() - target_link_options(evm_runtime PUBLIC --stack-size=35248) + target_link_options(evm_runtime PUBLIC --stack-size=35216) endif() diff --git a/src/actions.cpp b/src/actions.cpp index 8a9086f8..ce0a5d58 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -820,9 +820,9 @@ void evm_contract::setversion(uint64_t version) { _config->set_evm_version(version); } -void evm_contract::updtgasparam(eosio::asset ram_price_mb, uint64_t minimum_gas_price) { +void evm_contract::updtgasparam(eosio::asset ram_price_mb, uint64_t gas_price) { require_auth(get_self()); - _config->update_consensus_parameters(ram_price_mb, minimum_gas_price); + _config->update_consensus_parameters(ram_price_mb, gas_price); } void evm_contract::setgasparam(uint64_t gas_txnewaccount, @@ -835,8 +835,7 @@ void evm_contract::setgasparam(uint64_t gas_txnewaccount, gas_newaccount, gas_txcreate, gas_codedeposit, - gas_sset, - std::optional() /* min_gas_price*/); + gas_sset); } } //evm_runtime diff --git a/src/config_wrapper.cpp b/src/config_wrapper.cpp index f831c94a..f65e3ae6 100644 --- a/src/config_wrapper.cpp +++ b/src/config_wrapper.cpp @@ -11,9 +11,6 @@ config_wrapper::config_wrapper(eosio::name self) : _self(self), _config(self, se } if (!_cached_config.consensus_parameter.has_value()) { _cached_config.consensus_parameter = consensus_parameter_type(); - std::visit([&](auto &v) { - v.minimum_gas_price = _cached_config.gas_price; - }, _cached_config.consensus_parameter->current); // Don't set dirty because action can be read-only. } } @@ -72,9 +69,12 @@ void config_wrapper::set_ingress_bridge_fee(const eosio::asset& ingress_bridge_f } uint64_t config_wrapper::get_gas_price()const { - return std::visit([&](const auto& v) { - return v.minimum_gas_price; - }, _cached_config.consensus_parameter->get_consensus_param(_cached_config.genesis_time, get_current_time())); + return _cached_config.gas_price; +} + +void config_wrapper::set_gas_price(uint64_t gas_price) { + _cached_config.gas_price = gas_price; + set_dirty(); } uint32_t config_wrapper::get_miner_cut()const { @@ -127,22 +127,7 @@ void config_wrapper::set_fee_parameters(const fee_parameters& fee_params, { if (fee_params.gas_price.has_value()) { eosio::check(*fee_params.gas_price >= one_gwei, "gas_price must >= 1Gwei"); - if (get_evm_version() >= 1) { - // activate in the next evm block - this->update_consensus_parameters2(std::optional(), /* gas_txnewaccount */ - std::optional(), /* gas_newaccount */ - std::optional(), /* gas_txcreate */ - std::optional(), /* gas_codedeposit */ - std::optional(), /* gas_sset */ - *fee_params.gas_price /* minimum_gas_price */ - ); - } else { - _cached_config.gas_price = *fee_params.gas_price; - std::visit([&](auto &v) { - v.minimum_gas_price = _cached_config.gas_price; - }, - _cached_config.consensus_parameter->current); - } + _cached_config.gas_price = *fee_params.gas_price; } else { eosio::check(allow_any_to_be_unspecified, "All required fee parameters not specified: missing gas_price"); } @@ -164,12 +149,12 @@ void config_wrapper::set_fee_parameters(const fee_parameters& fee_params, set_dirty(); } -void config_wrapper::update_consensus_parameters(eosio::asset ram_price_mb, uint64_t minimum_gas_price) { +void config_wrapper::update_consensus_parameters(eosio::asset ram_price_mb, uint64_t gas_price) { eosio::check(ram_price_mb.symbol == token_symbol, "invalid price symbol"); - eosio::check(minimum_gas_price >= one_gwei, "gas_price must >= 1Gwei"); + eosio::check(gas_price >= one_gwei, "gas_price must >= 1Gwei"); - double gas_per_byte_f = (ram_price_mb.amount / (1024.0 * 1024.0) * minimum_natively_representable_f) / (minimum_gas_price * static_cast(hundred_percent - _cached_config.miner_cut) / hundred_percent); + double gas_per_byte_f = (ram_price_mb.amount / (1024.0 * 1024.0) * minimum_natively_representable_f) / (gas_price * static_cast(hundred_percent - _cached_config.miner_cut) / hundred_percent); constexpr uint64_t account_bytes = 347; constexpr uint64_t contract_fixed_bytes = 606; @@ -186,22 +171,19 @@ void config_wrapper::update_consensus_parameters(eosio::asset ram_price_mb, uint account_bytes * gas_per_byte, /* gas_newaccount */ contract_fixed_bytes * gas_per_byte, /*gas_txcreate*/ gas_per_byte,/*gas_codedeposit*/ - gas_sset_min + storage_slot_bytes * gas_per_byte,/*gas_sset*/ - minimum_gas_price /*minimum_gas_price*/ + gas_sset_min + storage_slot_bytes * gas_per_byte /*gas_sset*/ ); + + set_gas_price(gas_price); } -void config_wrapper::update_consensus_parameters2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset, std::optional minimum_gas_price) +void config_wrapper::update_consensus_parameters2(std::optional gas_txnewaccount, std::optional gas_newaccount, std::optional gas_txcreate, std::optional gas_codedeposit, std::optional gas_sset) { eosio::check(get_evm_version() >= 1, "evm_version must >= 1"); // should not happen eosio::check(_cached_config.consensus_parameter.has_value(), "consensus_parameter not exist"); - if (minimum_gas_price.has_value()) { - eosio::check(*minimum_gas_price >= one_gwei, "gas_price must >= 1Gwei"); - } - _cached_config.consensus_parameter->update_consensus_param([&](auto & v) { if (gas_txnewaccount.has_value()) v.gas_parameter.gas_txnewaccount = *gas_txnewaccount; if (gas_newaccount.has_value()) v.gas_parameter.gas_newaccount = *gas_newaccount; @@ -211,7 +193,6 @@ void config_wrapper::update_consensus_parameters2(std::optional gas_tx eosio::check(*gas_sset >= gas_sset_min, "gas_sset too small"); v.gas_parameter.gas_sset = *gas_sset; } - if (minimum_gas_price.has_value()) v.minimum_gas_price = *minimum_gas_price; }, get_current_time()); set_dirty(); @@ -230,9 +211,6 @@ std::pair config_wrapper::get_conse auto pair = _cached_config.consensus_parameter->get_consensus_param_and_maybe_promote(_cached_config.genesis_time, get_current_time()); if (pair.second) { - std::visit([&](const auto &v) { - _cached_config.gas_price = v.minimum_gas_price; - }, pair.first); set_dirty(); } diff --git a/tests/basic_evm_tester.cpp b/tests/basic_evm_tester.cpp index 8c132de2..4c89b12c 100644 --- a/tests/basic_evm_tester.cpp +++ b/tests/basic_evm_tester.cpp @@ -433,9 +433,9 @@ transaction_trace_ptr basic_evm_tester::setversion(uint64_t version, name actor) mvo()("version", version)); } -transaction_trace_ptr basic_evm_tester::updtgasparam(asset ram_price_mb, uint64_t minimum_gas_price, name actor) { +transaction_trace_ptr basic_evm_tester::updtgasparam(asset ram_price_mb, uint64_t gas_price, name actor) { return basic_evm_tester::push_action(evm_account_name, "updtgasparam"_n, actor, - mvo()("ram_price_mb", ram_price_mb)("minimum_gas_price", minimum_gas_price)); + mvo()("ram_price_mb", ram_price_mb)("gas_price", gas_price)); } transaction_trace_ptr basic_evm_tester::setgasparam(uint64_t gas_txnewaccount, diff --git a/tests/basic_evm_tester.hpp b/tests/basic_evm_tester.hpp index ec6ecaea..f6184476 100644 --- a/tests/basic_evm_tester.hpp +++ b/tests/basic_evm_tester.hpp @@ -404,7 +404,7 @@ class basic_evm_tester : public evm_validating_tester transaction_trace_ptr call(name from, const evmc::bytes& to, const evmc::bytes& value, evmc::bytes& data, uint64_t gas_limit, name actor); transaction_trace_ptr admincall(const evmc::bytes& from, const evmc::bytes& to, const evmc::bytes& value, evmc::bytes& data, uint64_t gas_limit, name actor); evmc::address deploy_contract(evm_eoa& eoa, evmc::bytes bytecode); - transaction_trace_ptr updtgasparam(asset ram_price_mb, uint64_t minimum_gas_price, name actor); + transaction_trace_ptr updtgasparam(asset ram_price_mb, uint64_t gas_price, name actor); transaction_trace_ptr setgasparam(uint64_t gas_txnewaccount, uint64_t gas_newaccount, uint64_t gas_txcreate, diff --git a/tests/gas_param_tests.cpp b/tests/gas_param_tests.cpp index 87735ac4..e04cbfd7 100644 --- a/tests/gas_param_tests.cpp +++ b/tests/gas_param_tests.cpp @@ -108,6 +108,7 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try { eosio_assert_message_exception, eosio_assert_message_is("gas_sset too small")); + // This change in the gas price now takes effect immediately updtgasparam(asset(10'0000, native_symbol), 1'000'000'000, evm_account_name); setgasparam(21000,21000,21000,21000,2900, evm_account_name); @@ -124,19 +125,14 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try { .value = 1, } }; - uint64_t cur_nonce = faucet_eoa.next_nonce; faucet_eoa.sign(tx); - BOOST_REQUIRE_EXCEPTION( - pushtx(tx), - eosio_assert_message_exception, - eosio_assert_message_is("gas price is too low")); - faucet_eoa.next_nonce = cur_nonce; + BOOST_CHECK_NO_THROW(pushtx(tx)); } produce_block(); produce_block(); - // new gas price take effect in the next evm block, configchange event before evmtx + // new gas params take effect in the next evm block, configchange event before evmtx { evm_eoa recipient; silkworm::Transaction tx{ From 876f2659e89c5faed91bb9d595802603472f322e Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Mon, 8 Apr 2024 15:23:42 -0300 Subject: [PATCH 2/3] Update silkworm --- silkworm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/silkworm b/silkworm index ee4b4a03..0636dd04 160000 --- a/silkworm +++ b/silkworm @@ -1 +1 @@ -Subproject commit ee4b4a03b07688139b48b329023edcde315d39b4 +Subproject commit 0636dd04391d11462ee42129c20619ff042017e5 From f212d9e2152feecd49edc81e58bdcfadee9035ed Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Tue, 9 Apr 2024 14:45:57 -0300 Subject: [PATCH 3/3] Update silkworm --- silkworm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/silkworm b/silkworm index 0636dd04..b9554f89 160000 --- a/silkworm +++ b/silkworm @@ -1 +1 @@ -Subproject commit 0636dd04391d11462ee42129c20619ff042017e5 +Subproject commit b9554f894184fa09408170bb9ee0ae3febb10ced