limited usage of infinite timeout (#10551)

production-fuse
Alexander Kolotov 4 months ago committed by GitHub
parent 11e71b734d
commit a8c0c1ba92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 101
      apps/explorer/lib/explorer/chain/arbitrum/reader.ex
  2. 33
      apps/indexer/lib/indexer/fetcher/arbitrum/utils/db.ex

@ -40,7 +40,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
) )
query query
|> Repo.one() |> Repo.one(timeout: :infinity)
end end
@doc """ @doc """
@ -60,7 +60,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
) )
query query
|> Repo.one() |> Repo.one(timeout: :infinity)
end end
@doc """ @doc """
@ -86,7 +86,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
|> order_by(desc: :block_number) |> order_by(desc: :block_number)
|> limit(1) |> limit(1)
|> select([log], log.block_number) |> select([log], log.block_number)
|> Repo.one() |> Repo.one(timeout: :infinity)
end end
@doc """ @doc """
@ -107,7 +107,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
|> order_by(desc: :block_number) |> order_by(desc: :block_number)
|> limit(1) |> limit(1)
|> select([rollup_tx], rollup_tx.block_number) |> select([rollup_tx], rollup_tx.block_number)
|> Repo.one() |> Repo.one(timeout: :infinity)
end end
@doc """ @doc """
@ -132,7 +132,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
case query case query
# :required is used since the situation when commit transaction is not found is not possible # :required is used since the situation when commit transaction is not found is not possible
|> Chain.join_associations(%{:commitment_transaction => :required}) |> Chain.join_associations(%{:commitment_transaction => :required})
|> Repo.one() do |> Repo.one(timeout: :infinity) do
nil -> nil nil -> nil
batch -> batch.commitment_transaction.block_number batch -> batch.commitment_transaction.block_number
end end
@ -160,7 +160,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
case query case query
# :required is used since the situation when commit transaction is not found is not possible # :required is used since the situation when commit transaction is not found is not possible
|> Chain.join_associations(%{:commitment_transaction => :required}) |> Chain.join_associations(%{:commitment_transaction => :required})
|> Repo.one() do |> Repo.one(timeout: :infinity) do
nil -> nil nil -> nil
batch -> batch.commitment_transaction.block_number batch -> batch.commitment_transaction.block_number
end end
@ -205,7 +205,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
where: lt.hash in ^l1_tx_hashes where: lt.hash in ^l1_tx_hashes
) )
Repo.all(query, timeout: :infinity) Repo.all(query)
end end
@doc """ @doc """
@ -227,7 +227,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
where: lt.hash in ^l1_tx_hashes where: lt.hash in ^l1_tx_hashes
) )
Repo.all(query, timeout: :infinity) Repo.all(query)
end end
@doc """ @doc """
@ -253,7 +253,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
# :required is used since execution records in the table are created only when # :required is used since execution records in the table are created only when
# the corresponding execution transaction is indexed # the corresponding execution transaction is indexed
|> Chain.join_associations(%{:execution_transaction => :required}) |> Chain.join_associations(%{:execution_transaction => :required})
|> Repo.all(timeout: :infinity) |> Repo.all()
end end
@doc """ @doc """
@ -305,7 +305,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
where: lt.block_number <= ^finalized_block and lt.status == :unfinalized where: lt.block_number <= ^finalized_block and lt.status == :unfinalized
) )
Repo.all(query, timeout: :infinity) Repo.all(query)
end end
@doc """ @doc """
@ -357,7 +357,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
) )
query query
|> Repo.all(timeout: :infinity) |> Repo.all()
end end
@doc """ @doc """
@ -426,7 +426,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
case query case query
# :required is used since existence of the confirmation id is checked above # :required is used since existence of the confirmation id is checked above
|> Chain.join_associations(%{:confirmation_transaction => :required}) |> Chain.join_associations(%{:confirmation_transaction => :required})
|> Repo.one() do |> Repo.one(timeout: :infinity) do
nil -> nil ->
nil nil
@ -480,7 +480,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
) )
query query
|> Repo.one() |> Repo.one(timeout: :infinity)
end end
@doc """ @doc """
@ -502,7 +502,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
) )
query query
|> Repo.one() |> Repo.one(timeout: :infinity)
end end
@doc """ @doc """
@ -532,7 +532,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
order_by: [asc: rb.block_number] order_by: [asc: rb.block_number]
) )
Repo.all(query, timeout: :infinity) Repo.all(query)
end end
@doc """ @doc """
@ -553,7 +553,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
where: rb.batch_number == ^batch_number and not is_nil(rb.confirmation_id) where: rb.batch_number == ^batch_number and not is_nil(rb.confirmation_id)
) )
Repo.aggregate(query, :count, timeout: :infinity) Repo.aggregate(query, :count)
end end
@doc """ @doc """
@ -588,7 +588,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
order_by: [desc: msg.message_id] order_by: [desc: msg.message_id]
) )
Repo.all(query, timeout: :infinity) Repo.all(query)
end end
def l2_to_l1_messages(status, nil) when status in [:initiated, :sent, :confirmed, :relayed] do def l2_to_l1_messages(status, nil) when status in [:initiated, :sent, :confirmed, :relayed] do
@ -598,7 +598,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
order_by: [desc: msg.message_id] order_by: [desc: msg.message_id]
) )
Repo.all(query, timeout: :infinity) Repo.all(query)
end end
@doc """ @doc """
@ -704,7 +704,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
defp do_messages_count(direction, options) do defp do_messages_count(direction, options) do
Message Message
|> where([msg], msg.direction == ^direction) |> where([msg], msg.direction == ^direction)
|> select_repo(options).aggregate(:count, timeout: :infinity) |> select_repo(options).aggregate(:count)
end end
@doc """ @doc """
@ -1223,7 +1223,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
) )
query query
|> Repo.all(timeout: :infinity) |> Repo.all()
end end
@doc """ @doc """
@ -1248,7 +1248,7 @@ defmodule Explorer.Chain.Arbitrum.Reader do
) )
query query
|> Repo.all(timeout: :infinity) |> Repo.all()
|> Enum.reduce(%{}, fn {batch_number, l1_block_number}, acc -> |> Enum.reduce(%{}, fn {batch_number, l1_block_number}, acc ->
Map.put(acc, batch_number, l1_block_number) Map.put(acc, batch_number, l1_block_number)
end) end)
@ -1267,6 +1267,63 @@ defmodule Explorer.Chain.Arbitrum.Reader do
select: {min(batch.number), max(batch.number)} select: {min(batch.number), max(batch.number)}
) )
Repo.one(query) Repo.one(query, timeout: :infinity)
end
#####################################################################################
### Below are the functions that implement functionality not specific to Arbitrum ###
#####################################################################################
@doc """
Checks if a block with the given block number exists.
This function queries the database to determine if a block with the specified
block number exists and has been marked as having reached consensus.
## Parameters
- `block_number`: The number of the block to check.
## Returns
- `true` if the block exists and has reached consensus.
- `false` otherwise.
"""
@spec rollup_block_exists?(FullBlock.block_number()) :: boolean()
def rollup_block_exists?(block_number) do
query =
from(
block in FullBlock,
where: block.number == ^block_number and block.consensus == true
)
Repo.exists?(query, timeout: :infinity)
end
@doc """
Retrieves full details of rollup blocks, including associated transactions, for each
block number specified in the input list.
## Parameters
- `list_of_block_numbers`: A list of block numbers for which full block details are to be retrieved.
## Returns
- A list of `Explorer.Chain.Block` instances containing detailed information for each
block number in the input list. Returns an empty list if no blocks are found for the given numbers.
"""
@spec rollup_blocks([FullBlock.block_number()]) :: [FullBlock.t()]
def rollup_blocks(list_of_block_numbers)
def rollup_blocks([]), do: []
def rollup_blocks(list_of_block_numbers) do
query =
from(
block in FullBlock,
where: block.number in ^list_of_block_numbers
)
query
# :optional is used since a block may not have any transactions
|> Chain.join_associations(%{:transactions => :optional})
|> Repo.all()
end end
end end

