Handle error at first trace request

pull/3026/head
Victor Baranov 5 years ago
parent 4247e7fefe
commit d183a607af
  1. 2
      CHANGELOG.md
  2. 20
      apps/block_scout_web/lib/block_scout_web/controllers/transaction_raw_trace_controller.ex
  3. 40
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/parity.ex
  4. 9
      apps/explorer/lib/explorer/chain.ex

@ -1,7 +1,7 @@
## Current ## Current
### Features ### 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 - [#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 - [#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 - [#2834](https://github.com/poanetwork/blockscout/pull/2834) - always redirect to checksummed hash

@ -35,7 +35,7 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
if first_trace_exists do if first_trace_exists do
internal_transactions internal_transactions
else else
{:ok, first_trace_params} = response =
Chain.fetch_first_trace( Chain.fetch_first_trace(
[ [
%{ %{
@ -48,13 +48,19 @@ defmodule BlockScoutWeb.TransactionRawTraceController do
json_rpc_named_arguments json_rpc_named_arguments
) )
InternalTransactions.run_insert_only(first_trace_params, %{ case response do
timeout: :infinity, {:ok, first_trace_params} ->
timestamps: Import.timestamps(), InternalTransactions.run_insert_only(first_trace_params, %{
internal_transactions: %{params: 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 end
render( render(

@ -2,7 +2,7 @@ defmodule EthereumJSONRPC.Parity do
@moduledoc """ @moduledoc """
Ethereum JSONRPC methods that are only supported by [Parity](https://wiki.parity.io/). 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] import EthereumJSONRPC, only: [id_to_params: 1, integer_to_quantity: 1, json_rpc: 2, request: 1]
alias EthereumJSONRPC.Parity.{FetchedBeneficiaries, Traces} 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 def fetch_first_trace(transactions_params, json_rpc_named_arguments) when is_list(transactions_params) do
id_to_params = id_to_params(transactions_params) id_to_params = id_to_params(transactions_params)
with {:ok, responses} <- trace_replay_transaction_response =
id_to_params id_to_params
|> trace_replay_transaction_requests() |> trace_replay_transaction_requests()
|> json_rpc(json_rpc_named_arguments) do |> json_rpc(json_rpc_named_arguments)
{:ok, [first_trace]} = trace_replay_transaction_responses_to_first_trace_params(responses, id_to_params)
case trace_replay_transaction_response do
%{block_hash: block_hash} = {:ok, responses} ->
transactions_params case trace_replay_transaction_responses_to_first_trace_params(responses, id_to_params) do
|> Enum.at(0) {:ok, [first_trace]} ->
%{block_hash: block_hash} =
{:ok, [%{first_trace: first_trace, block_hash: block_hash, json_rpc_named_arguments: json_rpc_named_arguments}]} 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
end end

@ -4070,10 +4070,13 @@ defmodule Explorer.Chain do
Fetches the first trace from the Parity trace URL. Fetches the first trace from the Parity trace URL.
""" """
def fetch_first_trace(transactions_params, json_rpc_named_arguments) do 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}]} = case EthereumJSONRPC.fetch_first_trace(transactions_params, json_rpc_named_arguments) do
EthereumJSONRPC.fetch_first_trace(transactions_params, json_rpc_named_arguments) {: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 end
defp format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) do defp format_tx_first_trace(first_trace, block_hash, json_rpc_named_arguments) do

Loading…
Cancel
Save