fix: filter out incorrect L1-to-L2 Arbitrum messages (#10570)

vb-nft-collection-trigger-metadata-refetch-admin-api-endpoint
Alexander Kolotov 4 months ago committed by GitHub
parent 259a143c4f
commit a13d43f0a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 15
      apps/explorer/lib/explorer/chain/arbitrum/reader.ex
  2. 14
      apps/indexer/lib/indexer/fetcher/arbitrum/messaging.ex
  3. 2
      apps/indexer/lib/indexer/fetcher/arbitrum/workers/historical_messages_on_l2.ex

@ -21,7 +21,11 @@ defmodule Explorer.Chain.Arbitrum.Reader do
alias Explorer.Chain.Block, as: FullBlock
alias Explorer.Chain.{Hash, Log, Transaction}
@to_l2_messages_transaction_types [100, 105]
# https://github.com/OffchainLabs/go-ethereum/blob/dff302de66598c36b964b971f72d35a95148e650/core/types/transaction.go#L44C2-L50
@message_to_l2_eth_deposit 100
@message_to_l2_submit_retryable_tx 105
@zero_wei 0
@doc """
Retrieves the number of the latest L1 block where an L1-to-L2 message was discovered.
@ -834,6 +838,10 @@ defmodule Explorer.Chain.Arbitrum.Reader do
# table. A message is considered missed if there is a transaction without a
# matching message record.
#
# For transactions that could be considered ETH deposits, it checks
# that the message value is not zero, as transactions with a zero value
# cannot be a deposit.
#
# ## Returns
# - A query to retrieve missed L1-to-L2 messages.
@spec missed_messages_to_l2_query() :: Ecto.Query.t()
@ -841,7 +849,10 @@ defmodule Explorer.Chain.Arbitrum.Reader do
from(rollup_tx in Transaction,
left_join: msg in Message,
on: rollup_tx.hash == msg.completion_transaction_hash and msg.direction == :to_l2,
where: rollup_tx.type in @to_l2_messages_transaction_types and is_nil(msg.completion_transaction_hash)
where:
(rollup_tx.type == ^@message_to_l2_submit_retryable_tx or
(rollup_tx.type == ^@message_to_l2_eth_deposit and rollup_tx.value != ^@zero_wei)) and
is_nil(msg.completion_transaction_hash)
)
end

@ -62,10 +62,10 @@ defmodule Indexer.Fetcher.Arbitrum.Messaging do
@doc """
Filters a list of rollup transactions to identify L1-to-L2 messages and composes a map for each with the related message information.
This function filters through a list of rollup transactions, selecting those
with a non-nil `request_id`, indicating they are L1-to-L2 message completions.
These filtered transactions are then processed to construct a detailed message
structure for each.
This function filters a list of rollup transactions, selecting those where
`request_id` is not nil and is below 2^31, indicating they are L1-to-L2
message completions. These filtered transactions are then processed to
construct a detailed message structure for each.
## Parameters
- `transactions`: A list of rollup transaction entries.
@ -78,14 +78,14 @@ defmodule Indexer.Fetcher.Arbitrum.Messaging do
this context are considered `:relayed` as they represent completed actions from
L1 to L2.
"""
@spec filter_l1_to_l2_messages(maybe_improper_list(min_transaction, [])) :: [arbitrum_message]
@spec filter_l1_to_l2_messages(maybe_improper_list(min_transaction, []), boolean()) :: [arbitrum_message]
@spec filter_l1_to_l2_messages([min_transaction()]) :: [arbitrum_message]
@spec filter_l1_to_l2_messages([min_transaction()], boolean()) :: [arbitrum_message]
def filter_l1_to_l2_messages(transactions, report \\ true)
when is_list(transactions) and is_boolean(report) do
messages =
transactions
|> Enum.filter(fn tx ->
tx[:request_id] != nil
tx[:request_id] != nil and Bitwise.bsr(tx[:request_id], 31) == 0
end)
|> handle_filtered_l1_to_l2_messages()

@ -273,6 +273,8 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.HistoricalMessagesOnL2 do
messages ++ messages_acc
end)
# Logging of zero messages is left by intent to reveal potential cases when
# not all transactions are recognized as completed L1-to-L2 messages.
log_info("#{length(messages)} completions of L1-to-L2 messages will be imported")
import_to_db(messages)
end

Loading…
Cancel
Save