Skip to content

Commit

Permalink
Merge pull request #779 from eosnetworkfoundation/elmato/add-gas-para…
Browse files Browse the repository at this point in the history
…meters-scaling-tests

Add gas parameters scaling tests
  • Loading branch information
elmato authored Dec 10, 2024
2 parents dd2f2a9 + 65ed53f commit 4558425
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/contract.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
owner: AntelopeIO
repo: spring
file: 'antelope-spring-dev.*ubuntu22\.04_amd64.deb'
target: 'main'
target: '1'
prereleases: false
artifact-name: antelope-spring-dev-ubuntu22-amd64
container-package: antelope-spring-experimental-binaries
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 @@ -138,7 +138,7 @@ class [[eosio::contract]] evm_contract : public contract
void assert_inited();
void assert_unfrozen();

silkworm::Receipt execute_tx(const runtime_config& rc, eosio::name miner, silkworm::Block& block, const transaction& tx, silkworm::ExecutionProcessor& ep);
silkworm::Receipt execute_tx(const runtime_config& rc, eosio::name miner, silkworm::Block& block, const transaction& tx, silkworm::ExecutionProcessor& ep, const evmone::gas_parameters& gas_params);
void process_filtered_messages(const std::vector<silkworm::FilteredMessage>& filtered_messages);

uint64_t get_and_increment_nonce(const name owner);
Expand Down
4 changes: 4 additions & 0 deletions include/evm_runtime/tables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ struct [[eosio::table]] [[eosio::contract("evm_contract")]] config2
struct gas_prices_type {
uint64_t overhead_price{0};
uint64_t storage_price{0};

uint64_t get_base_price()const {
return std::max(overhead_price, storage_price);
}
};

using evm_version_type = uint64_t;
Expand Down
2 changes: 1 addition & 1 deletion silkworm
Submodule silkworm updated 45 files
+1 −1 CMakeLists.txt
+1 −1 cmd/dev/check_changes.cpp
+1 −1 cmd/dev/scan_txs.cpp
+1 −1 cmd/state-transition/state_transition.cpp
+1 −1 cmd/test/ethereum.cpp
+2 −0 eosevm/CMakeLists.txt
+64 −0 eosevm/refund_v3.cpp
+11 −0 eosevm/refund_v3.hpp
+1 −0 silkworm/core/CMakeLists.txt
+84 −31 silkworm/core/execution/evm.cpp
+13 −10 silkworm/core/execution/evm.hpp
+194 −45 silkworm/core/execution/evm_test.cpp
+3 −3 silkworm/core/execution/execution.hpp
+2 −2 silkworm/core/execution/execution_test.cpp
+44 −17 silkworm/core/execution/processor.cpp
+6 −4 silkworm/core/execution/processor.hpp
+318 −92 silkworm/core/execution/processor_test.cpp
+4 −5 silkworm/core/protocol/blockchain.cpp
+3 −1 silkworm/core/protocol/blockchain.hpp
+20 −0 silkworm/core/types/gas_prices.hpp
+3 −3 silkworm/node/db/access_layer_test.cpp
+3 −3 silkworm/node/stagedsync/stages/_test.cpp
+15 −0 silkworm/node/stagedsync/stages/stage.cpp
+6 −0 silkworm/node/stagedsync/stages/stage.hpp
+4 −3 silkworm/node/stagedsync/stages/stage_execution.cpp
+3 −3 silkworm/node/stagedsync/stages/stage_history_index_test.cpp
+6 −4 silkworm/node/stagedsync/stages/stage_senders.cpp
+6 −11 silkworm/silkrpc/commands/eth_api.cpp
+5 −4 silkworm/silkrpc/core/call_many.cpp
+2 −0 silkworm/silkrpc/core/call_many.hpp
+5 −5 silkworm/silkrpc/core/estimate_gas_oracle.cpp
+1 −1 silkworm/silkrpc/core/estimate_gas_oracle.hpp
+15 −15 silkworm/silkrpc/core/estimate_gas_oracle_test.cpp
+8 −8 silkworm/silkrpc/core/evm_debug.cpp
+41 −14 silkworm/silkrpc/core/evm_executor.cpp
+3 −2 silkworm/silkrpc/core/evm_executor.hpp
+6 −6 silkworm/silkrpc/core/evm_executor_test.cpp
+20 −19 silkworm/silkrpc/core/evm_trace.cpp
+14 −14 silkworm/silkrpc/core/evm_trace_test.cpp
+13 −5 silkworm/silkrpc/core/gas_parameters.cpp
+2 −1 silkworm/silkrpc/core/gas_parameters.hpp
+10 −1 silkworm/silkrpc/core/rawdb/chain.cpp
+3 −0 silkworm/silkrpc/core/rawdb/chain.hpp
+1 −1 silkworm/silkrpc/test/mock_estimate_gas_oracle.hpp
+1 −1 third_party/evmone
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ list(APPEND SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/../silkworm/silkworm/core/crypto/ecdsa.c
${CMAKE_CURRENT_SOURCE_DIR}/../silkworm/silkworm/core/crypto/secp256k1n.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../silkworm/silkworm/core/chain/config.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../silkworm/eosevm/refund_v3.cpp
)

