Skip to content

Commit

Permalink
rpcdaemon: trace_call trace_block trace_callMany traceRawTransaction …
Browse files Browse the repository at this point in the history
…trace_replayBlockTransaction w/ snapshots (#1362)
  • Loading branch information
lupin012 authored Jul 23, 2023
1 parent 38ea478 commit 97fa1f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
19 changes: 11 additions & 8 deletions silkworm/silkrpc/commands/trace_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ boost::asio::awaitable<void> TraceRpcApi::handle_trace_call(const nlohmann::json
try {
ethdb::TransactionDatabase tx_database{*tx};
ethdb::kv::CachedDatabase cached_database{block_number_or_hash, *tx, *state_cache_};
const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, tx_database, block_number_or_hash);
const auto chain_storage = tx->create_storage(tx_database, backend_);

const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, *chain_storage, tx_database, block_number_or_hash);
const bool is_latest_block = co_await core::is_latest_block_number(block_with_hash->block.header.number, tx_database);
const core::rawdb::DatabaseReader& db_reader =
is_latest_block ? static_cast<core::rawdb::DatabaseReader&>(cached_database) : static_cast<core::rawdb::DatabaseReader&>(tx_database);
Expand Down Expand Up @@ -98,7 +100,8 @@ boost::asio::awaitable<void> TraceRpcApi::handle_trace_call_many(const nlohmann:
try {
ethdb::TransactionDatabase tx_database{*tx};
ethdb::kv::CachedDatabase cached_database{block_number_or_hash, *tx, *state_cache_};
const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, tx_database, block_number_or_hash);
const auto chain_storage = tx->create_storage(tx_database, backend_);
const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, *chain_storage, tx_database, block_number_or_hash);
const bool is_latest_block = co_await core::is_latest_block_number(block_with_hash->block.header.number, tx_database);

const core::rawdb::DatabaseReader& db_reader =
Expand Down Expand Up @@ -185,7 +188,8 @@ boost::asio::awaitable<void> TraceRpcApi::handle_trace_raw_transaction(const nlo
ethdb::TransactionDatabase tx_database{*tx};

const auto block_number = co_await core::get_latest_block_number(tx_database);
const auto block_with_hash = co_await core::read_block_by_number(*block_cache_, tx_database, block_number);
const auto chain_storage = tx->create_storage(tx_database, backend_);
const auto block_with_hash = co_await core::read_block_by_number(*block_cache_, *chain_storage, tx_database, block_number);

trace::TraceCallExecutor executor{*block_cache_, tx_database, workers_, *tx};
const auto result = co_await executor.trace_transaction(block_with_hash->block, transaction, config);
Expand Down Expand Up @@ -225,8 +229,8 @@ boost::asio::awaitable<void> TraceRpcApi::handle_trace_replay_block_transactions

try {
ethdb::TransactionDatabase tx_database{*tx};

const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, tx_database, block_number_or_hash);
const auto chain_storage = tx->create_storage(tx_database, backend_);
const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, *chain_storage, tx_database, block_number_or_hash);

trace::TraceCallExecutor executor{*block_cache_, tx_database, workers_, *tx};
const auto result = co_await executor.trace_block_transactions(block_with_hash->block, config);
Expand Down Expand Up @@ -305,8 +309,8 @@ boost::asio::awaitable<void> TraceRpcApi::handle_trace_block(const nlohmann::jso

try {
ethdb::TransactionDatabase tx_database{*tx};

const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, tx_database, block_number_or_hash);
const auto chain_storage = tx->create_storage(tx_database, backend_);
const auto block_with_hash = co_await core::read_block_by_number_or_hash(*block_cache_, *chain_storage, tx_database, block_number_or_hash);

trace::TraceCallExecutor executor{*block_cache_, tx_database, workers_, *tx};
trace::Filter filter;
Expand Down Expand Up @@ -347,7 +351,6 @@ boost::asio::awaitable<void> TraceRpcApi::handle_trace_filter(const nlohmann::js

try {
ethdb::TransactionDatabase tx_database{*tx};

trace::TraceCallExecutor executor{*block_cache_, tx_database, workers_, *tx};

co_await executor.trace_filter(trace_filter, &stream);
Expand Down
5 changes: 4 additions & 1 deletion silkworm/silkrpc/commands/trace_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class TraceRpcApi {
block_cache_{must_use_shared_service<BlockCache>(io_context_)},
state_cache_{must_use_shared_service<ethdb::kv::StateCache>(io_context_)},
database_{must_use_private_service<ethdb::Database>(io_context_)},
workers_{workers} {}
workers_{workers},
backend_{must_use_private_service<ethbackend::BackEnd>(io_context_)} {}

virtual ~TraceRpcApi() = default;

TraceRpcApi(const TraceRpcApi&) = delete;
Expand All @@ -70,6 +72,7 @@ class TraceRpcApi {
ethdb::kv::StateCache* state_cache_;
ethdb::Database* database_;
boost::asio::thread_pool& workers_;
ethbackend::BackEnd* backend_;

friend class silkworm::http::RequestHandler;
};
Expand Down
7 changes: 1 addition & 6 deletions silkworm/silkrpc/storage/remote_chain_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ Task<bool> RemoteChainStorage::read_block(const Hash& hash, BlockNum number, sil
}

Task<bool> RemoteChainStorage::read_block(const Hash& hash, silkworm::Block& block) const {
uint64_t block_number{0};
try {
block_number = co_await core::rawdb::read_header_number(reader_, hash);
} catch (const std::invalid_argument& iv) {
co_return false;
}
uint64_t block_number = co_await core::rawdb::read_header_number(reader_, hash);
co_return co_await backend_->get_block(block_number, hash.bytes, /*.read_senders=*/false, block);
}

Expand Down

0 comments on commit 97fa1f8

Please sign in to comment.