Merge pull request #3327 from poanetwork/vb-handle-errors-for-nonarchive-node

Handle various indexer fetchers errors in setup with non-archive node
pull/3329/head
Victor Baranov 4 years ago committed by GitHub
commit 73ea331c6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      apps/explorer/lib/explorer/chain/address/coin_balance_daily.ex
  3. 3
      apps/explorer/lib/explorer/chain/import.ex
  4. 2
      apps/indexer/config/dev/geth.exs
  5. 2
      apps/indexer/config/prod/geth.exs
  6. 17
      apps/indexer/lib/indexer/fetcher/coin_balance.ex
  7. 17
      apps/indexer/lib/indexer/fetcher/internal_transaction.ex
  8. 22
      apps/indexer/lib/indexer/transform/address_coin_balances_daily.ex

@ -31,6 +31,7 @@
- [#3256](https://github.com/poanetwork/blockscout/pull/3256) - Fix for invisible validator address at block page and wrong alert text color at xDai - [#3256](https://github.com/poanetwork/blockscout/pull/3256) - Fix for invisible validator address at block page and wrong alert text color at xDai
### Chore ### Chore
- [#3327](https://github.com/poanetwork/blockscout/pull/3327) - Handle various indexer fetchers errors in setup with non-archive node
- [#3325](https://github.com/poanetwork/blockscout/pull/3325) - Dark theme improvements - [#3325](https://github.com/poanetwork/blockscout/pull/3325) - Dark theme improvements
- [#3316](https://github.com/poanetwork/blockscout/pull/3316), [#3317](https://github.com/poanetwork/blockscout/pull/3317) - xDai smile logo - [#3316](https://github.com/poanetwork/blockscout/pull/3316), [#3317](https://github.com/poanetwork/blockscout/pull/3317) - xDai smile logo
- [#3315](https://github.com/poanetwork/blockscout/pull/3315) - Environment variable to disable Bridge market cap updater - [#3315](https://github.com/poanetwork/blockscout/pull/3315) - Environment variable to disable Bridge market cap updater

@ -64,7 +64,9 @@ defmodule Explorer.Chain.Address.CoinBalanceDaily do
) )
end end
def changeset(%__MODULE__{} = balance, params) do def changeset(_, params) when is_nil(params), do: :ignore
def changeset(%__MODULE__{} = balance, params) when not is_nil(params) do
balance balance
|> cast(params, @allowed_fields) |> cast(params, @allowed_fields)
|> validate_required(@required_fields) |> validate_required(@required_fields)

@ -168,6 +168,9 @@ defmodule Explorer.Chain.Import do
%Changeset{valid?: true}, {:error, _} = error -> %Changeset{valid?: true}, {:error, _} = error ->
error error
:ignore, error ->
{:error, error}
end) end)
|> case do |> case do
{:ok, changes} -> {:ok, {runner, changes}} {:ok, changes} -> {:ok, {runner, changes}}

@ -10,7 +10,7 @@ config :indexer,
), ),
transport_options: [ transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison, http: EthereumJSONRPC.HTTP.HTTPoison,
url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY", url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"),
http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]] http_options: [recv_timeout: :timer.minutes(1), timeout: :timer.minutes(1), hackney: [pool: :ethereum_jsonrpc]]
], ],
variant: EthereumJSONRPC.Geth variant: EthereumJSONRPC.Geth

@ -10,7 +10,7 @@ config :indexer,
), ),
transport_options: [ transport_options: [
http: EthereumJSONRPC.HTTP.HTTPoison, http: EthereumJSONRPC.HTTP.HTTPoison,
url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL") || "https://mainnet.infura.io/8lTvJTKmHPCHazkneJsY", url: System.get_env("ETHEREUM_JSONRPC_HTTP_URL"),
http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]] http_options: [recv_timeout: :timer.minutes(10), timeout: :timer.minutes(10), hackney: [pool: :ethereum_jsonrpc]]
], ],
variant: EthereumJSONRPC.Geth variant: EthereumJSONRPC.Geth

@ -151,16 +151,20 @@ defmodule Indexer.Fetcher.CoinBalance do
block_timestamp_map = block_timestamp_map =
Enum.reduce(block_numbers, %{}, fn block_number, map -> Enum.reduce(block_numbers, %{}, fn block_number, map ->
{:ok, %Blocks{blocks_params: [%{timestamp: timestamp}]}} = case EthereumJSONRPC.fetch_blocks_by_range(block_number..block_number, json_rpc_named_arguments) do
EthereumJSONRPC.fetch_blocks_by_range(block_number..block_number, json_rpc_named_arguments) {:ok, %Blocks{blocks_params: [%{timestamp: timestamp}]}} ->
day = DateTime.to_date(timestamp) day = DateTime.to_date(timestamp)
Map.put(map, "#{block_number}", day) Map.put(map, "#{block_number}", day)
_ ->
%{}
end
end) end)
importable_balances_daily_params = importable_balances_daily_params =
params_list params_list
|> Enum.map(fn balance_param -> |> Enum.map(fn balance_param ->
if Map.has_key?(block_timestamp_map, "#{balance_param.block_number}") do
day = Map.get(block_timestamp_map, "#{balance_param.block_number}") day = Map.get(block_timestamp_map, "#{balance_param.block_number}")
incoming_balance_daily_param = %{ incoming_balance_daily_param = %{
@ -170,6 +174,9 @@ defmodule Indexer.Fetcher.CoinBalance do
} }
incoming_balance_daily_param incoming_balance_daily_param
else
nil
end
end) end)
addresses_params = balances_params_to_address_params(importable_balances_params) addresses_params = balances_params_to_address_params(importable_balances_params)
@ -228,9 +235,9 @@ defmodule Indexer.Fetcher.CoinBalance do
end end
defp run_fetched_balances(%FetchedBalances{errors: errors} = fetched_balances, _) do defp run_fetched_balances(%FetchedBalances{errors: errors} = fetched_balances, _) do
{:ok, imported} = import_fetched_balances(fetched_balances) with {:ok, imported} <- import_fetched_balances(fetched_balances) do
Accounts.drop(imported[:addresses]) Accounts.drop(imported[:addresses])
end
retry(errors) retry(errors)
end end

