pull/2128/head
Ayrat Badykov 6 years ago
parent a9bbf8acd4
commit 55854d9b3b
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 6
      apps/indexer/lib/indexer/block/realtime/fetcher.ex
  2. 26
      apps/indexer/lib/indexer/fetcher/uncle_block.ex
  3. 38
      apps/indexer/test/indexer/fetcher/uncle_block_test.exs

@ -201,6 +201,12 @@ defmodule Indexer.Block.Realtime.Fetcher do
end
end
def import(_, _) do
Logger.warn("Empty parameters were provided for realtime fetcher")
{:ok, []}
end
defp start_fetch_and_import(number, block_fetcher, previous_number, max_number_seen) do
start_at = determine_start_at(number, previous_number, max_number_seen)

@ -104,18 +104,18 @@ defmodule Indexer.Fetcher.UncleBlock do
{nephew_hash_bytes, index}
end
defp run_blocks(%Blocks{blocks_params: []}, _, original_entries), do: {:retry, original_entries}
defp run_blocks(
%Blocks{
blocks_params: blocks_params,
transactions_params: transactions_params,
block_second_degree_relations_params: block_second_degree_relations_params,
errors: errors
},
block_fetcher,
original_entries
) do
def run_blocks(%Blocks{blocks_params: []}, _, original_entries), do: {:retry, original_entries}
def run_blocks(
%Blocks{
blocks_params: blocks_params,
transactions_params: transactions_params,
block_second_degree_relations_params: block_second_degree_relations_params,
errors: errors
},
block_fetcher,
original_entries
) do
addresses_params = Addresses.extract_addresses(%{blocks: blocks_params, transactions: transactions_params})
case Block.Fetcher.import(block_fetcher, %{
@ -241,7 +241,7 @@ defmodule Indexer.Fetcher.UncleBlock do
{nephew_hash_bytes, index}
end
defp error_to_entry(%{data: %{nephew_hash: hash}, index: index}) when is_binary(hash) do
defp error_to_entry(%{data: %{nephew_hash: hash, index: index}}) when is_binary(hash) do
{:ok, %Hash{bytes: nephew_hash_bytes}} = Hash.Full.cast(hash)
{nephew_hash_bytes, index}

@ -6,6 +6,7 @@ defmodule Indexer.Fetcher.UncleBlockTest do
import EthereumJSONRPC, only: [integer_to_quantity: 1]
alias EthereumJSONRPC.Blocks
alias Explorer.Chain
alias Explorer.Chain.Hash
alias Indexer.Block
@ -170,6 +171,43 @@ defmodule Indexer.Fetcher.UncleBlockTest do
end
end
describe "run_blocks/2" do
test "converts errors to entries for retry", %{json_rpc_named_arguments: json_rpc_named_arguments} do
miner_hash =
address_hash()
|> to_string()
block_number = 1
index = 0
hash = "0xa0814f0478fe90c82852f812fd74c96df148654c326d2600d836e6908ebb62b4"
params = %Blocks{
errors: [
%{
code: 404,
data: %{index: index, nephew_hash: hash},
message: "Not Found"
}
],
blocks_params: [%{miner_hash: miner_hash, number: block_number}]
}
assert {:retry, [{bin_hash, ^index}]} =
UncleBlock.run_blocks(
params,
%Block.Fetcher{
json_rpc_named_arguments: json_rpc_named_arguments,
callback_module: Indexer.Block.Realtime.Fetcher
},
[]
)
assert Hash.Full.cast(bin_hash) == Hash.Full.cast(hash)
end
end
defp wait(producer) do
producer.()
rescue

Loading…
Cancel
Save