Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/lib/explorer/skipped_blocks.ex

27 lines
783 B

defmodule Explorer.SkippedBlocks do
@moduledoc """
Fill in older blocks that were skipped during processing.
"""
import Ecto.Query, only: [from: 2, limit: 2]
alias Explorer.Block
alias Explorer.Repo.NewRelic, as: Repo
@missing "SELECT generate_series(?, 0, -1) AS missing_number"
def first, do: first(1)
def first(count) do
blocks = from b in Block,
right_join: missing_number in fragment(@missing, ^latest_block_number()),
on: b.number == fragment("missing_number"),
limit: ^count,
where: is_nil(b.id),
select: fragment("missing_number")
Repo.all(blocks) |> Enum.map(&Integer.to_string/1)
end
def latest_block_number do
block = Repo.one(Block |> Block.latest |> limit(1)) || Block.null
block.number
end
end