@ -109,7 +109,12 @@ defmodule Indexer.Fetcher.InternalTransaction do
EthereumJSONRPC.fetch_block_internal_transactions(unique_numbers, json_rpc_named_arguments) EthereumJSONRPC.fetch_block_internal_transactions(unique_numbers, json_rpc_named_arguments)
_ -> _ ->
try do
fetch_block_internal_transactions_by_transactions(unique_numbers, json_rpc_named_arguments) fetch_block_internal_transactions_by_transactions(unique_numbers, json_rpc_named_arguments)
rescue
error ->
{:error, error}
end
end end
|> case do |> case do
{:ok, internal_transactions_params} -> {:ok, internal_transactions_params} ->
@ -156,8 +161,16 @@ defmodule Indexer.Fetcher.InternalTransaction do
|> Chain.get_transactions_of_block_number() |> Chain.get_transactions_of_block_number()
|> Enum.map(&params(&1)) |> Enum.map(&params(&1))
|> case do |> case do
[] -> {:ok, []} [] ->
transactions -> EthereumJSONRPC.fetch_internal_transactions(transactions, json_rpc_named_arguments) {:ok, []}
transactions ->
try do
EthereumJSONRPC.fetch_internal_transactions(transactions, json_rpc_named_arguments)
catch
:exit, error ->
{:error, error}
end
end end
|> case do |> case do
{:ok, internal_transactions} -> {:ok, internal_transactions ++ acc_list} {:ok, internal_transactions} -> {:ok, internal_transactions ++ acc_list}

@ -64,19 +64,26 @@ defmodule Indexer.Transform.AddressCoinBalancesDaily do
block_timestamp_map = block_timestamp_map =
Enum.reduce(block_numbers, %{}, fn block_number, map -> Enum.reduce(block_numbers, %{}, fn block_number, map ->
{:ok, %Blocks{blocks_params: [%{timestamp: timestamp}]}} = case EthereumJSONRPC.fetch_blocks_by_range(block_number..block_number, json_rpc_named_arguments) do
EthereumJSONRPC.fetch_blocks_by_range(block_number..block_number, json_rpc_named_arguments) {:ok, %Blocks{blocks_params: [%{timestamp: timestamp}]}} ->
day = DateTime.to_date(timestamp) day = DateTime.to_date(timestamp)
Map.put(map, "#{block_number}", day) Map.put(map, "#{block_number}", day)
_ ->
map
end
end) end)
logs_params logs_params
|> Enum.into(acc, fn |> Enum.into(acc, fn
%{address_hash: address_hash, block_number: block_number} %{address_hash: address_hash, block_number: block_number}
when is_binary(address_hash) and is_integer(block_number) -> when is_binary(address_hash) and is_integer(block_number) ->
if Map.has_key?(block_timestamp_map, "#{block_number}") do
day = Map.get(block_timestamp_map, "#{block_number}") day = Map.get(block_timestamp_map, "#{block_number}")
%{address_hash: address_hash, day: day} %{address_hash: address_hash, day: day}
else
nil
end
%{type: "pending"} -> %{type: "pending"} ->
nil nil
@ -137,9 +144,8 @@ defmodule Indexer.Transform.AddressCoinBalancesDaily do
# a transaction MUST have a `from_address_hash` # a transaction MUST have a `from_address_hash`
json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments) json_rpc_named_arguments = Application.get_env(:explorer, :json_rpc_named_arguments)
{:ok, %Blocks{blocks_params: [%{timestamp: block_timestamp}]}} = case EthereumJSONRPC.fetch_blocks_by_range(block_number..block_number, json_rpc_named_arguments) do
EthereumJSONRPC.fetch_blocks_by_range(block_number..block_number, json_rpc_named_arguments) {:ok, %Blocks{blocks_params: [%{timestamp: block_timestamp}]}} ->
day = DateTime.to_date(block_timestamp) day = DateTime.to_date(block_timestamp)
acc = MapSet.put(initial, %{address_hash: from_address_hash, day: day}) acc = MapSet.put(initial, %{address_hash: from_address_hash, day: day})
@ -151,5 +157,9 @@ defmodule Indexer.Transform.AddressCoinBalancesDaily do
_ -> _ ->
acc acc
end end
_ ->
initial
end
end end
end end

Loading…
Cancel
Save