diff --git a/external/silkworm b/external/silkworm index 8a2b691..6367598 160000 --- a/external/silkworm +++ b/external/silkworm @@ -1 +1 @@ -Subproject commit 8a2b691f683f1a392f148c67412aab39b21d31f7 +Subproject commit 636759886f40e4dddf07ea603f94c1fefda30447 diff --git a/src/block_conversion_plugin.cpp b/src/block_conversion_plugin.cpp index 7ad7aba..b5bca1a 100644 --- a/src/block_conversion_plugin.cpp +++ b/src/block_conversion_plugin.cpp @@ -1,8 +1,10 @@ #include "block_conversion_plugin.hpp" +#include "blockchain_plugin.hpp" #include "channels.hpp" #include "abi_utils.hpp" #include "utils.hpp" #include +#include #include #include @@ -10,6 +12,7 @@ #include #include #include +#include using sys = sys_plugin; @@ -119,6 +122,8 @@ class block_conversion_plugin_impl : std::enable_shared_from_thisnew_config.has_value()){ + if (!curr.transactions.empty()) { + SILK_CRIT << "new config comes in the middle of an evm block"; + throw std::runtime_error("new config comes in the middle of an evm block"); + } + auto new_config = deserialize_config(new_block->new_config.value()); + auto consensus_param = eosevm::ConsensusParameters { + .min_gas_price = std::visit([](auto&& arg) -> auto& { return arg.minimum_gas_price; }, new_config), + .gas_fee_parameters = eosevm::GasFeeParameters { + .gas_txnewaccount = std::visit([](auto&& arg) -> auto& { return arg.gas_parameter.gas_txnewaccount; }, new_config), + .gas_newaccount = std::visit([](auto&& arg) -> auto& { return arg.gas_parameter.gas_newaccount; }, new_config), + .gas_txcreate = std::visit([](auto&& arg) -> auto& { return arg.gas_parameter.gas_txcreate; }, new_config), + .gas_codedeposit = std::visit([](auto&& arg) -> auto& { return arg.gas_parameter.gas_codedeposit; }, new_config), + .gas_sset = std::visit([](auto&& arg) -> auto& { return arg.gas_parameter.gas_sset; }, new_config), + } + }; + curr.consensus_parameter_index = consensus_param.hash(); + + silkworm::db::update_consensus_parameters(appbase::app().get_plugin().get_tx(), *curr.consensus_parameter_index, consensus_param); + } + for_each_action(*new_block, [this, &curr, &block_version](const auto& act){ auto dtx = deserialize_tx(act); auto& rlpx_ref = std::visit([](auto&& arg) -> auto& { return arg.rlpx; }, dtx); @@ -339,6 +365,12 @@ class block_conversion_plugin_impl : std::enable_shared_from_this; EOSIO_REFLECT(evmtx_v0, eos_evm_version, rlpx) +struct gas_parameter_type { + uint64_t gas_txnewaccount = 0; + uint64_t gas_newaccount = 25000; + uint64_t gas_txcreate = 32000; + uint64_t gas_codedeposit = 200; + uint64_t gas_sset = 20000; +}; +EOSIO_REFLECT(gas_parameter_type, gas_txnewaccount, gas_newaccount, gas_txcreate, gas_codedeposit, gas_sset) + +struct consensus_parameter_data_v0 { + uint64_t minimum_gas_price = 0; + gas_parameter_type gas_parameter; +}; +using consensus_parameter_data_type = std::variant; +EOSIO_REFLECT(consensus_parameter_data_v0, minimum_gas_price, gas_parameter) + class block_conversion_plugin : public appbase::plugin { public: APPBASE_PLUGIN_REQUIRES((sys_plugin)(ship_receiver_plugin)(engine_plugin)); diff --git a/src/blockchain_plugin.cpp b/src/blockchain_plugin.cpp index 68f6a6e..6531388 100644 --- a/src/blockchain_plugin.cpp +++ b/src/blockchain_plugin.cpp @@ -46,7 +46,7 @@ class blockchain_plugin_impl : std::enable_shared_from_this(appbase::app().get_io_context(), *node_settings, silkworm::db::RWAccess{*db_env}); exec_engine->open(); } - + exec_engine->insert_block(new_block); if(!(++block_count % 5000) || !new_block->irreversible) { // Get the last complete EVM block from irreversible EOS blocks. diff --git a/src/channels.hpp b/src/channels.hpp index e96e749..e9585c4 100644 --- a/src/channels.hpp +++ b/src/channels.hpp @@ -38,6 +38,7 @@ namespace channels { uint32_t block_num = 0; int64_t timestamp = 0; uint32_t lib = 0; + std::optional new_config = std::nullopt; std::vector transactions; }; diff --git a/src/ship_receiver_plugin.cpp b/src/ship_receiver_plugin.cpp index d8c8a0e..fa56c84 100644 --- a/src/ship_receiver_plugin.cpp +++ b/src/ship_receiver_plugin.cpp @@ -201,7 +201,7 @@ class ship_receiver_plugin_impl : std::enable_shared_from_this ordered_action_traces; for (std::size_t j = 0; j < actions.size(); ++j) { std::visit([&](auto& act) { - if (act.act.name == action_to_search && core_account == act.receiver) { + if ((act.act.name == action_to_search || act.act.name == configchange_n) && core_account == act.receiver) { if (!act.receipt.has_value()) { SILK_ERROR << "action_trace does not have receipt"; throw std::runtime_error("action_trace does not have receipt"); @@ -215,7 +215,7 @@ class ship_receiver_plugin_impl : std::enable_shared_from_this(act.act.data.pos, act.act.data.end) }; - if(native_trx.actions.size() && native_trx.actions.back().name != action.name) { - SILK_ERROR << "pushtx and evmtx found on the same transaction"; - throw std::runtime_error("pushtx and evmtx found on the same transaction"); + + if (action.name == configchange_n) { + if (block.new_config.has_value()) { + SILK_ERROR << "multiple configchange in one block"; + throw std::runtime_error("multiple configchange in one block"); + } + if (native_trx.actions.size() || block.transactions.size()) { + SILK_ERROR << "configchange can only be the first action"; + throw std::runtime_error("configchange can only be the first action"); + } + block.new_config = action; + } + else { + if (block.new_config.has_value() && action.name == pushtx_n) { + SILK_ERROR << "pushtx and configchange found on the same transaction"; + throw std::runtime_error("pushtx and configchange found on the same transaction"); + } + if (native_trx.actions.size() && native_trx.actions.back().name != action.name) { + SILK_ERROR << "pushtx and evmtx found on the same transaction"; + throw std::runtime_error("pushtx and evmtx found on the same transaction"); + } + native_trx.actions.emplace_back(std::move(action)); } - native_trx.actions.emplace_back(std::move(action)); }, pair.second); } if(block.transactions.size() && block.transactions.back().actions.back().name != native_trx.actions.back().name) { diff --git a/src/utils.hpp b/src/utils.hpp index 56081a5..00de07e 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -5,6 +5,7 @@ #include #include +static constexpr eosio::name configchange_n = eosio::name("configchange"); static constexpr eosio::name pushtx_n = eosio::name("pushtx"); static constexpr eosio::name evmtx_n = eosio::name("evmtx");