From 9dbf51db94e88563460a6ea0bf85bec92ef12132 Mon Sep 17 00:00:00 2001 From: goodsoft Date: Fri, 29 Mar 2019 16:34:14 +0200 Subject: [PATCH] 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. --- .../block/realtime/consensus_ensurer.ex | 34 ------------------- .../lib/indexer/block/realtime/fetcher.ex | 9 ++--- 2 files changed, 2 insertions(+), 41 deletions(-) delete mode 100644 apps/indexer/lib/indexer/block/realtime/consensus_ensurer.ex diff --git a/apps/indexer/lib/indexer/block/realtime/consensus_ensurer.ex b/apps/indexer/lib/indexer/block/realtime/consensus_ensurer.ex deleted file mode 100644 index 816f1d76bf..0000000000 --- a/apps/indexer/lib/indexer/block/realtime/consensus_ensurer.ex +++ /dev/null @@ -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 diff --git a/apps/indexer/lib/indexer/block/realtime/fetcher.ex b/apps/indexer/lib/indexer/block/realtime/fetcher.ex index 49787ad675..fe486f62c2 100644 --- a/apps/indexer/lib/indexer/block/realtime/fetcher.ex +++ b/apps/indexer/lib/indexer/block/realtime/fetcher.ex @@ -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}} ->