diff --git a/CHANGELOG.md b/CHANGELOG.md index fb0a5f0898..d756235f95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ - [#2130](https://github.com/poanetwork/blockscout/pull/2130) - fix navigation - [#2147](https://github.com/poanetwork/blockscout/pull/2147) - add rsk format of checksum - [#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 - [#2169](https://github.com/poanetwork/blockscout/pull/2169) - add more validator reward types for xDai - [#2173](https://github.com/poanetwork/blockscout/pull/2173) - handle correctly empty transactions - [#2174](https://github.com/poanetwork/blockscout/pull/2174) - fix reward channel joining 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