Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0->main] configurable ingress gas limit #782

Merged
merged 10 commits into from
Nov 19, 2024
3 changes: 3 additions & 0 deletions include/evm_runtime/config_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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);

Expand Down
1 change: 1 addition & 0 deletions include/evm_runtime/evm_contract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class [[eosio::contract]] evm_contract : public contract
[[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 setgasprices(const gas_prices_type& prices);
[[eosio::action]] void setgaslimit(uint64_t ingress_gas_limit);

// Events
[[eosio::action]] void evmtx(eosio::ignore<evm_runtime::evmtx_type> event){
Expand Down
3 changes: 2 additions & 1 deletion include/evm_runtime/tables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,10 @@ struct [[eosio::table]] [[eosio::contract("evm_contract")]] config
binary_extension<value_promoter_consensus_parameter_data_type> consensus_parameter;
binary_extension<eosio::name> token_contract; // <- default(unset) means eosio.token
binary_extension<uint32_t> queue_front_block;
binary_extension<uint64_t> ingress_gas_limit;
binary_extension<gas_prices_type> gas_prices;

EOSLIB_SERIALIZE(config, (version)(chainid)(genesis_time)(ingress_bridge_fee)(gas_price)(miner_cut)(status)(evm_version)(consensus_parameter)(token_contract)(queue_front_block)(gas_prices));
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)(gas_prices));
};

struct [[eosio::table]] [[eosio::contract("evm_contract")]] price_queue
Expand Down
6 changes: 5 additions & 1 deletion src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,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>();
Expand Down Expand Up @@ -916,4 +916,8 @@ void evm_contract::setgasprices(const gas_prices_type& prices) {
}
}

void evm_contract::setgaslimit(uint64_t ingress_gas_limit) {
_config->set_ingress_gas_limit(ingress_gas_limit);
}

} //evm_runtime
12 changes: 12 additions & 0 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ config_wrapper::config_wrapper(eosio::name self) : _self(self), _config(self, se
if (!_cached_config.gas_prices.has_value()) {
_cached_config.gas_prices = gas_prices_type{};
}
if (!_cached_config.ingress_gas_limit.has_value()) {
_cached_config.ingress_gas_limit = 21000;
}
}

config_wrapper::~config_wrapper() {
Expand Down Expand Up @@ -395,4 +398,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
5 changes: 5 additions & 0 deletions tests/basic_evm_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ struct config_table_row
std::optional<consensus_parameter_type> consensus_parameter;
std::optional<name> token_contract;
std::optional<uint32_t> queue_front_block;
std::optional<uint64_t> ingress_gas_limit;
std::optional<gas_prices_type> gas_prices;
};

Expand Down