Skip to content

Commit

Permalink
rpcdaemon: add catch invalid argument in debug_accountStorageAt, trac…
Browse files Browse the repository at this point in the history
…e_filter, eth_estimateGas (#2357)
  • Loading branch information
lupin012 committed Sep 17, 2024
1 parent 2cb9ed8 commit 1ca6972
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions silkworm/rpc/commands/debug_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ Task<void> DebugRpcApi::handle_debug_storage_range_at(const nlohmann::json& requ
result["nextKey"] = "0x" + silkworm::to_hex(next_key);
}

reply = make_json_content(request, result);
} catch (const std::invalid_argument& e) {
nlohmann::json result = {{"storage", nullptr}, {"nextKey", nullptr}};
reply = make_json_content(request, result);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
Expand Down
6 changes: 4 additions & 2 deletions silkworm/rpc/commands/eth_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ Task<void> EthereumRpcApi::handle_eth_get_block_transaction_count_by_hash(const
reply = make_json_content(request, nullptr);
}
} catch (const std::invalid_argument& iv) {
reply = make_json_content(request, 0x0);
reply = make_json_content(request, nullptr);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, kInternalError, e.what());
Expand Down Expand Up @@ -318,7 +318,7 @@ Task<void> EthereumRpcApi::handle_eth_get_block_transaction_count_by_number(cons
reply = make_json_content(request, nullptr);
}
} catch (const std::invalid_argument& iv) {
reply = make_json_content(request, 0x0);
reply = make_json_content(request, nullptr);
} catch (const std::exception& e) {
SILK_ERROR << "exception: " << e.what() << " processing request: " << request.dump();
reply = make_json_error(request, kInternalError, e.what());
Expand Down Expand Up @@ -921,6 +921,8 @@ Task<void> EthereumRpcApi::handle_eth_estimate_gas(const nlohmann::json& request
const auto estimated_gas = co_await estimate_gas_oracle.estimate_gas(call, latest_block, block_number_for_gas_limit);

reply = make_json_content(request, to_quantity(estimated_gas));
} catch (const std::invalid_argument& iv) {
reply = make_json_content(request, to_quantity(0));
} catch (const rpc::EstimateGasException& e) {
SILK_ERROR << "EstimateGasException: code: " << e.error_code() << " message: " << e.message() << " processing request: " << request.dump();
if (e.data().empty()) {
Expand Down
13 changes: 11 additions & 2 deletions silkworm/rpc/core/evm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,12 @@ Task<void> TraceCallExecutor::trace_filter(const TraceFilter& trace_filter, cons
filter.count = trace_filter.count;

auto block_number = trace_filter.from_block.number();
auto block_with_hash = co_await core::read_block_by_number_or_hash(block_cache_, storage, tx_, trace_filter.from_block);
std::shared_ptr<BlockWithHash> block_with_hash;
try {
block_with_hash = co_await core::read_block_by_number_or_hash(block_cache_, storage, tx_, trace_filter.from_block);
} catch (const std::invalid_argument& iv) {
block_with_hash = nullptr;
}

while (block_number <= trace_filter.to_block.number()) {
if (!block_with_hash) {
Expand All @@ -1798,7 +1803,11 @@ Task<void> TraceCallExecutor::trace_filter(const TraceFilter& trace_filter, cons
}

block_number++;
block_with_hash = co_await core::read_block_by_number(block_cache_, storage, block_number);
try {
block_with_hash = co_await core::read_block_by_number(block_cache_, storage, block_number);
} catch (const std::invalid_argument& iv) {
block_with_hash = nullptr;
}
}

stream.close_array();
Expand Down

0 comments on commit 1ca6972

Please sign in to comment.