add logging

pull/1470/head
Ayrat Badykov 6 years ago
parent f619016587
commit 659c26d4a2
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 5
      apps/indexer/config/dev.exs
  2. 5
      apps/indexer/config/prod.exs
  3. 5
      apps/indexer/config/test.exs
  4. 6
      apps/indexer/lib/indexer/block/supervisor.ex
  5. 65
      apps/indexer/lib/indexer/temporary/failed_created_addresses.ex
  6. 1
      config/config.exs

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

@ -13,6 +13,11 @@ config :logger, :indexer_token_balances,
metadata_filter: [fetcher: :token_balances],
rotate: %{max_bytes: 52_428_800, keep: 19}
config :logger, :failed_contract_creations,
level: :prod,
path: Path.absname("logs/prod/indexer/failed_contract_creations.log"),
metadata_filter: [fetcher: :failed_created_addresses]
variant =
if is_nil(System.get_env("ETHEREUM_JSONRPC_VARIANT")) do
"parity"

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

@ -5,6 +5,7 @@ defmodule Indexer.Block.Supervisor do
alias Indexer.Block
alias Indexer.Block.{Catchup, InvalidConsensus, Realtime, Reward, Uncle}
alias Indexer.Temporary.FailedCreatedAddresses
use Supervisor
@ -45,6 +46,11 @@ defmodule Indexer.Block.Supervisor do
[
[json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor],
[name: Reward.Supervisor]
]},
{FailedCreatedAddresses.Supervisor,
[
json_rpc_named_arguments,
[name: FailedCreatedAddresses.Supervisor]
]}
],
strategy: :one_for_one

@ -2,9 +2,10 @@ defmodule Indexer.Temporary.FailedCreatedAddresses do
@moduledoc """
Temporary module to fix internal transactions and their created transactions if a parent transaction has failed.
"""
use GenServer
require Logger
import Ecto.Query
alias Explorer.Chain.{InternalTransaction, Transaction}
@ -26,6 +27,13 @@ defmodule Indexer.Temporary.FailedCreatedAddresses do
end
def run(json_rpc_named_arguments) do
Logger.debug(
[
"Started query to fetch internal transactions that need to be fixed"
],
fetcher: :failed_created_addresses
)
query =
from(it in InternalTransaction,
left_join: t in Transaction,
@ -36,8 +44,17 @@ defmodule Indexer.Temporary.FailedCreatedAddresses do
found_internal_transactions = Repo.all(query, timeout: @query_timeout)
Logger.debug(
[
"Finished query to fetch internal transactions that need to be fixed. Number of records is #{
Enum.count(found_internal_transactions)
}"
],
fetcher: :failed_created_addresses
)
TaskSupervisor
|> Task.Supervisor.async_stream(
|> Task.Supervisor.async_stream_nolink(
found_internal_transactions,
fn internal_transaction -> fix_internal_transaction(internal_transaction, json_rpc_named_arguments) end,
@task_options
@ -46,13 +63,45 @@ defmodule Indexer.Temporary.FailedCreatedAddresses do
end
def fix_internal_transaction(internal_transaction, json_rpc_named_arguments) do
internal_transaction
|> code_entry()
|> Indexer.Code.Fetcher.run(json_rpc_named_arguments)
try do
Logger.debug(
[
"Started fixing internal transaction #{internal_transaction.index} for transaction with hash #{
to_string(internal_transaction.transaction_hash)
}"
],
fetcher: :failed_created_addresses
)
:ok =
internal_transaction
|> code_entry()
|> Indexer.Code.Fetcher.run(json_rpc_named_arguments)
internal_transaction.transaction
|> transaction_entry()
|> Indexer.InternalTransaction.Fetcher.run(json_rpc_named_arguments)
:ok =
internal_transaction.transaction
|> transaction_entry()
|> Indexer.InternalTransaction.Fetcher.run(json_rpc_named_arguments)
Logger.debug(
[
"Finished fixing internal transaction #{internal_transaction.index} for transaction with hash #{
to_string(internal_transaction.transaction_hash)
}"
],
fetcher: :failed_created_addresses
)
rescue
e ->
Logger.debug(
[
"Failed to fix internal transaction #{internal_transaction.index} for transaction with hash #{
to_string(internal_transaction.transaction_hash)
} because of #{inspect(e)}"
],
fetcher: :failed_created_addresses
)
end
end
def code_entry(%InternalTransaction{

@ -26,6 +26,7 @@ config :logger,
# only :indexer, but all levels
{LoggerFileBackend, :indexer},
{LoggerFileBackend, :indexer_token_balances},
{LoggerFileBackend, :failed_contract_creations},
{LoggerFileBackend, :reading_token_functions}
]

Loading…
Cancel
Save