Ignore logs of non-consensus blocks in Indexer.Fetcher.TransactionAction

pull/7712/head
POA 2 years ago
parent d28c77fee8
commit a35e7dffe6
  1. 15
      apps/indexer/lib/indexer/fetcher/transaction_action.ex

@ -15,7 +15,7 @@ defmodule Indexer.Fetcher.TransactionAction do
alias Explorer.{Chain, Repo} alias Explorer.{Chain, Repo}
alias Explorer.Helper, as: ExplorerHelper alias Explorer.Helper, as: ExplorerHelper
alias Explorer.Chain.{Log, TransactionAction} alias Explorer.Chain.{Block, Log, TransactionAction}
alias Indexer.Transform.{Addresses, TransactionActions} alias Indexer.Transform.{Addresses, TransactionActions}
@stage_first_block "tx_action_first_block" @stage_first_block "tx_action_first_block"
@ -87,8 +87,10 @@ defmodule Indexer.Fetcher.TransactionAction do
if reason === :normal do if reason === :normal do
{:noreply, %__MODULE__{state | task: nil}} {:noreply, %__MODULE__{state | task: nil}}
else else
logger_metadata = Logger.metadata()
Logger.metadata(fetcher: :transaction_action) Logger.metadata(fetcher: :transaction_action)
Logger.error(fn -> "Transaction action fetcher task exited due to #{inspect(reason)}. Rerunning..." end) Logger.error(fn -> "Transaction action fetcher task exited due to #{inspect(reason)}. Rerunning..." end)
Logger.reset_metadata(logger_metadata)
{:noreply, run_fetch(%__MODULE__{state | next_block: get_stage_block(@stage_next_block)})} {:noreply, run_fetch(%__MODULE__{state | next_block: get_stage_block(@stage_next_block)})}
end end
end end
@ -108,6 +110,7 @@ defmodule Indexer.Fetcher.TransactionAction do
pid: pid pid: pid
} = _state } = _state
) do ) do
logger_metadata = Logger.metadata()
Logger.metadata(fetcher: :transaction_action) Logger.metadata(fetcher: :transaction_action)
block_range = Range.new(next_block, first_block, -1) block_range = Range.new(next_block, first_block, -1)
@ -117,6 +120,8 @@ defmodule Indexer.Fetcher.TransactionAction do
query = query =
from( from(
log in Log, log in Log,
inner_join: b in Block,
on: b.hash == log.block_hash and b.consensus == true,
where: log.block_number == ^block_number, where: log.block_number == ^block_number,
select: log select: log
) )
@ -183,15 +188,19 @@ defmodule Indexer.Fetcher.TransactionAction do
Process.send(pid, :stop_server, []) Process.send(pid, :stop_server, [])
Logger.reset_metadata(logger_metadata)
:ok :ok
end end
defp init_fetching(opts, first_block, last_block) do defp init_fetching(opts, first_block, last_block) do
logger_metadata = Logger.metadata()
Logger.metadata(fetcher: :transaction_action) Logger.metadata(fetcher: :transaction_action)
first_block = ExplorerHelper.parse_integer(first_block) first_block = ExplorerHelper.parse_integer(first_block)
last_block = ExplorerHelper.parse_integer(last_block) last_block = ExplorerHelper.parse_integer(last_block)
return =
if is_nil(first_block) or is_nil(last_block) or first_block <= 0 or last_block <= 0 or first_block > last_block do if is_nil(first_block) or is_nil(last_block) or first_block <= 0 or last_block <= 0 or first_block > last_block do
{:stop, "Correct block range must be provided to #{__MODULE__}."} {:stop, "Correct block range must be provided to #{__MODULE__}."}
else else
@ -228,6 +237,10 @@ defmodule Indexer.Fetcher.TransactionAction do
{:ok, state} {:ok, state}
end end
Logger.reset_metadata(logger_metadata)
return
end end
defp get_next_block(first_block, last_block, protocols) do defp get_next_block(first_block, last_block, protocols) do

Loading…
Cancel
Save