From ea6280a1c8e934b95e4dea15e69f20946205d63c Mon Sep 17 00:00:00 2001 From: kayan Date: Thu, 7 Nov 2024 19:29:25 +0800 Subject: [PATCH 1/7] configurable ingress gas limit --- include/evm_runtime/config_wrapper.hpp | 3 +++ include/evm_runtime/evm_contract.hpp | 2 ++ include/evm_runtime/tables.hpp | 3 ++- src/actions.cpp | 8 +++++++- src/config_wrapper.cpp | 9 +++++++++ 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/include/evm_runtime/config_wrapper.hpp b/include/evm_runtime/config_wrapper.hpp index 40e54e8e..00561a92 100644 --- a/include/evm_runtime/config_wrapper.hpp +++ b/include/evm_runtime/config_wrapper.hpp @@ -57,6 +57,9 @@ struct config_wrapper { eosio::symbol get_token_symbol() const; uint64_t get_minimum_natively_representable() const; + void set_ingress_gas_limit(uint64_t gas_limit); + uint64_t get_ingress_gas_limit() const; + private: void set_queue_front_block(uint32_t block_num); diff --git a/include/evm_runtime/evm_contract.hpp b/include/evm_runtime/evm_contract.hpp index 4a761a97..81e9ec21 100644 --- a/include/evm_runtime/evm_contract.hpp +++ b/include/evm_runtime/evm_contract.hpp @@ -88,6 +88,8 @@ class [[eosio::contract]] evm_contract : public contract [[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); + [[eosio::action]] void setgaslimit(std::optional ingress_gas_limit); + // Events [[eosio::action]] void evmtx(eosio::ignore event){ eosio::check(get_sender() == get_self(), "forbidden to call"); diff --git a/include/evm_runtime/tables.hpp b/include/evm_runtime/tables.hpp index 94ed03e4..d3adf52b 100644 --- a/include/evm_runtime/tables.hpp +++ b/include/evm_runtime/tables.hpp @@ -346,8 +346,9 @@ struct [[eosio::table]] [[eosio::contract("evm_contract")]] config binary_extension consensus_parameter; binary_extension token_contract; // <- default(unset) means eosio.token binary_extension queue_front_block; + binary_extension ingress_gas_limit = 21000; - EOSLIB_SERIALIZE(config, (version)(chainid)(genesis_time)(ingress_bridge_fee)(gas_price)(miner_cut)(status)(evm_version)(consensus_parameter)(token_contract)(queue_front_block)); + EOSLIB_SERIALIZE(config, (version)(chainid)(genesis_time)(ingress_bridge_fee)(gas_price)(miner_cut)(status)(evm_version)(consensus_parameter)(token_contract)(queue_front_block)(ingress_gas_limit)); }; struct [[eosio::table]] [[eosio::contract("evm_contract")]] price_queue diff --git a/src/actions.cpp b/src/actions.cpp index a2997856..ca111c9c 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -660,7 +660,7 @@ void evm_contract::handle_evm_transfer(eosio::asset quantity, const std::string& value *= intx::uint256(_config->get_minimum_natively_representable()); auto calculate_gas_limit = [&](const evmc::address& destination) -> int64_t { - int64_t gas_limit = 21000; + int64_t gas_limit = _config->get_ingress_gas_limit(); account_table accounts(get_self(), get_self().value); auto inx = accounts.get_index<"by.address"_n>(); @@ -899,4 +899,10 @@ void evm_contract::setgasparam(uint64_t gas_txnewaccount, gas_sset); } +void evm_contract::setgaslimit(std::optional ingress_gas_limit) { + if (ingress_gas_limit.has_value()) { + _config->set_ingress_gas_limit(*ingress_gas_limit); + } +} + } //evm_runtime diff --git a/src/config_wrapper.cpp b/src/config_wrapper.cpp index cb389a7d..be8043f5 100644 --- a/src/config_wrapper.cpp +++ b/src/config_wrapper.cpp @@ -347,4 +347,13 @@ bool config_wrapper::check_gas_overflow(uint64_t gas_txcreate, uint64_t gas_code return true; } +void config_wrapper::set_ingress_gas_limit(uint64_t gas_limit) { + _cached_config.ingress_gas_limit = gas_limit; + set_dirty(); +} + +uint64_t config_wrapper::get_ingress_gas_limit() const { + return *_cached_config.ingress_gas_limit; +} + } //namespace evm_runtime From 755225523e883a1cae5008ddfd65ea7b504e304f Mon Sep 17 00:00:00 2001 From: kayan Date: Fri, 8 Nov 2024 18:03:17 +0800 Subject: [PATCH 2/7] small improvement --- src/actions.cpp | 6 ++---- src/config_wrapper.cpp | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index ca111c9c..dc42fe5b 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -899,10 +899,8 @@ void evm_contract::setgasparam(uint64_t gas_txnewaccount, gas_sset); } -void evm_contract::setgaslimit(std::optional ingress_gas_limit) { - if (ingress_gas_limit.has_value()) { - _config->set_ingress_gas_limit(*ingress_gas_limit); - } +void evm_contract::setgaslimit(uint64_t ingress_gas_limit) { + _config->set_ingress_gas_limit(ingress_gas_limit); } } //evm_runtime diff --git a/src/config_wrapper.cpp b/src/config_wrapper.cpp index be8043f5..1ebbc01b 100644 --- a/src/config_wrapper.cpp +++ b/src/config_wrapper.cpp @@ -21,6 +21,9 @@ config_wrapper::config_wrapper(eosio::name self) : _self(self), _config(self, se if (!_cached_config.queue_front_block.has_value()) { _cached_config.queue_front_block = 0; } + if (!_cached_config.ingress_gas_limit.has_value()) { + _cached_config.ingress_gas_limit = 21000; + } } config_wrapper::~config_wrapper() { From 842c562e4087aba0101c1d79a6db4e926be3d725 Mon Sep 17 00:00:00 2001 From: kayan Date: Fri, 8 Nov 2024 18:06:27 +0800 Subject: [PATCH 3/7] other improvments --- include/evm_runtime/evm_contract.hpp | 2 +- include/evm_runtime/tables.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/evm_runtime/evm_contract.hpp b/include/evm_runtime/evm_contract.hpp index 81e9ec21..a93faaf5 100644 --- a/include/evm_runtime/evm_contract.hpp +++ b/include/evm_runtime/evm_contract.hpp @@ -88,7 +88,7 @@ class [[eosio::contract]] evm_contract : public contract [[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); - [[eosio::action]] void setgaslimit(std::optional ingress_gas_limit); + [[eosio::action]] void setgaslimit(uint64_t ingress_gas_limit); // Events [[eosio::action]] void evmtx(eosio::ignore event){ diff --git a/include/evm_runtime/tables.hpp b/include/evm_runtime/tables.hpp index d3adf52b..86b7566f 100644 --- a/include/evm_runtime/tables.hpp +++ b/include/evm_runtime/tables.hpp @@ -346,7 +346,7 @@ struct [[eosio::table]] [[eosio::contract("evm_contract")]] config binary_extension consensus_parameter; binary_extension token_contract; // <- default(unset) means eosio.token binary_extension queue_front_block; - binary_extension ingress_gas_limit = 21000; + binary_extension ingress_gas_limit; EOSLIB_SERIALIZE(config, (version)(chainid)(genesis_time)(ingress_bridge_fee)(gas_price)(miner_cut)(status)(evm_version)(consensus_parameter)(token_contract)(queue_front_block)(ingress_gas_limit)); }; From 155897112f26f945e55b3752feb20af2b8cfec35 Mon Sep 17 00:00:00 2001 From: kayan Date: Fri, 8 Nov 2024 19:30:30 +0800 Subject: [PATCH 4/7] fix cicd --- .github/workflows/contract.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/contract.yml b/.github/workflows/contract.yml index 6aa215ed..8742b82e 100644 --- a/.github/workflows/contract.yml +++ b/.github/workflows/contract.yml @@ -68,7 +68,7 @@ jobs: owner: AntelopeIO repo: spring file: 'antelope-spring-dev.*ubuntu22\.04_amd64.deb' - target: 'main' + target: '1' prereleases: false artifact-name: antelope-spring-dev-ubuntu22-amd64 container-package: antelope-spring-experimental-binaries From fdfb0ba090f88cf69d40b930dbfd3bf94da1334d Mon Sep 17 00:00:00 2001 From: Kayan <37097018+taokayan@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:58:07 +0800 Subject: [PATCH 5/7] Update contract.yml --- .github/workflows/contract.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/contract.yml b/.github/workflows/contract.yml index c46a67ec..60dd7328 100644 --- a/.github/workflows/contract.yml +++ b/.github/workflows/contract.yml @@ -70,7 +70,7 @@ jobs: owner: AntelopeIO repo: spring file: 'antelope-spring-dev.*ubuntu22\.04_amd64.deb' - target: '1' + target: 'main' prereleases: false artifact-name: antelope-spring-dev-ubuntu22-amd64 container-package: antelope-spring-experimental-binaries From f3e94d3662b729a8e939e51762b9b02fbc460d9f Mon Sep 17 00:00:00 2001 From: kayan Date: Tue, 19 Nov 2024 16:18:08 +0800 Subject: [PATCH 6/7] fix unit tests --- tests/basic_evm_tester.cpp | 5 +++++ tests/basic_evm_tester.hpp | 1 + 2 files changed, 6 insertions(+) diff --git a/tests/basic_evm_tester.cpp b/tests/basic_evm_tester.cpp index e05a0c75..1fe61460 100644 --- a/tests/basic_evm_tester.cpp +++ b/tests/basic_evm_tester.cpp @@ -103,6 +103,11 @@ namespace fc { namespace raw { fc::raw::unpack(ds, queue_front_block); tmp.queue_front_block.emplace(queue_front_block); } + if(ds.remaining()) { + uint64_t ingress_gas_limit; + fc::raw::unpack(ds, ingress_gas_limit); + tmp.ingress_gas_limit.emplace(ingress_gas_limit); + } if(ds.remaining()) { evm_test::gas_prices_type prices; fc::raw::unpack(ds, prices); diff --git a/tests/basic_evm_tester.hpp b/tests/basic_evm_tester.hpp index 481ede80..cdf3b80d 100644 --- a/tests/basic_evm_tester.hpp +++ b/tests/basic_evm_tester.hpp @@ -118,6 +118,7 @@ struct config_table_row std::optional consensus_parameter; std::optional token_contract; std::optional queue_front_block; + std::optional ingress_gas_limit; std::optional gas_prices; }; From 65c08b99952da0cf8dd7ba0e172093e6ea1cf63e Mon Sep 17 00:00:00 2001 From: kayan Date: Tue, 19 Nov 2024 16:19:55 +0800 Subject: [PATCH 7/7] fix test --- .github/workflows/contract.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/contract.yml b/.github/workflows/contract.yml index c46a67ec..60dd7328 100644 --- a/.github/workflows/contract.yml +++ b/.github/workflows/contract.yml @@ -70,7 +70,7 @@ jobs: owner: AntelopeIO repo: spring file: 'antelope-spring-dev.*ubuntu22\.04_amd64.deb' - target: '1' + target: 'main' prereleases: false artifact-name: antelope-spring-dev-ubuntu22-amd64 container-package: antelope-spring-experimental-binaries