@ -3,11 +3,9 @@ defmodule Indexer.Fetcher.Arbitrum.Utils.Db do
Common functions to simplify DB routines for Indexer.Fetcher.Arbitrum fetchers Common functions to simplify DB routines for Indexer.Fetcher.Arbitrum fetchers
""" """
import Ecto.Query, only: [from: 2]
import Indexer.Fetcher.Arbitrum.Utils.Logging, only: [log_warning: 1, log_info: 1] import Indexer.Fetcher.Arbitrum.Utils.Logging, only: [log_warning: 1, log_info: 1]
alias Explorer.{Chain, Repo} alias Explorer.Chain
alias Explorer.Chain.Arbitrum alias Explorer.Chain.Arbitrum
alias Explorer.Chain.Arbitrum.Reader alias Explorer.Chain.Arbitrum.Reader
alias Explorer.Chain.Block, as: FullBlock alias Explorer.Chain.Block, as: FullBlock
@ -388,8 +386,7 @@ defmodule Indexer.Fetcher.Arbitrum.Utils.Db do
end end
@doc """ @doc """
Retrieves full details of rollup blocks, including associated transactions, for each Retrieves full details of rollup blocks, including associated transactions, for each block number specified in the input list.
block number specified in the input list.
## Parameters ## Parameters
- `list_of_block_numbers`: A list of block numbers for which full block details are to be retrieved. - `list_of_block_numbers`: A list of block numbers for which full block details are to be retrieved.
@ -399,23 +396,7 @@ defmodule Indexer.Fetcher.Arbitrum.Utils.Db do
block number in the input list. Returns an empty list if no blocks are found for the given numbers. block number in the input list. Returns an empty list if no blocks are found for the given numbers.
""" """
@spec rollup_blocks([FullBlock.block_number()]) :: [FullBlock.t()] @spec rollup_blocks([FullBlock.block_number()]) :: [FullBlock.t()]
def rollup_blocks(list_of_block_numbers) def rollup_blocks(list_of_block_numbers), do: Reader.rollup_blocks(list_of_block_numbers)
def rollup_blocks([]), do: []
def rollup_blocks(list_of_block_numbers)
when is_list(list_of_block_numbers) do
query =
from(
block in FullBlock,
where: block.number in ^list_of_block_numbers
)
query
# :optional is used since a block may not have any transactions
|> Chain.join_associations(%{:transactions => :optional})
|> Repo.all(timeout: :infinity)
end
@doc """ @doc """
Retrieves unfinalized L1 transactions that are involved in changing the statuses Retrieves unfinalized L1 transactions that are involved in changing the statuses
@ -942,13 +923,7 @@ defmodule Indexer.Fetcher.Arbitrum.Utils.Db do
# the block just after it # the block just after it
rollup_tail = Application.get_all_env(:indexer)[:first_block] + 1 rollup_tail = Application.get_all_env(:indexer)[:first_block] + 1
query = Reader.rollup_block_exists?(rollup_tail)
from(
block in FullBlock,
where: block.number == ^rollup_tail and block.consensus == true
)
if(is_nil(query |> Repo.one()), do: false, else: true)
end end
@spec lifecycle_transaction_to_map(Arbitrum.LifecycleTransaction.t()) :: Arbitrum.LifecycleTransaction.to_import() @spec lifecycle_transaction_to_map(Arbitrum.LifecycleTransaction.t()) :: Arbitrum.LifecycleTransaction.to_import()

Loading…
Cancel
Save