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
### 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

@ -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(

@ -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

@ -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

Loading…
Cancel
Save