From 2aec1f4c9fd4187e54bac63dfc443f2a93665192 Mon Sep 17 00:00:00 2001 From: pasqu4le Date: Fri, 14 Jun 2019 17:57:30 +0200 Subject: [PATCH] Removes duplicate entries from Indexer.Fetcher.UncleBlock --- CHANGELOG.md | 1 + .../lib/indexer/fetcher/uncle_block.ex | 10 ++++--- .../test/indexer/fetcher/uncle_block_test.exs | 30 +++++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f77cb5439a..39596363b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - [#2119](https://github.com/poanetwork/blockscout/pull/2119) - fix map logging - [#2130](https://github.com/poanetwork/blockscout/pull/2130) - fix navigation - [#2149](https://github.com/poanetwork/blockscout/pull/2149) - remove pending transaction count +- [#2177](https://github.com/poanetwork/blockscout/pull/2177) - remove duplicate entries from UncleBlock's Fetcher ### Chore - [#2127](https://github.com/poanetwork/blockscout/pull/2127) - use previouse chromedriver version diff --git a/apps/indexer/lib/indexer/fetcher/uncle_block.ex b/apps/indexer/lib/indexer/fetcher/uncle_block.ex index 213604a73e..e9300d1e39 100644 --- a/apps/indexer/lib/indexer/fetcher/uncle_block.ex +++ b/apps/indexer/lib/indexer/fetcher/uncle_block.ex @@ -71,17 +71,19 @@ defmodule Indexer.Fetcher.UncleBlock do @impl BufferedTask @decorate trace(name: "fetch", resource: "Indexer.Fetcher.UncleBlock.run/2", service: :indexer, tracer: Tracer) def run(entries, %Block.Fetcher{json_rpc_named_arguments: json_rpc_named_arguments} = block_fetcher) do - entry_count = Enum.count(entries) + unique_entries = Enum.uniq(entries) + + entry_count = Enum.count(unique_entries) Logger.metadata(count: entry_count) Logger.debug("fetching") - entries + unique_entries |> Enum.map(&entry_to_params/1) |> EthereumJSONRPC.fetch_uncle_blocks(json_rpc_named_arguments) |> case do {:ok, blocks} -> - run_blocks(blocks, block_fetcher, entries) + run_blocks(blocks, block_fetcher, unique_entries) {:error, reason} -> Logger.error( @@ -91,7 +93,7 @@ defmodule Indexer.Fetcher.UncleBlock do error_count: entry_count ) - {:retry, entries} + {:retry, unique_entries} end end diff --git a/apps/indexer/test/indexer/fetcher/uncle_block_test.exs b/apps/indexer/test/indexer/fetcher/uncle_block_test.exs index f3350b8de7..93a11b0b64 100644 --- a/apps/indexer/test/indexer/fetcher/uncle_block_test.exs +++ b/apps/indexer/test/indexer/fetcher/uncle_block_test.exs @@ -169,6 +169,36 @@ defmodule Indexer.Fetcher.UncleBlockTest do assert {:retry, ^entries} = UncleBlock.run(entries, %Block.Fetcher{json_rpc_named_arguments: json_rpc_named_arguments}) end + + test "retries only unique uncles on failed request", %{json_rpc_named_arguments: json_rpc_named_arguments} do + %Hash{bytes: block_hash_bytes} = block_hash() + entry = {block_hash_bytes, 0} + entries = [entry, entry] + + EthereumJSONRPC.Mox + |> expect(:json_rpc, fn [ + %{ + id: id, + method: "eth_getUncleByBlockHashAndIndex" + } + ], + _ -> + {:ok, + [ + %{ + id: id, + error: %{ + code: 404, + data: %{index: 0, nephew_hash: "0xa0814f0478fe90c82852f812fd74c96df148654c326d2600d836e6908ebb62b4"}, + message: "Not Found" + } + } + ]} + end) + + assert {:retry, [entry]} = + UncleBlock.run(entries, %Block.Fetcher{json_rpc_named_arguments: json_rpc_named_arguments}) + end end describe "run_blocks/2" do