Skip to content

Commit

Permalink
other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
taokayan committed Feb 23, 2024
1 parent d39abf6 commit 0953e8d
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions include/evm_runtime/config_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ struct config_wrapper {
void set_fee_parameters(const fee_parameters& fee_params,
bool allow_any_to_be_unspecified);

void update_gas_params(eosio::asset ram_price_mb, uint64_t minimum_gas_price);
void update_gas_params2(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 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);

std::pair<const consensus_parameter_data_type &, bool> get_consensus_param_and_maybe_promote();

Expand Down
1 change: 1 addition & 0 deletions include/evm_runtime/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace evm_runtime {
static constexpr uint32_t ninety_percent = 90'000;
static constexpr uint32_t hundred_percent = 100'000;
static constexpr uint64_t one_gwei = 1'000'000'000ull;
static constexpr uint64_t gas_sset_min = 2900;

constexpr unsigned evm_precision = 18;
constexpr eosio::name token_account(eosio::name(TOKEN_ACCOUNT_NAME));
Expand Down
4 changes: 2 additions & 2 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ void evm_contract::setversion(uint64_t version) {

void evm_contract::updtgasparam(eosio::asset ram_price_mb, uint64_t minimum_gas_price) {
require_auth(get_self());
_config->update_gas_params(ram_price_mb, minimum_gas_price);
_config->update_consensus_parameters(ram_price_mb, minimum_gas_price);
}

void evm_contract::setgasparam(uint64_t gas_txnewaccount,
Expand All @@ -806,7 +806,7 @@ void evm_contract::setgasparam(uint64_t gas_txnewaccount,
uint64_t gas_codedeposit,
uint64_t gas_sset) {
require_auth(get_self());
_config->update_gas_params2(gas_txnewaccount,
_config->update_consensus_parameters2(gas_txnewaccount,
gas_newaccount,
gas_txcreate,
gas_codedeposit,
Expand Down
22 changes: 11 additions & 11 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ 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 (_cached_config.evm_version.has_value() && _cached_config.evm_version->cached_version >= 1) {
if (get_evm_version() >= 1) {
// activate in the next evm block
this->update_gas_params2(std::optional<uint64_t>(), /* gas_txnewaccount */
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 */
Expand Down Expand Up @@ -164,7 +164,7 @@ void config_wrapper::set_fee_parameters(const fee_parameters& fee_params,
set_dirty();
}

void config_wrapper::update_gas_params(eosio::asset ram_price_mb, uint64_t minimum_gas_price) {
void config_wrapper::update_consensus_parameters(eosio::asset ram_price_mb, uint64_t minimum_gas_price) {

eosio::check(ram_price_mb.symbol == token_symbol, "invalid price symbol");
eosio::check(minimum_gas_price >= one_gwei, "gas_price must >= 1Gwei");
Expand All @@ -175,25 +175,25 @@ void config_wrapper::update_gas_params(eosio::asset ram_price_mb, uint64_t minim
constexpr uint64_t contract_fixed_bytes = 606;
constexpr uint64_t storage_slot_bytes = 346;

constexpr uint64_t max_gas_per_byte = (1ull << 43) - 1;

eosio::check(gas_per_byte_f >= 0.0, "gas_per_byte must >= 0");
eosio::check(gas_per_byte_f * contract_fixed_bytes < (double)(0x7ffffffffffull), "gas_per_byte too big");
eosio::check(gas_per_byte_f * contract_fixed_bytes < (double)(max_gas_per_byte), "gas_per_byte too big");

uint64_t gas_per_byte = (uint64_t)(gas_per_byte_f + 1.0);

this->update_gas_params2(account_bytes * gas_per_byte, /* gas_txnewaccount */
this->update_consensus_parameters2(account_bytes * gas_per_byte, /* gas_txnewaccount */
account_bytes * gas_per_byte, /* gas_newaccount */
contract_fixed_bytes * gas_per_byte, /*gas_txcreate*/
gas_per_byte,/*gas_codedeposit*/
2900 + storage_slot_bytes * gas_per_byte,/*gas_sset*/
gas_sset_min + storage_slot_bytes * gas_per_byte,/*gas_sset*/
minimum_gas_price /*minimum_gas_price*/
);
}

void config_wrapper::update_gas_params2(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, std::optional<uint64_t> minimum_gas_price)
{
// for simplicity, ensure last (cached) evm_version >= 1, not touching promote logic
eosio::check(_cached_config.evm_version.has_value() && _cached_config.evm_version->cached_version >= 1,
"evm_version must >= 1");
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");
Expand All @@ -208,7 +208,7 @@ void config_wrapper::update_gas_params2(std::optional<uint64_t> gas_txnewaccount
if (gas_txcreate.has_value()) v.gas_parameter.gas_txcreate = *gas_txcreate;
if (gas_codedeposit.has_value()) v.gas_parameter.gas_codedeposit = *gas_codedeposit;
if (gas_sset.has_value()) {
eosio::check(*gas_sset >= 2900, "G_sset must >= 2900");
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;
Expand Down
8 changes: 1 addition & 7 deletions tests/gas_param_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try {
produce_block();
produce_block();

// require promoted evm_version larger or equal to 1
BOOST_REQUIRE_EXCEPTION(
updtgasparam(asset(10'0000, native_symbol), 1'000'000'000, evm_account_name),
eosio_assert_message_exception,
eosio_assert_message_is("evm_version must >= 1"));

// kick of setverion, evmtx event generated
{
evm_eoa recipient;
Expand Down Expand Up @@ -104,7 +98,7 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try {
BOOST_REQUIRE_EXCEPTION(
setgasparam(21000,21000,21000,21000,2899, evm_account_name),
eosio_assert_message_exception,
eosio_assert_message_is("G_sset must >= 2900"));
eosio_assert_message_is("gas_sset too small"));

updtgasparam(asset(10'0000, native_symbol), 1'000'000'000, evm_account_name);

Expand Down

0 comments on commit 0953e8d

Please sign in to comment.