add_contract( evm_contract evm_runtime ${SOURCES})
Expand Down
32 changes: 21 additions & 11 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void check_result( ValidationResult r, const Transaction& txn, const char* desc
eosio::check( false, std::move(err_msg));
}

Receipt evm_contract::execute_tx(const runtime_config& rc, eosio::name miner, Block& block, const transaction& txn, silkworm::ExecutionProcessor& ep) {
Receipt evm_contract::execute_tx(const runtime_config& rc, eosio::name miner, Block& block, const transaction& txn, silkworm::ExecutionProcessor& ep, const evmone::gas_parameters& gas_params) {
const auto& tx = txn.get_tx();
balances balance_table(get_self(), get_self().value);

Expand Down Expand Up @@ -241,20 +241,23 @@ Receipt evm_contract::execute_tx(const runtime_config& rc, eosio::name miner, Bl

ValidationResult r = silkworm::protocol::pre_validate_transaction(tx, ep.evm().revision(), ep.evm().config().chain_id,
ep.evm().block().header.base_fee_per_gas, ep.evm().block().header.data_gas_price(),
ep.evm().get_eos_evm_version(), ep.evm().get_gas_params());
ep.evm().get_eos_evm_version(), gas_params);

check_result( r, tx, "pre_validate_transaction error" );
r = silkworm::protocol::validate_transaction(tx, ep.state(), ep.available_gas());
check_result( r, tx, "validate_transaction error" );

Receipt receipt;
ep.execute_transaction(tx, receipt);
const auto res = ep.execute_transaction(tx, receipt, gas_params);

// Calculate the miner portion of the actual gas fee (if necessary):
std::optional<intx::uint256> gas_fee_miner_portion;
if (miner) {
auto version = _config->get_evm_version();
uint64_t tx_gas_used = receipt.cumulative_gas_used; // Only transaction in the "block" so cumulative_gas_used is the tx gas_used.
if(_config->get_evm_version() >= 1) {
if(version >= 3) {
gas_fee_miner_portion.emplace(res.inclusion_fee);
} else if(version >= 1) {
eosio::check(ep.evm().block().header.base_fee_per_gas.has_value(), "no base fee");
intx::uint512 gas_fee = intx::uint256(tx_gas_used) * tx.priority_fee_per_gas(ep.evm().block().header.base_fee_per_gas.value());
check(gas_fee < std::numeric_limits<intx::uint256>::max(), "too much gas");
Expand Down Expand Up @@ -344,12 +347,18 @@ 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;
auto gas_prices = _config->get_gas_prices();
if (evm_version >= 1) {
base_fee_per_gas = _config->get_gas_price();
if( evm_version >= 3) {
base_fee_per_gas = gas_prices.get_base_price();
} else {
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()), evm_version, base_fee_per_gas);

Expand All @@ -368,15 +377,15 @@ void evm_contract::exec(const exec_input& input, const std::optional<exec_callba
);
}, consensus_param);

EVM evm{block, ibstate, *found_chain_config.value().second, gas_params};
EVM evm{block, ibstate, *found_chain_config.value().second};

Transaction txn;
txn.to = to_address(input.to);
txn.data = Bytes{input.data.begin(), input.data.end()};
txn.from = input.from.has_value() ? to_address(input.from.value()) : evmc::address{};
txn.value = input.value.has_value() ? to_uint256(input.value.value()) : 0;

const CallResult vm_res{evm.execute(txn, 0x7ffffffffff)};
const CallResult vm_res{evm.execute(txn, 0x7ffffffffff, gas_params)};

exec_output output{
.status = int32_t(vm_res.status),
Expand Down Expand Up @@ -475,7 +484,7 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
auto gas_prices = _config->get_gas_prices();
if (current_version >= 1) {
if( current_version >= 3) {
//base_fee_per_gas = f(gas_prices, min_inclusion_price)
base_fee_per_gas = gas_prices.get_base_price();
} else {
base_fee_per_gas = _config->get_gas_price();
}
Expand Down Expand Up @@ -506,7 +515,8 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
check(tx.max_fee_per_gas >= _config->get_gas_price(), "gas price is too low");
}

silkworm::ExecutionProcessor ep{block, engine, state, *found_chain_config->second, gas_params};
auto gp = silkworm::gas_prices_t{gas_prices.overhead_price, gas_prices.storage_price};
silkworm::ExecutionProcessor ep{block, engine, state, *found_chain_config->second, gp};

// Filter EVM messages (with data) that are sent to the reserved address
// corresponding to the EOS account holding the contract (self)
Expand All @@ -515,7 +525,7 @@ void evm_contract::process_tx(const runtime_config& rc, eosio::name miner, const
return message.recipient == me && message.input_size > 0;
});

auto receipt = execute_tx(rc, miner, block, txn, ep);
auto receipt = execute_tx(rc, miner, block, txn, ep, gas_params);

process_filtered_messages(ep.state().filtered_messages());

Expand Down
4 changes: 2 additions & 2 deletions src/config_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ 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*/
(get_evm_version() < 3 ? gas_sset_min : 0) + storage_slot_bytes * gas_per_byte /*gas_sset*/
);

if(get_evm_version() >= 1) {
Expand All @@ -324,7 +324,7 @@ void config_wrapper::update_consensus_parameters2(std::optional<uint64_t> gas_tx
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 >= gas_sset_min, "gas_sset too small");
eosio::check(get_evm_version() >= 3 || *gas_sset >= gas_sset_min, "gas_sset too small");
v.gas_parameter.gas_sset = *gas_sset;
}
}, p);
Expand Down
2 changes: 1 addition & 1 deletion src/test_actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ using namespace silkworm;
.enforce_chain_id = false,
.allow_non_self_miner = true
};
execute_tx(rc, eosio::name{}, block, transaction{std::move(tx)}, ep);
execute_tx(rc, eosio::name{}, block, transaction{std::move(tx)}, ep, {});
}
engine.finalize(ep.state(), ep.evm().block());
ep.state().write_to_db(ep.evm().block().header.number);
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_eosio_test_executable( unit_test
${CMAKE_SOURCE_DIR}/mapping_tests.cpp
${CMAKE_SOURCE_DIR}/gas_fee_tests.cpp
${CMAKE_SOURCE_DIR}/gas_param_tests.cpp
${CMAKE_SOURCE_DIR}/gas_prices_tests.cpp
${CMAKE_SOURCE_DIR}/blockhash_tests.cpp
${CMAKE_SOURCE_DIR}/exec_tests.cpp
${CMAKE_SOURCE_DIR}/call_tests.cpp
Expand Down
18 changes: 9 additions & 9 deletions tests/basic_evm_tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@ class evm_validating_tester : public testing::base_tester {
signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false )override {
auto produce_block_result = _produce_block(skip_time, false, no_throw);
auto sb = produce_block_result.block;
auto [best_head, obh] = validating_node->accept_block( sb->calculate_id(), sb );
EOS_ASSERT(obh, unlinkable_block_exception, "block did not link ${b}", ("b", sb->calculate_id()));
validating_node->apply_blocks( {}, trx_meta_cache_lookup{} );
auto bhf = validating_node->create_block_handle_future( sb->calculate_id(), sb );
struct controller::block_report br;
validating_node->push_block(br, bhf.get(), forked_callback_t{}, trx_meta_cache_lookup{} );

return sb;
}
Expand All @@ -362,17 +362,17 @@ class evm_validating_tester : public testing::base_tester {
}

void validate_push_block(const signed_block_ptr& sb) {
auto [best_head, obh] = validating_node->accept_block( sb->calculate_id(), sb );
EOS_ASSERT(obh, unlinkable_block_exception, "block did not link ${b}", ("b", sb->calculate_id()));
validating_node->apply_blocks( {}, trx_meta_cache_lookup{} );
auto bhf = validating_node->create_block_handle_future( sb->calculate_id(), sb );
struct controller::block_report br;
validating_node->push_block(br, bhf.get(), forked_callback_t{}, trx_meta_cache_lookup{} );
}

signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
unapplied_transactions.add_aborted( control->abort_block() );
auto sb = _produce_block(skip_time, true);
auto [best_head, obh] = validating_node->accept_block( sb->calculate_id(), sb );
EOS_ASSERT(obh, unlinkable_block_exception, "block did not link ${b}", ("b", sb->calculate_id()));
validating_node->apply_blocks( {}, trx_meta_cache_lookup{} );
auto bhf = validating_node->create_block_handle_future( sb->calculate_id(), sb );
struct controller::block_report br;
validating_node->push_block(br, bhf.get(), forked_callback_t{}, trx_meta_cache_lookup{} );

return sb;
}
Expand Down
Loading

0 comments on commit 4558425

Please sign in to comment.