return InternalTransaction.Fetcher

pull/1353/head
Ayrat Badykov 6 years ago
parent 3520c7d8d7
commit 2e94a0d2a6
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 2
      apps/explorer/priv/repo/migrations/20190116082843_add_created_contract_indexed_at_to_transactions.exs
  2. 18
      apps/indexer/lib/indexer/block/catchup/fetcher.ex
  3. 13
      apps/indexer/lib/indexer/code/fetcher.ex
  4. 6
      apps/indexer/lib/indexer/shrinkable/supervisor.ex
  5. 7
      apps/indexer/test/indexer/block/fetcher_test.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

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

@ -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(&params/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

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

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

Loading…
Cancel
Save