Skip to content

Commit

Permalink
Merge pull request #698 from eosnetworkfoundation/elmato/remove-min-g…
Browse files Browse the repository at this point in the history
…as-price

Remove minimum_gas_price from consensus parameters
  • Loading branch information
elmato authored Apr 11, 2024
2 parents d232ace + f212d9e commit 14342cc
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 57 deletions.
5 changes: 3 additions & 2 deletions include/evm_runtime/config_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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<uint64_t> gas_txnewaccount, std::optional<uint64_t> gas_newaccount, std::optional<uint64_t> gas_txcreate, std::optional<uint64_t> gas_codedeposit, std::optional<uint64_t> gas_sset, std::optional<uint64_t> minimum_gas_price);
void update_consensus_parameters(eosio::asset ram_price_mb, uint64_t gas_price);
void update_consensus_parameters2(std::optional<uint64_t> gas_txnewaccount, std::optional<uint64_t> gas_newaccount, std::optional<uint64_t> gas_txcreate, std::optional<uint64_t> gas_codedeposit, std::optional<uint64_t> gas_sset);

const consensus_parameter_data_type& get_consensus_param();
std::pair<const consensus_parameter_data_type &, bool> get_consensus_param_and_maybe_promote();
Expand Down
2 changes: 1 addition & 1 deletion include/evm_runtime/evm_contract.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions include/evm_runtime/runtime_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<consensus_parameter_data_v0>;

Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
7 changes: 3 additions & 4 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -835,8 +835,7 @@ void evm_contract::setgasparam(uint64_t gas_txnewaccount,
gas_newaccount,
gas_txcreate,
gas_codedeposit,
gas_sset,
std::optional<uint64_t>() /* min_gas_price*/);
gas_sset);
}

} //evm_runtime
50 changes: 14 additions & 36 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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<uint64_t>(), /* gas_txnewaccount */
std::optional<uint64_t>(), /* gas_newaccount */
std::optional<uint64_t>(), /* gas_txcreate */
std::optional<uint64_t>(), /* gas_codedeposit */
std::optional<uint64_t>(), /* 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");
}
Expand All @@ -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<double>(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<double>(hundred_percent - _cached_config.miner_cut) / hundred_percent);

constexpr uint64_t account_bytes = 347;
constexpr uint64_t contract_fixed_bytes = 606;
Expand All @@ -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<uint64_t> gas_txnewaccount, std::optional<uint64_t> gas_newaccount, std::optional<uint64_t> gas_txcreate, std::optional<uint64_t> gas_codedeposit, std::optional<uint64_t> gas_sset, std::optional<uint64_t> minimum_gas_price)
void config_wrapper::update_consensus_parameters2(std::optional<uint64_t> gas_txnewaccount, std::optional<uint64_t> gas_newaccount, std::optional<uint64_t> gas_txcreate, std::optional<uint64_t> gas_codedeposit, std::optional<uint64_t> 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;
Expand All @@ -211,7 +193,6 @@ void config_wrapper::update_consensus_parameters2(std::optional<uint64_t> 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();
Expand All @@ -230,9 +211,6 @@ std::pair<const consensus_parameter_data_type &, bool> 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();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/basic_evm_tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 3 additions & 7 deletions tests/gas_param_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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{
Expand Down

0 comments on commit 14342cc

Please sign in to comment.