diff --git a/external/silkworm b/external/silkworm index 32a86f2..99edb9b 160000 --- a/external/silkworm +++ b/external/silkworm @@ -1 +1 @@ -Subproject commit 32a86f24cc0aac708f6553268f7e1cd6ce7c01bc +Subproject commit 99edb9ba5d5fb85a5532135e8c06e42ceee518e4 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;