Remove obsolete ConsensusEnsurer

As a result of #1657 out-of-place parent blocks are marked as non-consensus
more reliably, i.e. they will eventually be fetched even if first attempt is
unsuccessful.

The `ConsensusEnsurer` module, on the contrary, only tried refetching block
once, and left it as-is if the refetch failed. Now it is not needed anymore.
pull/1684/head
goodsoft 6 years ago
parent bc61808344
commit 9dbf51db94
No known key found for this signature in database
GPG Key ID: DF5159A3A5F09D21
  1. 34
      apps/indexer/lib/indexer/block/realtime/consensus_ensurer.ex
  2. 9
      apps/indexer/lib/indexer/block/realtime/fetcher.ex

@ -1,34 +0,0 @@
defmodule Indexer.Block.Realtime.ConsensusEnsurer do
@moduledoc """
Triggers a refetch if a given block doesn't have consensus.
"""
require Logger
alias Explorer.Chain
alias Explorer.Chain.Hash
alias Indexer.Block.Realtime.Fetcher
def perform(_, number, _) when not is_integer(number) or number < 0, do: :ok
def perform(%Hash{byte_count: unquote(Hash.Full.byte_count())} = block_hash, number, block_fetcher) do
case Chain.hash_to_block(block_hash) do
{:ok, %{consensus: true} = _block} ->
:ignore
_ ->
Logger.info(fn ->
[
"refetch from consensus was found on block (",
to_string(number),
"). A reorg initiated."
]
end)
# trigger refetch if consensus=false or block was not found
Fetcher.fetch_and_import_block(number, block_fetcher, true)
end
:ok
end
end

@ -27,7 +27,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
alias Explorer.Chain.TokenTransfer
alias Explorer.Counters.AverageBlockTime
alias Indexer.{AddressExtraction, Block, TokenBalances, Tracer}
alias Indexer.Block.Realtime.{ConsensusEnsurer, TaskSupervisor}
alias Indexer.Block.Realtime.TaskSupervisor
alias Timex.Duration
@behaviour Block.Fetcher
@ -269,12 +269,7 @@ defmodule Indexer.Block.Realtime.Fetcher do
@decorate span(tracer: Tracer)
defp do_fetch_and_import_block(block_number_to_fetch, block_fetcher, retry) do
case fetch_and_import_range(block_fetcher, block_number_to_fetch..block_number_to_fetch) do
{:ok, %{inserted: inserted, errors: []}} ->
for block <- Map.get(inserted, :blocks, []) do
args = [block.parent_hash, block.number - 1, block_fetcher]
Task.Supervisor.start_child(TaskSupervisor, ConsensusEnsurer, :perform, args)
end
{:ok, %{inserted: _, errors: []}} ->
Logger.debug("Fetched and imported.")
{:ok, %{inserted: _, errors: [_ | _] = errors}} ->

Loading…
Cancel
Save