Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process configchange event and save the parameters in some data structure. #190

Merged
merged 14 commits into from
Mar 20, 2024
Merged
2 changes: 1 addition & 1 deletion external/silkworm
Submodule silkworm updated 38 files
+1 −0 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
+38 −0 eosevm/CMakeLists.txt
+85 −0 eosevm/consensus_parameters.cpp
+58 −0 eosevm/consensus_parameters.hpp
+12 −5 silkworm/core/chain/config.cpp
+1 −0 silkworm/core/chain/config.hpp
+6 −0 silkworm/core/common/test_util.hpp
+35 −9 silkworm/core/execution/evm.cpp
+8 −1 silkworm/core/execution/evm.hpp
+77 −12 silkworm/core/execution/evm_test.cpp
+2 −2 silkworm/core/execution/execution.hpp
+2 −2 silkworm/core/execution/execution_test.cpp
+2 −2 silkworm/core/execution/processor.cpp
+1 −1 silkworm/core/execution/processor.hpp
+7 −7 silkworm/core/execution/processor_test.cpp
+3 −3 silkworm/core/protocol/blockchain.cpp
+2 −1 silkworm/core/protocol/blockchain.hpp
+28 −1 silkworm/core/types/block.cpp
+6 −0 silkworm/core/types/block.hpp
+2 −0 silkworm/core/types/block_test.cpp
+1 −0 silkworm/node/CMakeLists.txt
+20 −0 silkworm/node/db/access_layer.cpp
+8 −0 silkworm/node/db/access_layer.hpp
+56 −3 silkworm/node/db/access_layer_test.cpp
+4 −0 silkworm/node/db/tables.hpp
+21 −0 silkworm/node/db/util.cpp
+4 −0 silkworm/node/db/util.hpp
+8 −1 silkworm/node/db/util_test.cpp
+3 −3 silkworm/node/stagedsync/stages/_test.cpp
+9 −1 silkworm/node/stagedsync/stages/stage_execution.cpp
+2 −0 silkworm/node/stagedsync/stages/stage_execution.hpp
+3 −3 silkworm/node/stagedsync/stages/stage_history_index_test.cpp
+2 −1 silkworm/silkrpc/core/evm_executor.cpp
+1 −1 third_party/evmone
32 changes: 32 additions & 0 deletions src/block_conversion_plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include "block_conversion_plugin.hpp"
#include "blockchain_plugin.hpp"
#include "channels.hpp"
#include "abi_utils.hpp"
#include "utils.hpp"
#include <eosevm/block_mapping.hpp>
#include <eosevm/consensus_parameters.hpp>
#include <eosevm/version.hpp>

#include <fstream>

#include <silkworm/core/types/transaction.hpp>
#include <silkworm/core/trie/vector_root.hpp>
#include <silkworm/core/common/endian.hpp>
#include <silkworm/node/db/access_layer.hpp>

using sys = sys_plugin;

Expand Down Expand Up @@ -119,6 +122,8 @@ class block_conversion_plugin_impl : std::enable_shared_from_this<block_conversi

new_block.header.parent_hash = last_evm_block.header.hash();
new_block.header.transactions_root = silkworm::kEmptyRoot;
// Note: can be null
new_block.consensus_parameter_index = last_evm_block.consensus_parameter_index;
return new_block;
}

Expand Down Expand Up @@ -267,6 +272,27 @@ class block_conversion_plugin_impl : std::enable_shared_from_this<block_conversi
// Add transactions to the evm block
auto& curr = evm_blocks.back();
auto block_version = eosevm::nonce_to_version(curr.header.nonce);
if (new_block->new_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<blockchain_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);
Expand Down Expand Up @@ -339,6 +365,12 @@ class block_conversion_plugin_impl : std::enable_shared_from_this<block_conversi
return evmtx;
}

inline consensus_parameter_data_type deserialize_config(const channels::native_action& na) const {
consensus_parameter_data_type new_configs;
eosio::convert_from_bin(new_configs, na.data);
return new_configs;
}

uint64_t get_evm_lib() {
return evm_lib_;
}
Expand Down
16 changes: 16 additions & 0 deletions src/block_conversion_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,22 @@ struct evmtx_v0 {
using evmtx_type = std::variant<evmtx_v0>;
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<consensus_parameter_data_v0>;
EOSIO_REFLECT(consensus_parameter_data_v0, minimum_gas_price, gas_parameter)

class block_conversion_plugin : public appbase::plugin<block_conversion_plugin> {
public:
APPBASE_PLUGIN_REQUIRES((sys_plugin)(ship_receiver_plugin)(engine_plugin));
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class blockchain_plugin_impl : std::enable_shared_from_this<blockchain_plugin_im
exec_engine = std::make_unique<ExecutionEngineEx>(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.
Expand Down
1 change: 1 addition & 0 deletions src/channels.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace channels {
uint32_t block_num = 0;
int64_t timestamp = 0;
uint32_t lib = 0;
std::optional<native_action> new_config = std::nullopt;
std::vector<native_trx> transactions;
};

Expand Down
30 changes: 24 additions & 6 deletions src/ship_receiver_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class ship_receiver_plugin_impl : std::enable_shared_from_this<ship_receiver_plu
std::map<uint64_t, eosio::ship_protocol::action_trace> 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");
Expand All @@ -215,7 +215,7 @@ class ship_receiver_plugin_impl : std::enable_shared_from_this<ship_receiver_plu
}
}, actions[j]);
}
if (ordered_action_traces.size()) {
if (ordered_action_traces.size()) {
for (const auto &pair: ordered_action_traces) {
std::visit([&](const auto& act) {
channels::native_action action = {
Expand All @@ -225,11 +225,29 @@ class ship_receiver_plugin_impl : std::enable_shared_from_this<ship_receiver_plu
act.act.name,
std::vector<char>(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) {
Expand Down
1 change: 1 addition & 0 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <silkworm/core/common/util.hpp>
#include <silkworm/infra/common/log.hpp>

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");

Expand Down
Loading