From d183a607af243609add4e25d6c200cff8a9a7a00 Mon Sep 17 00:00:00 2001 From: Victor Baranov Date: Wed, 26 Feb 2020 16:12:57 +0300 Subject: [PATCH] Handle error at first trace request --- CHANGELOG.md | 2 +- .../transaction_raw_trace_controller.ex | 20 ++++++---- .../lib/ethereum_jsonrpc/parity.ex | 40 +++++++++++++------ apps/explorer/lib/explorer/chain.ex | 9 +++-- 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f6291c3310..f68b2a5ffd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ ## Current ### Features -- [#3013](https://github.com/poanetwork/blockscout/pull/3013) - Raw trace of transaction on-demand +- [#3013](https://github.com/poanetwork/blockscout/pull/3013), [#3026](https://github.com/poanetwork/blockscout/pull/3026) - Raw trace of transaction on-demand - [#3000](https://github.com/poanetwork/blockscout/pull/3000) - Get rid of storing of internal transactions for simple coin transfers - [#2875](https://github.com/poanetwork/blockscout/pull/2875) - Save contract code from Parity genesis file - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash diff --git a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex index 0f0e4114e1..5aeca2184e 100644 --- a/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex +++ b/apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex @@ -35,7 +35,7 @@ defmodule BlockScoutWeb.TransactionRawTraceController do if first_trace_exists do internal_transactions else - {:ok, first_trace_params} = + response = Chain.fetch_first_trace( [ %{ @@ -48,13 +48,19 @@ defmodule BlockScoutWeb.TransactionRawTraceController do json_rpc_named_arguments ) - InternalTransactions.run_insert_only(first_trace_params, %{ - timeout: :infinity, - timestamps: Import.timestamps(), - internal_transactions: %{params: first_trace_params} - }) + case response do + {:ok, first_trace_params} -> + InternalTransactions.run_insert_only(first_trace_params, %{ + timeout: :infinity, + timestamps: Import.timestamps(), + internal_transactions: %{params: first_trace_params} + }) - Chain.all_transaction_to_internal_transactions(hash) + Chain.all_transaction_to_internal_transactions(hash) + + {:error, _} -> + internal_transactions + end end render( diff --git a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex index 5c399887dd..84a1b94702 100644 --- a/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex +++ b/apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex @@ -2,7 +2,7 @@ defmodule EthereumJSONRPC.Parity do @moduledoc """ Ethereum JSONRPC methods that are only supported by [Parity](https://wiki.parity.io/). """ - + require Logger import EthereumJSONRPC, only: [id_to_params: 1, integer_to_quantity: 1, json_rpc: 2, request: 1] alias EthereumJSONRPC.Parity.{FetchedBeneficiaries, Traces} @@ -53,17 +53,33 @@ defmodule EthereumJSONRPC.Parity do def fetch_first_trace(transactions_params, json_rpc_named_arguments) when is_list(transactions_params) do id_to_params = id_to_params(transactions_params) - with {:ok, responses} <- - id_to_params - |> trace_replay_transaction_requests() - |> json_rpc(json_rpc_named_arguments) do - {:ok, [first_trace]} = trace_replay_transaction_responses_to_first_trace_params(responses, id_to_params) - - %{block_hash: block_hash} = - transactions_params - |> Enum.at(0) - - {:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} + trace_replay_transaction_response = + id_to_params + |> trace_replay_transaction_requests() + |> json_rpc(json_rpc_named_arguments) + + case trace_replay_transaction_response do + {:ok, responses} -> + case trace_replay_transaction_responses_to_first_trace_params(responses, id_to_params) do + {:ok, [first_trace]} -> + %{block_hash: block_hash} = + transactions_params + |> Enum.at(0) + + {:ok, + [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} + + {:error, error} -> + Logger.error(inspect(error)) + {:error, error} + end + + {:error, :econnrefused} -> + {:error, :econnrefused} + + {:error, [error]} -> + Logger.error(inspect(error)) + {:error, error} end end diff --git a/apps/explorer/lib/explorer/chain.ex b/apps/explorer/lib/explorer/chain.ex index f0992436d5..727b50aba6 100644 --- a/apps/explorer/lib/explorer/chain.ex +++ b/apps/explorer/lib/explorer/chain.ex @@ -4070,10 +4070,13 @@ defmodule Explorer.Chain do Fetches the first trace from the Parity trace URL. """ def fetch_first_trace(transactions_params, json_rpc_named_arguments) do - {:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} = - EthereumJSONRPC.fetch_first_trace(transactions_params, json_rpc_named_arguments) + case EthereumJSONRPC.fetch_first_trace(transactions_params, json_rpc_named_arguments) do + {:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} -> + format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) - format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) + {:error, error} -> + {:error, error} + end end defp format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) do