Removes duplicate entries from Indexer.Fetcher.UncleBlock

pull/2177/head
pasqu4le 6 years ago
parent 951045356d
commit 2aec1f4c9f
No known key found for this signature in database
GPG Key ID: 8F3EE01F1DC90687
  1. 1
      CHANGELOG.md
  2. 10
      apps/indexer/lib/indexer/fetcher/uncle_block.ex
  3. 30
      apps/indexer/test/indexer/fetcher/uncle_block_test.exs

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

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

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

Loading…
Cancel
Save