Skip to content

Commit

Permalink
rpcdaemon: trace_filter use stream reference (#1785)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sixtysixter authored Jan 30, 2024
1 parent a29b464 commit 8f26ea5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion silkworm/rpc/commands/trace_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ Task<void> TraceRpcApi::handle_trace_filter(const nlohmann::json& request, json:

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

co_await executor.trace_filter(trace_filter, *chain_storage, &stream);
co_await executor.trace_filter(trace_filter, *chain_storage, stream);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();

Expand Down
16 changes: 8 additions & 8 deletions silkworm/rpc/core/evm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1610,30 +1610,30 @@ Task<bool> TraceCallExecutor::trace_touch_transaction(const silkworm::Block& blo
co_return ret_entry_tracer->found();
}

Task<void> TraceCallExecutor::trace_filter(const TraceFilter& trace_filter, const ChainStorage& storage, json::Stream* stream) {
Task<void> TraceCallExecutor::trace_filter(const TraceFilter& trace_filter, const ChainStorage& storage, json::Stream& stream) {
SILK_TRACE << "TraceCallExecutor::trace_filter: filter " << trace_filter;

const auto from_block_with_hash = co_await core::read_block_by_number_or_hash(block_cache_, storage, database_reader_, trace_filter.from_block);
if (!from_block_with_hash) {
const Error error{-32000, "invalid parameters: fromBlock not found"};
stream->write_json_field("error", error);
stream.write_json_field("error", error);
co_return;
}
const auto to_block_with_hash = co_await core::read_block_by_number_or_hash(block_cache_, storage, database_reader_, trace_filter.to_block);
if (!to_block_with_hash) {
const Error error{-32000, "invalid parameters: toBlock not found"};
stream->write_json_field("error", error);
stream.write_json_field("error", error);
co_return;
}

if (from_block_with_hash->block.header.number > to_block_with_hash->block.header.number) {
const Error error{-32000, "invalid parameters: fromBlock cannot be greater than toBlock"};
stream->write_json_field("error", error);
stream.write_json_field("error", error);
co_return;
}

stream->write_field("result");
stream->open_array();
stream.write_field("result");
stream.open_array();

Filter filter;
filter.from_addresses.insert(trace_filter.from_addresses.begin(), trace_filter.from_addresses.end());
Expand All @@ -1649,7 +1649,7 @@ Task<void> TraceCallExecutor::trace_filter(const TraceFilter& trace_filter, cons
<< " block_number: " << block_number - 1
<< " block: " << block;

co_await trace_block(*block_with_hash, filter, stream);
co_await trace_block(*block_with_hash, filter, &stream);

if (filter.count == 0) {
break;
Expand All @@ -1662,7 +1662,7 @@ Task<void> TraceCallExecutor::trace_filter(const TraceFilter& trace_filter, cons
}
}

stream->close_array();
stream.close_array();

SILK_TRACE << "TraceCallExecutor::trace_filter: end";

Expand Down
2 changes: 1 addition & 1 deletion silkworm/rpc/core/evm_trace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ class TraceCallExecutor {
Task<std::string> trace_transaction_error(const TransactionWithBlock& transaction_with_block);
Task<TraceOperationsResult> trace_operations(const TransactionWithBlock& transaction_with_block);
Task<bool> trace_touch_transaction(const silkworm::Block& block, const silkworm::Transaction& txn, const evmc::address& address);
Task<void> trace_filter(const TraceFilter& trace_filter, const ChainStorage& storage, json::Stream* stream);
Task<void> trace_filter(const TraceFilter& trace_filter, const ChainStorage& storage, json::Stream& stream);

private:
Task<TraceCallResult> execute(
Expand Down

0 comments on commit 8f26ea5

Please sign in to comment.