From 367792948bcc9e5e070271b92b2122b4cb20494c Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Wed, 14 Aug 2024 02:38:36 -0300 Subject: [PATCH 1/2] Process evmtx_v3 to save overhead/storage price in the block extra data --- external/silkworm | 2 +- src/block_conversion_plugin.cpp | 44 ++++++++++++++++++++++++++++++--- src/block_conversion_plugin.hpp | 18 +++++++++++--- 3 files changed, 57 insertions(+), 7 deletions(-) diff --git a/external/silkworm b/external/silkworm index 76163e9..99b2ab4 160000 --- a/external/silkworm +++ b/external/silkworm @@ -1 +1 @@ -Subproject commit 76163e9c9aedc7991307f21eaa14a861964446b4 +Subproject commit 99b2ab4acd6d9282b846b502cab6ffcfaf42f7e3 diff --git a/src/block_conversion_plugin.cpp b/src/block_conversion_plugin.cpp index e7dd014..75dc78a 100644 --- a/src/block_conversion_plugin.cpp +++ b/src/block_conversion_plugin.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include @@ -128,11 +129,19 @@ class block_conversion_plugin_impl : std::enable_shared_from_this auto& { return arg.rlpx; }, dtx); + if(block_version >= 3) { + SILKWORM_ASSERT(std::holds_alternative(dtx)); + const auto& dtx_v3 = std::get(dtx); + auto tx_gas_prices = eosevm::gas_prices{ + .overhead_price = dtx_v3.overhead_price, + .storage_price = dtx_v3.storage_price + }; + auto tx_gas_prices_index = tx_gas_prices.hash(); + auto curr_block_prices_index = curr.get_gas_prices_index(); + + auto set_new_gas_prices = [&](){ + curr.set_gas_prices_index(tx_gas_prices_index); + silkworm::db::update_gas_prices(appbase::app().get_plugin().get_tx(), tx_gas_prices_index, tx_gas_prices); + }; + + if(!curr_block_prices_index) { + set_new_gas_prices(); + } else if(*curr_block_prices_index != tx_gas_prices_index) { + if(curr.transactions.empty()) { + set_new_gas_prices(); + } else { + SILK_CRIT << "curr_block_prices_index != tx_gas_prices_index"; + throw std::runtime_error("curr_block_prices_index != tx_gas_prices_index"); + } + } + + curr.header.base_fee_per_gas = eosevm::calculate_base_fee_per_gas(tx_gas_prices.overhead_price, tx_gas_prices.storage_price); + } + silkworm::ByteView bv = {(const uint8_t*)rlpx_ref.data(), rlpx_ref.size()}; silkworm::Transaction evm_tx; if (!silkworm::rlp::decode_transaction(bv, evm_tx, silkworm::rlp::Eip2718Wrapping::kBoth, silkworm::rlp::Leftover::kProhibit)) { @@ -326,8 +364,8 @@ class block_conversion_plugin_impl : std::enable_shared_from_this= 1) { - auto tx_base_fee = std::visit([](auto&& arg) -> auto { return arg.base_fee_per_gas; }, dtx); + if(block_version >= 1 && block_version < 3) { + auto tx_base_fee = std::get(dtx).base_fee_per_gas; if(!curr.header.base_fee_per_gas.has_value()) { curr.header.base_fee_per_gas = tx_base_fee; } else if (curr.header.base_fee_per_gas.value() != tx_base_fee) { @@ -380,7 +418,7 @@ class block_conversion_plugin_impl : std::enable_shared_from_this rlpx; +}; + +struct evmtx_v1 : evmtx_base { uint64_t base_fee_per_gas; }; -using evmtx_type = std::variant; -EOSIO_REFLECT(evmtx_v0, eos_evm_version, rlpx, base_fee_per_gas) + +struct evmtx_v3 : evmtx_base { + uint64_t overhead_price; + uint64_t storage_price; +}; + +using evmtx_type = std::variant; + +EOSIO_REFLECT(evmtx_base, eos_evm_version, rlpx); +EOSIO_REFLECT(evmtx_v1, base evmtx_base, base_fee_per_gas); +EOSIO_REFLECT(evmtx_v3, base evmtx_base, overhead_price, storage_price); struct gas_parameter_type { uint64_t gas_txnewaccount = 0; From 6ed4c13d286d614483a5568c41a4483ecb773255 Mon Sep 17 00:00:00 2001 From: Matias Romeo Date: Thu, 15 Aug 2024 21:23:09 -0300 Subject: [PATCH 2/2] Update silkworm --- external/silkworm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/silkworm b/external/silkworm index 99b2ab4..99edb9b 160000 --- a/external/silkworm +++ b/external/silkworm @@ -1 +1 @@ -Subproject commit 99b2ab4acd6d9282b846b502cab6ffcfaf42f7e3 +Subproject commit 99edb9ba5d5fb85a5532135e8c06e42ceee518e4