Merge pull request #2177 from poanetwork/filter_duplicate_uncles

Removes duplicate entries from Indexer.Fetcher.UncleBlock
pull/2203/head
Victor Baranov 6 years ago committed by GitHub
commit 558a85d1a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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

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

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