From 2e94a0d2a69f0934c74d05c7e445524031d01324 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Thu, 17 Jan 2019 14:27:18 +0300 Subject: [PATCH] return InternalTransaction.Fetcher --- ...ted_contract_indexed_at_to_transactions.exs | 2 +- .../lib/indexer/block/catchup/fetcher.ex | 18 +++++++++++++++++- apps/indexer/lib/indexer/code/fetcher.ex | 13 ++++++------- .../lib/indexer/shrinkable/supervisor.ex | 6 ++++++ .../test/indexer/block/fetcher_test.exs | 7 ++++--- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/apps/explorer/priv/repo/migrations/20190116082843_add_created_contract_indexed_at_to_transactions.exs b/apps/explorer/priv/repo/migrations/20190116082843_add_created_contract_indexed_at_to_transactions.exs index 3ce6f08580..98282c2a2d 100644 --- a/apps/explorer/priv/repo/migrations/20190116082843_add_created_contract_indexed_at_to_transactions.exs +++ b/apps/explorer/priv/repo/migrations/20190116082843_add_created_contract_indexed_at_to_transactions.exs @@ -3,7 +3,7 @@ defmodule Explorer.Repo.Migrations.AddCreatedContractIndexedAtToTransactions do def change do alter table(:transactions) do - # `null` when `internal_transactions` has never been fetched + # `null` when `created_contract_code` has never been fetched add(:created_contract_code_indexed_at, :utc_datetime_usec, null: true) end end diff --git a/apps/indexer/lib/indexer/block/catchup/fetcher.ex b/apps/indexer/lib/indexer/block/catchup/fetcher.ex index 869eb4b4d7..adcc547a79 100644 --- a/apps/indexer/lib/indexer/block/catchup/fetcher.ex +++ b/apps/indexer/lib/indexer/block/catchup/fetcher.ex @@ -13,7 +13,7 @@ defmodule Indexer.Block.Catchup.Fetcher do alias Ecto.Changeset alias Explorer.Chain alias Explorer.Chain.Transaction - alias Indexer.{Block, Code, Sequence, TokenBalance, Tracer} + alias Indexer.{Block, Code, InternalTransaction, Sequence, TokenBalance, Tracer} alias Indexer.Memory.Shrinkable @behaviour Block.Fetcher @@ -152,6 +152,22 @@ defmodule Indexer.Block.Catchup.Fetcher do [] end) |> Code.Fetcher.async_fetch(10_000) + + transactions + |> Enum.flat_map(fn + %Transaction{ + block_number: block_number, + index: index, + hash: hash, + created_contract_address_hash: nil, + internal_transactions_indexed_at: nil + } -> + [%{block_number: block_number, index: index, hash: hash}] + + _ -> + [] + end) + |> InternalTransaction.Fetcher.async_fetch(10_000) end defp async_import_created_contract_codes(_), do: :ok diff --git a/apps/indexer/lib/indexer/code/fetcher.ex b/apps/indexer/lib/indexer/code/fetcher.ex index d93a121b38..d2da70534f 100644 --- a/apps/indexer/lib/indexer/code/fetcher.ex +++ b/apps/indexer/lib/indexer/code/fetcher.ex @@ -1,4 +1,8 @@ defmodule Indexer.Code.Fetcher do + @moduledoc """ + Fetches `contract_code` `t:Explorer.Chain.Address.t/0`. + """ + use Spandex.Decorators require Logger @@ -78,7 +82,7 @@ defmodule Indexer.Code.Fetcher do tracer: Tracer ) def run(entries, json_rpc_named_arguments) do - Logger.debug("fetching internal transactions for transactions") + Logger.debug("fetching created_contract_code for transactions") entries |> Enum.map(¶ms/1) @@ -105,7 +109,7 @@ defmodule Indexer.Code.Fetcher do Logger.error( fn -> [ - "failed to import internal transactions for transactions: ", + "failed to import created_contract_code for transactions: ", inspect(reason) ] end, @@ -115,11 +119,6 @@ defmodule Indexer.Code.Fetcher do {:retry, entries} end - {:error, reason} -> - Logger.error(fn -> ["failed to fetch internal transactions for transactions: ", inspect(reason)] end) - - {:retry, entries} - :ignore -> :ok end diff --git a/apps/indexer/lib/indexer/shrinkable/supervisor.ex b/apps/indexer/lib/indexer/shrinkable/supervisor.ex index 1702be55ad..756c91d992 100644 --- a/apps/indexer/lib/indexer/shrinkable/supervisor.ex +++ b/apps/indexer/lib/indexer/shrinkable/supervisor.ex @@ -9,6 +9,7 @@ defmodule Indexer.Shrinkable.Supervisor do Block, Code, CoinBalance, + InternalTransaction, PendingTransaction, Token, TokenBalance, @@ -65,6 +66,11 @@ defmodule Indexer.Shrinkable.Supervisor do [json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor], [name: Code.Supervisor] ]}, + {InternalTransaction.Supervisor, + [ + [json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor], + [name: InternalTransaction.Supervisor] + ]}, {Token.Supervisor, [ [json_rpc_named_arguments: json_rpc_named_arguments, memory_monitor: memory_monitor], diff --git a/apps/indexer/test/indexer/block/fetcher_test.exs b/apps/indexer/test/indexer/block/fetcher_test.exs index c3af482b71..d6f163cd38 100644 --- a/apps/indexer/test/indexer/block/fetcher_test.exs +++ b/apps/indexer/test/indexer/block/fetcher_test.exs @@ -9,7 +9,7 @@ defmodule Indexer.Block.FetcherTest do alias Explorer.Chain alias Explorer.Chain.{Address, Log, Transaction, Wei} - alias Indexer.{CoinBalance, BufferedTask, Code, Token, TokenBalance} + alias Indexer.{CoinBalance, BufferedTask, Code, InternalTransaction, Token, TokenBalance} alias Indexer.Block.{Fetcher, Uncle} @moduletag capture_log: true @@ -42,6 +42,7 @@ defmodule Indexer.Block.FetcherTest do setup %{json_rpc_named_arguments: json_rpc_named_arguments} do CoinBalance.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) Code.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) + InternalTransaction.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) Token.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) TokenBalance.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments) @@ -222,7 +223,7 @@ defmodule Indexer.Block.FetcherTest do errors: [] }} = result - wait_for_tasks(Code.Fetcher) + wait_for_tasks(InternalTransaction.Fetcher) wait_for_tasks(CoinBalance.Fetcher) assert Repo.aggregate(Chain.Block, :count, :hash) == 1 @@ -579,7 +580,7 @@ defmodule Indexer.Block.FetcherTest do errors: [] }} = Fetcher.fetch_and_import_range(block_fetcher, block_number..block_number) - wait_for_tasks(Code.Fetcher) + wait_for_tasks(InternalTransaction.Fetcher) wait_for_tasks(CoinBalance.Fetcher) assert Repo.aggregate(Chain.Block, :count, :hash) == 1