|
|
@ -124,9 +124,14 @@ defmodule Indexer.Block.Realtime.Fetcher do |
|
|
|
new_previous_number = |
|
|
|
new_previous_number = |
|
|
|
case EthereumJSONRPC.fetch_block_number_by_tag("latest", json_rpc_named_arguments) do |
|
|
|
case EthereumJSONRPC.fetch_block_number_by_tag("latest", json_rpc_named_arguments) do |
|
|
|
{:ok, number} when is_nil(previous_number) or number != previous_number -> |
|
|
|
{:ok, number} when is_nil(previous_number) or number != previous_number -> |
|
|
|
start_fetch_and_import(number, block_fetcher, previous_number) |
|
|
|
if abnormal_gap?(number, previous_number) do |
|
|
|
|
|
|
|
new_number = max(number, previous_number) |
|
|
|
number |
|
|
|
start_fetch_and_import(new_number, block_fetcher, previous_number) |
|
|
|
|
|
|
|
new_number |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
start_fetch_and_import(number, block_fetcher, previous_number) |
|
|
|
|
|
|
|
number |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
_ -> |
|
|
|
_ -> |
|
|
|
previous_number |
|
|
|
previous_number |
|
|
@ -263,6 +268,15 @@ defmodule Indexer.Block.Realtime.Fetcher do |
|
|
|
|
|
|
|
|
|
|
|
defp reorg?(_, _), do: false |
|
|
|
defp reorg?(_, _), do: false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@default_max_gap 1000 |
|
|
|
|
|
|
|
defp abnormal_gap?(_number, nil), do: false |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defp abnormal_gap?(number, previous_number) do |
|
|
|
|
|
|
|
max_gap = Application.get_env(:indexer, __MODULE__)[:max_gap] || @default_max_gap |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abs(number - previous_number) > max_gap |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
@reorg_delay 5_000 |
|
|
|
@reorg_delay 5_000 |
|
|
|
|
|
|
|
|
|
|
|
@decorate trace(name: "fetch", resource: "Indexer.Block.Realtime.Fetcher.fetch_and_import_block/3", tracer: Tracer) |
|
|
|
@decorate trace(name: "fetch", resource: "Indexer.Block.Realtime.Fetcher.fetch_and_import_block/3", tracer: Tracer) |
|
|
|