|
|
@ -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,51 +188,59 @@ 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) |
|
|
|
|
|
|
|
|
|
|
|
if is_nil(first_block) or is_nil(last_block) or first_block <= 0 or last_block <= 0 or first_block > last_block do |
|
|
|
return = |
|
|
|
{:stop, "Correct block range must be provided to #{__MODULE__}."} |
|
|
|
if is_nil(first_block) or is_nil(last_block) or first_block <= 0 or last_block <= 0 or first_block > last_block do |
|
|
|
else |
|
|
|
{:stop, "Correct block range must be provided to #{__MODULE__}."} |
|
|
|
max_block_number = Chain.fetch_max_block_number() |
|
|
|
else |
|
|
|
|
|
|
|
max_block_number = Chain.fetch_max_block_number() |
|
|
|
if last_block > max_block_number do |
|
|
|
|
|
|
|
Logger.warning( |
|
|
|
if last_block > max_block_number do |
|
|
|
"Note, that the last block number (#{last_block}) provided to #{__MODULE__} exceeds max block number available in DB (#{max_block_number})." |
|
|
|
Logger.warning( |
|
|
|
) |
|
|
|
"Note, that the last block number (#{last_block}) provided to #{__MODULE__} exceeds max block number available in DB (#{max_block_number})." |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
supported_protocols = |
|
|
|
|
|
|
|
TransactionAction.supported_protocols() |
|
|
|
|
|
|
|
|> Enum.map(&Atom.to_string(&1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protocols = |
|
|
|
|
|
|
|
opts |
|
|
|
|
|
|
|
|> Keyword.get(:reindex_protocols, "") |
|
|
|
|
|
|
|
|> String.trim() |
|
|
|
|
|
|
|
|> String.split(",") |
|
|
|
|
|
|
|
|> Enum.map(&String.trim(&1)) |
|
|
|
|
|
|
|
|> Enum.filter(&Enum.member?(supported_protocols, &1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_block = get_next_block(first_block, last_block, protocols) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state = |
|
|
|
|
|
|
|
%__MODULE__{ |
|
|
|
|
|
|
|
first_block: first_block, |
|
|
|
|
|
|
|
next_block: next_block, |
|
|
|
|
|
|
|
last_block: last_block, |
|
|
|
|
|
|
|
protocols: protocols |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|> run_fetch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, state} |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
supported_protocols = |
|
|
|
Logger.reset_metadata(logger_metadata) |
|
|
|
TransactionAction.supported_protocols() |
|
|
|
|
|
|
|
|> Enum.map(&Atom.to_string(&1)) |
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
protocols = |
|
|
|
|
|
|
|
opts |
|
|
|
|
|
|
|
|> Keyword.get(:reindex_protocols, "") |
|
|
|
|
|
|
|
|> String.trim() |
|
|
|
|
|
|
|
|> String.split(",") |
|
|
|
|
|
|
|
|> Enum.map(&String.trim(&1)) |
|
|
|
|
|
|
|
|> Enum.filter(&Enum.member?(supported_protocols, &1)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
next_block = get_next_block(first_block, last_block, protocols) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state = |
|
|
|
|
|
|
|
%__MODULE__{ |
|
|
|
|
|
|
|
first_block: first_block, |
|
|
|
|
|
|
|
next_block: next_block, |
|
|
|
|
|
|
|
last_block: last_block, |
|
|
|
|
|
|
|
protocols: protocols |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|> run_fetch() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{:ok, state} |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
defp get_next_block(first_block, last_block, protocols) do |
|
|
|
defp get_next_block(first_block, last_block, protocols) do |
|
|
|