Skip to content

Commit

Permalink
Merge pull request #759 from eosnetworkfoundation/elmato/fix-configch…
Browse files Browse the repository at this point in the history
…ange-trace

Fix configchange trace generation
  • Loading branch information
elmato authored Aug 9, 2024
2 parents 2fe2322 + 22e4dd9 commit 3c6ff18
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 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 @@ -58,8 +58,8 @@ struct config_wrapper {
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();
consensus_parameter_data_type get_consensus_param();
std::pair<consensus_parameter_data_type, bool> get_consensus_param_and_maybe_promote();

void set_token_contract(eosio::name token_contract); // only set during init
eosio::name get_token_contract() const;
Expand Down
2 changes: 1 addition & 1 deletion src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const

auto current_version = _config->get_evm_version_and_maybe_promote();

std::pair<const consensus_parameter_data_type &, bool> gas_param_pair = _config->get_consensus_param_and_maybe_promote();
auto gas_param_pair = _config->get_consensus_param_and_maybe_promote();
if (gas_param_pair.second) {
// should not happen
eosio::check(current_version >= 1, "gas param change requires evm_version >= 1");
Expand Down
4 changes: 2 additions & 2 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ void config_wrapper::update_consensus_parameters2(std::optional<uint64_t> gas_tx
set_dirty();
}

const consensus_parameter_data_type& config_wrapper::get_consensus_param() {
consensus_parameter_data_type config_wrapper::get_consensus_param() {
// should not happen
eosio::check(_cached_config.consensus_parameter.has_value(), "consensus_parameter not exist");
return _cached_config.consensus_parameter->get_value(_cached_config.genesis_time, get_current_time());
}

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

// should not happen
eosio::check(_cached_config.consensus_parameter.has_value(), "consensus_parameter not exist");
Expand Down
32 changes: 32 additions & 0 deletions tests/gas_param_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,38 @@ BOOST_FIXTURE_TEST_CASE(basic, gas_param_evm_tester) try {

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(gas_param_traces, gas_param_evm_tester) try {

init();

setversion(3, evm_account_name);
produce_blocks(2);

setgasparam(1, 2, 3, 4, 2900, evm_account_name);
produce_blocks(3);

evm_eoa evm1;
auto trace = transfer_token("alice"_n, evm_account_name, make_asset(1), evm1.address_0x());

BOOST_REQUIRE_EQUAL(trace->action_traces.size(), 5);
BOOST_ASSERT(trace->action_traces[0].act.name == "transfer"_n);
BOOST_ASSERT(trace->action_traces[1].act.name == "transfer"_n);
BOOST_ASSERT(trace->action_traces[2].act.name == "transfer"_n);
BOOST_ASSERT(trace->action_traces[3].act.name == "configchange"_n);
BOOST_ASSERT(trace->action_traces[4].act.name == "evmtx"_n);

auto cp = fc::raw::unpack<consensus_parameter_data_type>(trace->action_traces[3].act.data);

std::visit([&](auto& v){
BOOST_REQUIRE_EQUAL(v.gas_parameter.gas_txnewaccount, 1);
BOOST_REQUIRE_EQUAL(v.gas_parameter.gas_newaccount, 2);
BOOST_REQUIRE_EQUAL(v.gas_parameter.gas_txcreate, 3);
BOOST_REQUIRE_EQUAL(v.gas_parameter.gas_codedeposit, 4);
BOOST_REQUIRE_EQUAL(v.gas_parameter.gas_sset, 2900);
}, cp);

} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE(gas_param_G_txnewaccount, gas_param_evm_tester) try {

uint64_t suggested_gas_price = 150'000'000'000ull;
Expand Down

0 comments on commit 3c6ff18

Please sign in to comment.