Merge branch 'master' into 623-live-reload-pending-transaction-details

pull/760/head
Andrew Cravenho 6 years ago committed by GitHub
commit 52fe1f1320
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      apps/explorer/lib/explorer/chain.ex
  2. 4
      apps/explorer/lib/explorer/chain/import.ex
  3. 5
      apps/indexer/config/dev.exs
  4. 5
      apps/indexer/config/prod.exs
  5. 5
      apps/indexer/config/test.exs
  6. 1
      apps/indexer/lib/indexer/block/realtime/fetcher.ex
  7. 6
      apps/indexer/lib/indexer/token_balance/fetcher.ex
  8. 30
      apps/indexer/lib/indexer/token_balances.ex
  9. 61
      apps/indexer/test/indexer/token_balances_test.exs
  10. 3
      config/config.exs

@ -1384,12 +1384,12 @@ defmodule Explorer.Chain do
* `:pending` - the transaction has not be confirmed in a block yet.
* `:awaiting_internal_transactions` - the transaction happened in a pre-Byzantium block or on a chain like Ethereum
Classic (ETC) that never adopted [EIP-658](https://github.com/Arachnid/EIPs/blob/master/EIPS/eip-658.md), which
add transaction status to transaction receipts, so the stats can only be derived whether the last internal
add transaction status to transaction receipts, so the status can only be derived whether the first internal
transaction has an error.
* `:success` - the transaction has been confirmed in a block
* `{:error, :awaiting_internal_transactions}` - the transactions happened post-Byzantium, but the error message
requires the internal transactions.
* `{:error, reason}` - the transaction failed due to `reason` in its last internal transaction.
* `{:error, reason}` - the transaction failed due to `reason` in its first internal transaction.
"""
@spec transaction_to_status(Transaction.t()) ::

@ -868,12 +868,12 @@ defmodule Explorer.Chain.Import do
),
error:
fragment(
"(SELECT it.error FROM internal_transactions AS it WHERE it.transaction_hash = ? ORDER BY it.index DESC LIMIT 1)",
"(SELECT it.error FROM internal_transactions AS it WHERE it.transaction_hash = ? ORDER BY it.index ASC LIMIT 1)",
t.hash
),
status:
fragment(
"COALESCE(?, CASE WHEN (SELECT it.error FROM internal_transactions AS it WHERE it.transaction_hash = ? ORDER BY it.index DESC LIMIT 1) IS NULL THEN ? ELSE ? END)",
"COALESCE(?, CASE WHEN (SELECT it.error FROM internal_transactions AS it WHERE it.transaction_hash = ? ORDER BY it.index ASC LIMIT 1) IS NULL THEN ? ELSE ? END)",
t.status,
t.hash,
type(^:ok, t.status),

@ -4,6 +4,11 @@ config :logger, :indexer,
level: :debug,
path: Path.absname("logs/dev/indexer.log")
config :logger, :indexer_token_balances,
level: :debug,
path: Path.absname("logs/dev/indexer/token_balances/error.log"),
metadata_filter: [fetcher: :token_balances]
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"

@ -4,6 +4,11 @@ config :logger, :indexer,
level: :info,
path: Path.absname("logs/prod/indexer.log")
config :logger, :indexer_token_balances,
level: :debug,
path: Path.absname("logs/prod/indexer/token_balances/error.log"),
metadata_filter: [fetcher: :token_balances]
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"

@ -3,3 +3,8 @@ use Mix.Config
config :logger, :indexer,
level: :warn,
path: Path.absname("logs/test/indexer.log")
config :logger, :indexer_token_balances,
level: :debug,
path: Path.absname("logs/test/indexer/token_balances/error.log"),
metadata_filter: [fetcher: :token_balances]

@ -146,6 +146,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
|> put_in([Access.key(:internal_transactions, %{}), :params], internal_transactions_params)
|> put_in([Access.key(:token_balances), :params], token_balances),
{:ok, results} = ok <- Chain.import(chain_import_options) do
TokenBalances.log_fetching_errors(__MODULE__, token_balances)
async_import_remaining_block_data(results)
ok
end

@ -69,12 +69,14 @@ defmodule Indexer.TokenBalance.Fetcher do
end
def fetch_from_blockchain(token_balances) do
{:ok, token_balances_params} =
{:ok, token_balances} =
token_balances
|> Stream.map(&format_params/1)
|> TokenBalances.fetch_token_balances_from_blockchain()
token_balances_params
TokenBalances.log_fetching_errors(__MODULE__, token_balances)
token_balances
end
def import_token_balances(token_balances_params) do

@ -3,6 +3,8 @@ defmodule Indexer.TokenBalances do
Reads Token's balances using Smart Contract functions from the blockchain.
"""
require Logger
alias Explorer.Token.BalanceReader
@doc """
@ -42,11 +44,11 @@ defmodule Indexer.TokenBalances do
end
defp set_token_balance_value({:ok, balance}, token_balance) do
Map.merge(token_balance, %{value: balance, value_fetched_at: DateTime.utc_now()})
Map.merge(token_balance, %{value: balance, value_fetched_at: DateTime.utc_now(), error: nil})
end
defp set_token_balance_value({:error, _}, token_balance) do
Map.merge(token_balance, %{value: nil, value_fetched_at: nil})
defp set_token_balance_value({:error, error_message}, token_balance) do
Map.merge(token_balance, %{value: nil, value_fetched_at: nil, error: error_message})
end
def format_task_results({:exit, :timeout}), do: {:error, :timeout}
@ -54,4 +56,26 @@ defmodule Indexer.TokenBalances do
def ignore_request_with_timeouts({:error, :timeout}), do: false
def ignore_request_with_timeouts(_token_balance), do: true
def log_fetching_errors(from, token_balances_params) do
error_messages =
token_balances_params
|> Stream.filter(fn token_balance -> token_balance.error != nil end)
|> Enum.map(fn token_balance ->
"<address_hash: #{token_balance.token_contract_address_hash}, " <>
"contract_address_hash: #{token_balance.address_hash}, " <>
"block_number: #{token_balance.block_number}, " <> "error: #{token_balance.error}> \n"
end)
if Enum.any?(error_messages) do
Logger.debug(
[
"<#{from}> ",
"Errors while fetching TokenBalances through Contract interaction: \n",
error_messages
],
fetcher: :token_balances
)
end
end
end

@ -8,6 +8,7 @@ defmodule Indexer.TokenBalancesTest do
alias Explorer.Chain.Hash
import Mox
import ExUnit.CaptureLog
setup :verify_on_exit!
setup :set_mox_global
@ -88,6 +89,66 @@ defmodule Indexer.TokenBalancesTest do
end
end
describe "log_fetching_errors" do
test "logs the given from argument in final message" do
token_balance_params_with_error = Map.put(build(:token_balance), :error, "Error")
params = [token_balance_params_with_error]
from = "Tests"
log_message_response =
capture_log(fn ->
TokenBalances.log_fetching_errors(from, params)
end)
assert log_message_response =~ "<Tests"
end
test "log when there is a token_balance param with errors" do
from = "Tests"
token_balance_params_with_error = Map.put(build(:token_balance), :error, "Error")
params = [token_balance_params_with_error]
log_message_response =
capture_log(fn ->
TokenBalances.log_fetching_errors(from, params)
end)
assert log_message_response =~ "Error"
end
test "log multiple token balances params with errors" do
from = "Tests"
error_1 = "Error"
error_2 = "BadGateway"
params = [
Map.put(build(:token_balance), :error, error_1),
Map.put(build(:token_balance), :error, error_2)
]
log_message_response =
capture_log(fn ->
TokenBalances.log_fetching_errors(from, params)
end)
assert log_message_response =~ error_1
assert log_message_response =~ error_2
end
test "doesn't log when there aren't errors after fetching token balances" do
from = "Tests"
token_balance_params = Map.put(build(:token_balance), :error, nil)
params = [token_balance_params]
log_message_response =
capture_log(fn ->
TokenBalances.log_fetching_errors(from, params)
end)
assert log_message_response == ""
end
end
defp get_balance_from_blockchain() do
expect(
EthereumJSONRPC.Mox,

@ -24,7 +24,8 @@ config :logger,
# only :explorer, but all levels
{LoggerFileBackend, :explorer},
# only :indexer, but all levels
{LoggerFileBackend, :indexer}
{LoggerFileBackend, :indexer},
{LoggerFileBackend, :indexer_token_balances}
]
config :logger, :console,

Loading…
Cancel
Save