From 1ca6972344f7bb5862a88686e9401b817145c222 Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Tue, 17 Sep 2024 08:54:57 +0200 Subject: [PATCH] rpcdaemon: add catch invalid argument in debug_accountStorageAt, trace_filter, eth_estimateGas (#2357) --- silkworm/rpc/commands/debug_api.cpp | 3 +++ silkworm/rpc/commands/eth_api.cpp | 6 ++++-- silkworm/rpc/core/evm_trace.cpp | 13 +++++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/silkworm/rpc/commands/debug_api.cpp b/silkworm/rpc/commands/debug_api.cpp index a64ab4148d..09a39c5f32 100644 --- a/silkworm/rpc/commands/debug_api.cpp +++ b/silkworm/rpc/commands/debug_api.cpp @@ -259,6 +259,9 @@ Task 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(); diff --git a/silkworm/rpc/commands/eth_api.cpp b/silkworm/rpc/commands/eth_api.cpp index c74b36a0d0..2e0ce2b0c4 100644 --- a/silkworm/rpc/commands/eth_api.cpp +++ b/silkworm/rpc/commands/eth_api.cpp @@ -281,7 +281,7 @@ Task 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()); @@ -318,7 +318,7 @@ Task 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()); @@ -921,6 +921,8 @@ Task 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()) { diff --git a/silkworm/rpc/core/evm_trace.cpp b/silkworm/rpc/core/evm_trace.cpp index 3a48f529f2..6bc5ac2f10 100644 --- a/silkworm/rpc/core/evm_trace.cpp +++ b/silkworm/rpc/core/evm_trace.cpp @@ -1775,7 +1775,12 @@ Task 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 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) { @@ -1798,7 +1803,11 @@ Task 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();