Merge pull request #7899 from blockscout/fix-catchup-numbers-to-ranges

Fix catchup numbers_to_ranges function
pull/7921/head
Victor Baranov 1 year ago committed by GitHub
commit c9da4781ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 4
      apps/indexer/lib/indexer/block/catchup/fetcher.ex
  3. 58
      apps/indexer/test/indexer/block/catchup/fetcher_test.exs

@ -21,6 +21,7 @@
- [#7764](https://github.com/blockscout/blockscout/pull/7764) - Fix missing ranges insertion and deletion logic
- [#7843](https://github.com/blockscout/blockscout/pull/7843) - Fix created_contract_code_indexed_at updating
- [#7855](https://github.com/blockscout/blockscout/pull/7855) - Handle internal transactions unique_violation
- [#7899](https://github.com/blockscout/blockscout/pull/7899) - Fix catchup numbers_to_ranges function
### Chore

@ -289,14 +289,14 @@ defmodule Indexer.Block.Catchup.Fetcher do
defp numbers_to_ranges(numbers) when is_list(numbers) do
numbers
|> Enum.sort()
|> Enum.sort(&>=/2)
|> Enum.chunk_while(
nil,
fn
number, nil ->
{:cont, number..number}
number, first..last when number == last + 1 ->
number, first..last when number == last - 1 ->
{:cont, first..number}
number, range ->

@ -9,6 +9,7 @@ defmodule Indexer.Block.Catchup.FetcherTest do
alias Explorer.Chain.Block.Reward
alias Explorer.Chain.Hash
alias Explorer.Utility.MissingRangesManipulator
alias Explorer.Utility.MissingBlockRange
alias Indexer.Block
alias Indexer.Block.Catchup.Fetcher
alias Indexer.Block.Catchup.MissingRangesCollector
@ -606,6 +607,63 @@ defmodule Indexer.Block.Catchup.FetcherTest do
assert_receive {:block_numbers, [^block_number]}, 5_000
end
test "failed blocks handles correctly", %{json_rpc_named_arguments: json_rpc_named_arguments} do
Application.put_env(:indexer, Indexer.Block.Catchup.Fetcher, batch_size: 2, concurrency: 10)
Application.put_env(:indexer, :block_ranges, "0..1")
start_supervised!({Task.Supervisor, name: Indexer.Block.Catchup.TaskSupervisor})
MissingRangesCollector.start_link([])
MissingRangesManipulator.start_link([])
EthereumJSONRPC.Mox
|> expect(:json_rpc, 2, fn
[
%{
id: id_1,
jsonrpc: "2.0",
method: "eth_getBlockByNumber",
params: ["0x1", true]
},
%{
id: id_2,
jsonrpc: "2.0",
method: "eth_getBlockByNumber",
params: ["0x0", true]
}
],
_options ->
{:ok,
[
%{
id: id_1,
jsonrpc: "2.0",
error: %{message: "error"}
},
%{
id: id_2,
jsonrpc: "2.0",
error: %{message: "error"}
}
]}
[], _options ->
{:ok, []}
end)
Process.sleep(50)
assert %{first_block_number: 1, last_block_number: 0, missing_block_count: 2, shrunk: false} =
Fetcher.task(%Fetcher{
block_fetcher: %Block.Fetcher{
callback_module: Fetcher,
json_rpc_named_arguments: json_rpc_named_arguments
}
})
Process.sleep(1000)
assert %{from_number: 1, to_number: 0} = Repo.one(MissingBlockRange)
end
end
defp count(schema) do

Loading…
Cancel
Save