From 2d573364b6b9ebda33838a2ad8ffa1d082c51edf Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Sat, 10 Aug 2024 15:14:26 +0200 Subject: [PATCH] rpcdaemon: fix data storage access in local state (#2221) --- .github/workflows/rpc-integration-tests.yml | 2 +- silkworm/db/state/local_state.cpp | 8 ++++---- silkworm/db/state/local_state.hpp | 3 ++- silkworm/rpc/core/evm_trace.cpp | 4 ++++ silkworm/rpc/core/evm_trace.hpp | 4 +--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/rpc-integration-tests.yml b/.github/workflows/rpc-integration-tests.yml index 89c72805a2..c1344403e2 100644 --- a/.github/workflows/rpc-integration-tests.yml +++ b/.github/workflows/rpc-integration-tests.yml @@ -27,7 +27,7 @@ jobs: - name: Checkout RPC Tests Repository & Install Requirements run: | rm -rf ${{runner.workspace}}/rpc-tests - git -c advice.detachedHead=false clone --depth 1 --branch v0.35.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests + git -c advice.detachedHead=false clone --depth 1 --branch v0.36.0 https://github.com/erigontech/rpc-tests ${{runner.workspace}}/rpc-tests cd ${{runner.workspace}}/rpc-tests pip3 install -r requirements.txt diff --git a/silkworm/db/state/local_state.cpp b/silkworm/db/state/local_state.cpp index eab4dec2e6..ceaf02b194 100644 --- a/silkworm/db/state/local_state.cpp +++ b/silkworm/db/state/local_state.cpp @@ -46,15 +46,15 @@ uint64_t LocalState::previous_incarnation(const evmc::address& /*address*/) cons } std::optional LocalState::read_header(BlockNum block_number, const evmc::bytes32& block_hash) const noexcept { - return db::read_header(txn_, block_number, block_hash); + return data_model_.read_header(block_number, block_hash); } bool LocalState::read_body(BlockNum block_number, const evmc::bytes32& block_hash, BlockBody& out) const noexcept { - return db::read_body(txn_, block_hash, block_number, out); + return data_model_.read_body(block_hash, block_number, out); } std::optional LocalState::total_difficulty(BlockNum block_number, const evmc::bytes32& block_hash) const noexcept { - return db::read_total_difficulty(txn_, block_number, block_hash); + return data_model_.read_total_difficulty(block_number, block_hash); } evmc::bytes32 LocalState::state_root_hash() const { @@ -68,7 +68,7 @@ BlockNum LocalState::current_canonical_block() const { std::optional LocalState::canonical_hash(BlockNum block_number) const { // This method should not be called by EVM::execute - return db::read_canonical_hash(txn_, block_number); + return data_model_.read_canonical_hash(block_number); } } // namespace silkworm::db::state diff --git a/silkworm/db/state/local_state.hpp b/silkworm/db/state/local_state.hpp index 8803fc8af3..8aa07857f1 100644 --- a/silkworm/db/state/local_state.hpp +++ b/silkworm/db/state/local_state.hpp @@ -34,7 +34,7 @@ namespace silkworm::db::state { class LocalState : public State { public: explicit LocalState(BlockNum block_number, mdbx::env chaindata_env) - : block_number_{block_number}, txn_{std::move(chaindata_env)} {} + : block_number_{block_number}, txn_{std::move(chaindata_env)}, data_model_{txn_} {} std::optional read_account(const evmc::address& address) const noexcept override; @@ -91,6 +91,7 @@ class LocalState : public State { private: BlockNum block_number_; mutable db::ROTxnManaged txn_; + db::DataModel data_model_; }; } // namespace silkworm::db::state diff --git a/silkworm/rpc/core/evm_trace.cpp b/silkworm/rpc/core/evm_trace.cpp index 0cf3c10369..7dc3f191ee 100644 --- a/silkworm/rpc/core/evm_trace.cpp +++ b/silkworm/rpc/core/evm_trace.cpp @@ -1561,6 +1561,10 @@ Task TraceCallExecutor::trace_deploy_transaction(const silkwo co_return deploy_result; } +Task TraceCallExecutor::trace_transaction(const silkworm::Block& block, const rpc::Transaction& transaction, const TraceConfig& config) { + return execute(block.header.number - 1, block, transaction, gsl::narrow(transaction.transaction_index), config); +} + Task> TraceCallExecutor::trace_transaction(const BlockWithHash& block_with_hash, const rpc::Transaction& transaction) { std::vector traces; diff --git a/silkworm/rpc/core/evm_trace.hpp b/silkworm/rpc/core/evm_trace.hpp index 87f638bda9..f4cb68a5d6 100644 --- a/silkworm/rpc/core/evm_trace.hpp +++ b/silkworm/rpc/core/evm_trace.hpp @@ -498,10 +498,8 @@ class TraceCallExecutor { Task> trace_block_transactions(const silkworm::Block& block, const TraceConfig& config); Task trace_call(const silkworm::Block& block, const Call& call, const TraceConfig& config); Task trace_calls(const silkworm::Block& block, const std::vector& calls); - Task trace_transaction(const silkworm::Block& block, const rpc::Transaction& transaction, const TraceConfig& config) { - return execute(block.header.number - 1, block, transaction, gsl::narrow(transaction.transaction_index), config); - } Task trace_deploy_transaction(const silkworm::Block& block, const evmc::address& contract_address); + Task trace_transaction(const silkworm::Block& block, const rpc::Transaction& transaction, const TraceConfig& config); Task> trace_transaction(const silkworm::BlockWithHash& block, const rpc::Transaction& transaction); Task trace_transaction_entries(const TransactionWithBlock& transaction_with_block); Task trace_transaction_error(const TransactionWithBlock& transaction_with_block);