Skip to content

Commit

Permalink
Merge pull request blockscout#6687 from blockscout/fix-missing-block-…
Browse files Browse the repository at this point in the history
…ranges-initial-state

Fix MissingRangesCollector initial state
  • Loading branch information
vbaranov authored Jan 9, 2023
2 parents 640a3af + 1c04204 commit 4d0e68a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- [#6510](https://github.com/blockscout/blockscout/pull/6510) - Set consensus: false for blocks on int transaction foreign_key_violation
- [#6565](https://github.com/blockscout/blockscout/pull/6565) - Set restart: :permanent for permanent fetchers
- [#6568](https://github.com/blockscout/blockscout/pull/6568) - Drop unfetched_token_balances index
- [#6583](https://github.com/blockscout/blockscout/pull/6583) - Missing ranges collector
- [#6583](https://github.com/blockscout/blockscout/pull/6583), [#6687](https://github.com/blockscout/blockscout/pull/6687) - Missing ranges collector
- [#6647](https://github.com/blockscout/blockscout/pull/6647) - Pending block operations update

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,19 @@ defmodule Indexer.Block.Catchup.MissingRangesCollector do
defp last_block do
case Integer.parse(Application.get_env(:indexer, :last_block)) do
{block, ""} -> block + 1
_ -> BlockNumber.get_max()
_ -> fetch_max_block_number()
end
end

defp fetch_max_block_number do
case BlockNumber.get_max() do
0 ->
json_rpc_named_arguments = Application.get_env(:indexer, :json_rpc_named_arguments)
{:ok, number} = EthereumJSONRPC.fetch_block_number_by_tag("latest", json_rpc_named_arguments)
number

number ->
number
end
end

Expand Down
9 changes: 9 additions & 0 deletions apps/indexer/test/indexer/block/catchup/fetcher_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ defmodule Indexer.Block.Catchup.FetcherTest do
end

describe "import/1" do
setup do
configuration = Application.get_env(:indexer, :last_block)
Application.put_env(:indexer, :last_block, "0")

on_exit(fn ->
Application.put_env(:indexer, :last_block, configuration)
end)
end

test "fetches uncles asynchronously", %{json_rpc_named_arguments: json_rpc_named_arguments} do
CoinBalance.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments)
InternalTransaction.Supervisor.Case.start_supervised!(json_rpc_named_arguments: json_rpc_named_arguments)
Expand Down

0 comments on commit 4d0e68a

Please sign in to comment.