fix: proper handling of old batches on Arbitrum Nova (#10786)

* AnyTrust old certificates support

* proper calculation the block range size

* don't exclude the block 0 from the boundaries search
pull/10805/head
Alexander Kolotov 1 month ago committed by GitHub
parent f0ef80be8d
commit e68090523c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 19
      apps/indexer/lib/indexer/fetcher/arbitrum/da/anytrust.ex
  2. 3
      apps/indexer/lib/indexer/fetcher/arbitrum/da/common.ex
  3. 4
      apps/indexer/lib/indexer/fetcher/arbitrum/utils/rpc.ex
  4. 23
      apps/indexer/lib/indexer/fetcher/arbitrum/workers/new_batches.ex

@ -124,6 +124,25 @@ defmodule Indexer.Fetcher.Arbitrum.DA.Anytrust do
}}
end
def parse_batch_accompanying_data(batch_number, <<
keyset_hash::binary-size(32),
data_hash::binary-size(32),
timeout::big-unsigned-integer-size(64),
signers_mask::big-unsigned-integer-size(64),
bls_signature::binary-size(96)
>>) do
# https://github.com/OffchainLabs/nitro/blob/ad9ab00723e13cf98307b9b65774ad455594ef7b/arbstate/das_reader.go#L95-L151
{:ok, :in_anytrust,
%__MODULE__{
batch_number: batch_number,
keyset_hash: keyset_hash,
data_hash: data_hash,
timeout: IndexerHelper.timestamp_to_datetime(timeout),
signers_mask: signers_mask,
bls_signature: bls_signature
}}
end
def parse_batch_accompanying_data(_, _) do
log_error("Can not parse Anytrust DA message.")
{:error, nil, nil}

@ -124,8 +124,7 @@ defmodule Indexer.Fetcher.Arbitrum.DA.Common do
{:error, nil, nil}
128 ->
log_error("DAS messages are not supported.")
{:error, nil, nil}
Anytrust.parse_batch_accompanying_data(batch_number, rest)
136 ->
Anytrust.parse_batch_accompanying_data(batch_number, rest)

@ -646,7 +646,9 @@ defmodule Indexer.Fetcher.Arbitrum.Utils.Rpc do
# inspected block is in the boundary of the required batch: the current batch is the same
# as one found in the previous iteration or the step is not the smallest possible.
next_block_to_inspect = max(1, inspected_block - new_step)
# it is OK to use the earliest block 0 as since the corresponding batch (0)
# will be returned by get_batch_number_for_rollup_block.
next_block_to_inspect = max(0, inspected_block - new_step)
do_binary_search_of_opposite_block(
next_block_to_inspect,

@ -1275,7 +1275,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
{nil, nil}
%Arbitrum.L1Batch{start_block: start_block, end_block: end_block} ->
{start_block - 1, div(end_block - start_block, 2)}
{start_block - 1, half_of_block_range(start_block, end_block, :descending)}
end
end
@ -1289,7 +1289,26 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
{nil, nil}
%Arbitrum.L1Batch{start_block: start_block, end_block: end_block} ->
{end_block + 1, div(start_block - end_block, 2)}
{end_block + 1, half_of_block_range(start_block, end_block, :ascending)}
end
end
# Calculates half the range between two block numbers, with direction adjustment.
#
# ## Parameters
# - `start_block`: The starting block number.
# - `end_block`: The ending block number.
# - `direction`: The direction of calculation, either `:ascending` or `:descending`.
#
# ## Returns
# - An integer representing half the block range, adjusted for direction:
# - For `:descending`, a positive integer >= 1.
# - For `:ascending`, a negative integer <= -1.
@spec half_of_block_range(non_neg_integer(), non_neg_integer(), :ascending | :descending) :: integer()
defp half_of_block_range(start_block, end_block, direction) do
case direction do
:descending -> max(div(end_block - start_block + 1, 2), 1)
:ascending -> min(div(start_block - end_block - 1, 2), -1)
end
end

Loading…
Cancel
Save