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

use base_fee_per_gas for exec a trx #699

Merged
merged 2 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/evm_runtime/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ namespace evm_runtime {
struct evmtx_v0 {
uint64_t eos_evm_version;
bytes rlptx;

EOSLIB_SERIALIZE(evmtx_v0, (eos_evm_version)(rlptx));
uint64_t base_fee_per_gas;

EOSLIB_SERIALIZE(evmtx_v0, (eos_evm_version)(rlptx)(base_fee_per_gas));
};

using evmtx_type = std::variant<evmtx_v0>;
Expand Down
2 changes: 1 addition & 1 deletion silkworm
18 changes: 15 additions & 3 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,14 @@ void evm_contract::exec(const exec_input& input, const std::optional<exec_callba
eosevm::block_mapping bm(_config->get_genesis_time().sec_since_epoch());

Block block;

auto evm_version = _config->get_evm_version();
std::optional<uint64_t> base_fee_per_gas;
if (evm_version >= 1) {
base_fee_per_gas = _config->get_gas_price();
}
eosevm::prepare_block_header(block.header, bm, get_self().value,
bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), _config->get_evm_version());
bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), evm_version, base_fee_per_gas);

evm_runtime::state state{get_self(), get_self(), true};
IntraBlockState ibstate{state};
Expand Down Expand Up @@ -448,8 +454,14 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
eosevm::block_mapping bm(_config->get_genesis_time().sec_since_epoch());

Block block;

std::optional<uint64_t> base_fee_per_gas;
if (current_version >= 1) {
base_fee_per_gas = _config->get_gas_price();
}

eosevm::prepare_block_header(block.header, bm, get_self().value,
bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), current_version);
bm.timestamp_to_evm_block_num(eosio::current_time_point().time_since_epoch().count()), current_version, base_fee_per_gas);

silkworm::protocol::TrustRuleSet engine{*found_chain_config->second};

Expand Down Expand Up @@ -490,7 +502,7 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
}

if (current_version >= 1) {
auto event = evmtx_type{evmtx_v0{current_version, txn.get_rlptx()}};
auto event = evmtx_type{evmtx_v0{current_version, txn.get_rlptx(), *base_fee_per_gas}};
action(std::vector<permission_level>{}, get_self(), "evmtx"_n, event)
.send();
}
Expand Down
3 changes: 2 additions & 1 deletion tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ namespace evm_test {
struct evmtx_v0 {
uint64_t eos_evm_version;
bytes rlptx;
uint64_t base_fee_per_gas;
};

using evmtx_type = std::variant<evmtx_v0>;
Expand Down Expand Up @@ -195,7 +196,7 @@ FC_REFLECT(evm_test::message_receiver, (account)(handler)(min_fee)(flags));
FC_REFLECT(evm_test::bridge_message_v0, (receiver)(sender)(timestamp)(value)(data));
FC_REFLECT(evm_test::gcstore, (id)(storage_id));
FC_REFLECT(evm_test::account_code, (id)(ref_count)(code)(code_hash));
FC_REFLECT(evm_test::evmtx_v0, (eos_evm_version)(rlptx));
FC_REFLECT(evm_test::evmtx_v0, (eos_evm_version)(rlptx)(base_fee_per_gas));

namespace evm_test {
class evm_eoa
Expand Down
31 changes: 29 additions & 2 deletions tests/version_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,16 @@ BOOST_FIXTURE_TEST_CASE(set_version, version_tester) try {
// Fund evm1 address with 100 EOS (this will NOT trigger an update of the evm version)
evm_eoa evm1;
const int64_t to_bridge = 1000000;
transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x());
auto trace0 = transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x());
BOOST_CHECK_EQUAL(trace0->action_traces.size(), 4);
BOOST_REQUIRE(trace0->action_traces[0].act.account == token_account_name);
BOOST_REQUIRE(trace0->action_traces[0].act.name == "transfer"_n);
BOOST_REQUIRE(trace0->action_traces[1].act.account == token_account_name);
BOOST_REQUIRE(trace0->action_traces[1].act.name == "transfer"_n);
BOOST_REQUIRE(trace0->action_traces[2].act.account == token_account_name);
BOOST_REQUIRE(trace0->action_traces[2].act.name == "transfer"_n);
BOOST_REQUIRE(trace0->action_traces[3].act.account == evm_account_name);
BOOST_REQUIRE(trace0->action_traces[3].act.name == "pushtx"_n);

config = get_config();
BOOST_CHECK_EQUAL(config.evm_version.has_value(), true);
Expand All @@ -127,13 +136,31 @@ BOOST_FIXTURE_TEST_CASE(set_version, version_tester) try {
}

// Fund evm1 address with 100 more EOS (this will trigger an update of the evm version)
transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x());
auto trace = transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x());
config = get_config();

BOOST_CHECK_EQUAL(config.evm_version.has_value(), true);
BOOST_CHECK_EQUAL(config.evm_version.value().cached_version, 1);
BOOST_CHECK_EQUAL(config.evm_version.value().pending_version.has_value(), false);

BOOST_CHECK_EQUAL(trace->action_traces.size(), 4);
BOOST_REQUIRE(trace->action_traces[0].act.account == token_account_name);
BOOST_REQUIRE(trace->action_traces[0].act.name == "transfer"_n);
BOOST_REQUIRE(trace->action_traces[1].act.account == token_account_name);
BOOST_REQUIRE(trace->action_traces[1].act.name == "transfer"_n);
BOOST_REQUIRE(trace->action_traces[2].act.account == token_account_name);
BOOST_REQUIRE(trace->action_traces[2].act.name == "transfer"_n);
BOOST_REQUIRE(trace->action_traces[3].act.account == evm_account_name);
BOOST_REQUIRE(trace->action_traces[3].act.name == "evmtx"_n);

auto evmtx_v = fc::raw::unpack<evm_test::evmtx_type>(
trace->action_traces[3].act.data.data(), trace->action_traces[3].act.data.size());
BOOST_REQUIRE(std::holds_alternative<evm_test::evmtx_v0>(evmtx_v));

const auto &evmtx = std::get<evm_test::evmtx_v0>(evmtx_v);
BOOST_CHECK_EQUAL(evmtx.eos_evm_version, 1);
BOOST_CHECK_EQUAL(evmtx.base_fee_per_gas, config.gas_price);

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(traces_in_different_eosevm_version, version_tester) try {
Expand Down
Loading