@ -7,12 +7,13 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
being created and historical batches processed in the past but not yet imported
being created and historical batches processed in the past but not yet imported
into the database .
into the database .
The process involves fetching logs for the ` SequencerBatchDelivered ` event
Fetch logs for the ` SequencerBatchDelivered ` event emitted by the Arbitrum
emitted by the Arbitrum ` SequencerInbox ` contract , processing these logs to
` SequencerInbox ` contract . Process the logs to extract batch details . Build the
extract batch details , and then building the link between batches and the
link between batches and the corresponding rollup blocks and transactions . If
corresponding rollup blocks and transactions . It also discovers those
the batch data is located in Data Availability solutions like AnyTrust or
cross - chain messages initiated in rollup blocks linked with the new batches
Celestia , fetch DA information to locate the batch data . Discover cross - chain
and updates the status of messages to consider them as committed ( ` :sent ` ) .
messages initiated in rollup blocks linked with the new batches and update the
status of messages to consider them as committed ( ` :sent ` ) .
For any blocks or transactions missing in the database , data is requested in
For any blocks or transactions missing in the database , data is requested in
chunks from the rollup RPC endpoint by ` eth_getBlockByNumber ` . Additionally ,
chunks from the rollup RPC endpoint by ` eth_getBlockByNumber ` . Additionally ,
@ -29,8 +30,10 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
alias EthereumJSONRPC.Block.ByNumber , as : BlockByNumber
alias EthereumJSONRPC.Block.ByNumber , as : BlockByNumber
alias Indexer.Helper , as : IndexerHelper
alias Indexer.Fetcher.Arbitrum.DA.Common , as : DataAvailabilityInfo
alias Indexer.Fetcher.Arbitrum.DA . { Anytrust , Celestia }
alias Indexer.Fetcher.Arbitrum.Utils . { Db , Logging , Rpc }
alias Indexer.Fetcher.Arbitrum.Utils . { Db , Logging , Rpc }
alias Indexer.Helper , as : IndexerHelper
alias Explorer.Chain
alias Explorer.Chain
alias Explorer.Chain.Arbitrum
alias Explorer.Chain.Arbitrum
@ -292,25 +295,44 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# Performs the discovery of new or historical batches within a specified block range,
# Performs the discovery of new or historical batches within a specified block range,
# processing and importing the relevant data into the database.
# processing and importing the relevant data into the database.
#
#
# This function retrieves SequencerBatchDelivered event logs from the specified block range
# This function retrieves SequencerBatchDelivered event logs from the specified block
# and processes these logs to identify new batches and their corresponding details. It then
# range and processes these logs to identify new batches and their corresponding details.
# constructs comprehensive data structures for batches, lifecycle transactions, rollup
# It then constructs comprehensive data structures for batches, lifecycle transactions,
# blocks, and rollup transactions. Additionally, it identifies any L2-to-L1 messages that
# rollup blocks, rollup transactions, and Data Availability related records. Additionally,
# have been committed within these batches and updates their status. All discovered and
# it identifies any L2-to-L1 messages that have been committed within these batches and
# processed data are then imported into the database. If new batches were found, they are
# updates their status. All discovered and processed data are then imported into the
# announced to be broadcasted through a websocket.
# database. If new batches were found, they are announced to be broadcasted through a
# websocket.
#
#
# ## Parameters
# ## Parameters
# - `sequencer_inbox_address`: The SequencerInbox contract address used to filter logs.
# - `sequencer_inbox_address`: The SequencerInbox contract address used to filter logs.
# - `start_block`: The starting block number for the discovery range.
# - `start_block`: The starting block number for the discovery range.
# - `end_block`: The ending block number for the discovery range.
# - `end_block`: The ending block number for the discovery range.
# - `new_batches_limit`: The maximum number of new batches to process in one iteration.
# - `new_batches_limit`: The maximum number of new batches to process in one iteration.
# - `messages_to_blocks_shift`: The value used to align message counts with rollup block numbers.
# - `messages_to_blocks_shift`: The value used to align message counts with rollup block
# numbers.
# - `l1_rpc_config`: RPC configuration parameters for L1.
# - `l1_rpc_config`: RPC configuration parameters for L1.
# - `rollup_rpc_config`: RPC configuration parameters for rollup data.
# - `rollup_rpc_config`: RPC configuration parameters for rollup data.
#
#
# ## Returns
# ## Returns
# - N/A
# - N/A
@spec do_discover (
binary ( ) ,
non_neg_integer ( ) ,
non_neg_integer ( ) ,
non_neg_integer ( ) ,
non_neg_integer ( ) ,
%{
:json_rpc_named_arguments = > EthereumJSONRPC . json_rpc_named_arguments ( ) ,
:chunk_size = > non_neg_integer ( ) ,
optional ( any ( ) ) = > any ( )
} ,
%{
:json_rpc_named_arguments = > EthereumJSONRPC . json_rpc_named_arguments ( ) ,
:chunk_size = > non_neg_integer ( ) ,
optional ( any ( ) ) = > any ( )
}
) :: :ok
defp do_discover (
defp do_discover (
sequencer_inbox_address ,
sequencer_inbox_address ,
start_block ,
start_block ,
@ -344,11 +366,12 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
logs
logs
|> Enum . chunk_every ( new_batches_limit )
|> Enum . chunk_every ( new_batches_limit )
|> Enum . each ( fn chunked_logs ->
|> Enum . each ( fn chunked_logs ->
{ batches , lifecycle_txs , rollup_blocks , rollup_txs , committed_txs } =
{ batches , lifecycle_txs , rollup_blocks , rollup_txs , committed_txs , da_records } =
handle_batches_from_logs (
handle_batches_from_logs (
chunked_logs ,
chunked_logs ,
messages_to_blocks_shift ,
messages_to_blocks_shift ,
l1_rpc_config ,
l1_rpc_config ,
sequencer_inbox_address ,
rollup_rpc_config
rollup_rpc_config
)
)
@ -359,6 +382,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
arbitrum_batch_blocks : %{ params : rollup_blocks } ,
arbitrum_batch_blocks : %{ params : rollup_blocks } ,
arbitrum_batch_transactions : %{ params : rollup_txs } ,
arbitrum_batch_transactions : %{ params : rollup_txs } ,
arbitrum_messages : %{ params : committed_txs } ,
arbitrum_messages : %{ params : committed_txs } ,
arbitrum_da_multi_purpose_records : %{ params : da_records } ,
timeout : :infinity
timeout : :infinity
} )
} )
@ -384,6 +408,8 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
#
#
# ## Returns
# ## Returns
# - A list of logs for SequencerBatchDelivered events within the specified block range.
# - A list of logs for SequencerBatchDelivered events within the specified block range.
@spec get_logs_new_batches ( non_neg_integer ( ) , non_neg_integer ( ) , binary ( ) , EthereumJSONRPC . json_rpc_named_arguments ( ) ) ::
[ %{ String . t ( ) = > any ( ) } ]
defp get_logs_new_batches ( start_block , end_block , sequencer_inbox_address , json_rpc_named_arguments )
defp get_logs_new_batches ( start_block , end_block , sequencer_inbox_address , json_rpc_named_arguments )
when start_block <= end_block do
when start_block <= end_block do
{ :ok , logs } =
{ :ok , logs } =
@ -408,21 +434,23 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# and retrieves their details, avoiding the reprocessing of batches already known
# and retrieves their details, avoiding the reprocessing of batches already known
# in the database. It enriches the details of new batches with data from corresponding
# in the database. It enriches the details of new batches with data from corresponding
# L1 transactions and blocks, including timestamps and block ranges. The function
# L1 transactions and blocks, including timestamps and block ranges. The function
# then prepares batches, associated rollup blocks and transactions, and lifecycle
# then prepares batches, associated rollup blocks and transactions, lifecycle
# transactions for database import. Additionally, L2-to-L1 messages initiated in the
# transactions and Data Availability related records for database import.
# rollup blocks associated with the discovered batches are retrieved from the database,
# Additionally, L2-to-L1 messages initiated in the rollup blocks associated with the
# marked as `:sent`, and prepared for database import.
# discovered batches are retrieved from the database, marked as `:sent`, and prepared
# for database import.
#
#
# ## Parameters
# ## Parameters
# - `logs`: The list of SequencerBatchDelivered event logs.
# - `logs`: The list of SequencerBatchDelivered event logs.
# - `msg_to_block_shift`: The shift value for mapping batch messages to block numbers.
# - `msg_to_block_shift`: The shift value for mapping batch messages to block numbers.
# - `l1_rpc_config`: The RPC configuration for L1 requests.
# - `l1_rpc_config`: The RPC configuration for L1 requests.
# - `sequencer_inbox_address`: The address of the SequencerInbox contract.
# - `rollup_rpc_config`: The RPC configuration for rollup data requests.
# - `rollup_rpc_config`: The RPC configuration for rollup data requests.
#
#
# ## Returns
# ## Returns
# - A tuple containing lists of batches, lifecycle transactions, rollup blocks,
# - A tuple containing lists of batches, lifecycle transactions, rollup blocks,
# rollup transactions, and committed messages (with the status `:sent`), all
# rollup transactions, committed messages (with the status `:sent`), and records
# ready for database import.
# with DA-related information if applicable, all ready for database import.
@spec handle_batches_from_logs (
@spec handle_batches_from_logs (
[ %{ String . t ( ) = > any ( ) } ] ,
[ %{ String . t ( ) = > any ( ) } ] ,
non_neg_integer ( ) ,
non_neg_integer ( ) ,
@ -431,21 +459,19 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
:chunk_size = > non_neg_integer ( ) ,
:chunk_size = > non_neg_integer ( ) ,
optional ( any ( ) ) = > any ( )
optional ( any ( ) ) = > any ( )
} ,
} ,
binary ( ) ,
%{
%{
:json_rpc_named_arguments = > EthereumJSONRPC . json_rpc_named_arguments ( ) ,
:json_rpc_named_arguments = > EthereumJSONRPC . json_rpc_named_arguments ( ) ,
:chunk_size = > non_neg_integer ( ) ,
:chunk_size = > non_neg_integer ( ) ,
optional ( any ( ) ) = > any ( )
optional ( any ( ) ) = > any ( )
}
}
) :: {
) ::
[ Arbitrum.L1Batch . to_import ( ) ] ,
{ [ Arbitrum.L1Batch . to_import ( ) ] , [ Arbitrum.LifecycleTransaction . to_import ( ) ] ,
[ Arbitrum.LifecycleTransaction . to_import ( ) ] ,
[ Arbitrum.BatchBlock . to_import ( ) ] , [ Arbitrum.BatchTransaction . to_import ( ) ] , [ Arbitrum.Message . to_import ( ) ] ,
[ Arbitrum.BatchBlock . to_import ( ) ] ,
[ Arbitrum.DaMultiPurposeRecord . to_import ( ) ] }
[ Arbitrum.BatchTransaction . to_import ( ) ] ,
defp handle_batches_from_logs ( logs , msg_to_block_shift , l1_rpc_config , sequencer_inbox_address , rollup_rpc_config )
[ Arbitrum.Message . to_import ( ) ]
}
defp handle_batches_from_logs ( logs , msg_to_block_shift , l1_rpc_config , rollup_rpc_config )
defp handle_batches_from_logs ( [ ] , _ , _ , _ ) , do : { [ ] , [ ] , [ ] , [ ] , [ ] }
defp handle_batches_from_logs ( [ ] , _ , _ , _ , _ ) , do : { [ ] , [ ] , [ ] , [ ] , [ ] , [ ] }
defp handle_batches_from_logs (
defp handle_batches_from_logs (
logs ,
logs ,
@ -454,6 +480,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
json_rpc_named_arguments : json_rpc_named_arguments ,
json_rpc_named_arguments : json_rpc_named_arguments ,
chunk_size : chunk_size
chunk_size : chunk_size
} = l1_rpc_config ,
} = l1_rpc_config ,
sequencer_inbox_address ,
rollup_rpc_config
rollup_rpc_config
) do
) do
existing_batches =
existing_batches =
@ -466,7 +493,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
blocks_to_ts = Rpc . execute_blocks_requests_and_get_ts ( blocks_requests , json_rpc_named_arguments , chunk_size )
blocks_to_ts = Rpc . execute_blocks_requests_and_get_ts ( blocks_requests , json_rpc_named_arguments , chunk_size )
{ initial_lifecycle_txs , batches_to_import } =
{ initial_lifecycle_txs , batches_to_import , da_info } =
execute_tx_requests_parse_txs_calldata ( txs_requests , msg_to_block_shift , blocks_to_ts , batches , l1_rpc_config )
execute_tx_requests_parse_txs_calldata ( txs_requests , msg_to_block_shift , blocks_to_ts , batches , l1_rpc_config )
# Check if the commitment transactions for the batches which are already in the database
# Check if the commitment transactions for the batches which are already in the database
@ -502,6 +529,12 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
]
]
end )
end )
da_records =
DataAvailabilityInfo . prepare_for_import ( da_info , %{
sequencer_inbox_address : sequencer_inbox_address ,
json_rpc_named_arguments : l1_rpc_config . json_rpc_named_arguments
} )
# It is safe to not re-mark messages as committed for the batches that are already in the database
# It is safe to not re-mark messages as committed for the batches that are already in the database
committed_messages =
committed_messages =
if Enum . empty? ( blocks_to_import ) do
if Enum . empty? ( blocks_to_import ) do
@ -515,10 +548,11 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
end
end
{ batches_list_to_import , Map . values ( lifecycle_txs ) , Map . values ( blocks_to_import ) , rollup_txs_to_import ,
{ batches_list_to_import , Map . values ( lifecycle_txs ) , Map . values ( blocks_to_import ) , rollup_txs_to_import ,
committed_messages }
committed_messages , da_records }
end
end
# Extracts batch numbers from logs of SequencerBatchDelivered events.
# Extracts batch numbers from logs of SequencerBatchDelivered events.
@spec parse_logs_to_get_batch_numbers ( [ %{ String . t ( ) = > any ( ) } ] ) :: [ non_neg_integer ( ) ]
defp parse_logs_to_get_batch_numbers ( logs ) do
defp parse_logs_to_get_batch_numbers ( logs ) do
logs
logs
|> Enum . map ( fn event ->
|> Enum . map ( fn event ->
@ -554,7 +588,14 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
[ %{ String . t ( ) = > any ( ) } ] ,
[ %{ String . t ( ) = > any ( ) } ] ,
[ non_neg_integer ( ) ]
[ non_neg_integer ( ) ]
) :: {
) :: {
%{ :number = > non_neg_integer ( ) , :before_acc = > binary ( ) , :after_acc = > binary ( ) , :tx_hash = > binary ( ) } ,
%{
non_neg_integer ( ) = > %{
:number = > non_neg_integer ( ) ,
:before_acc = > binary ( ) ,
:after_acc = > binary ( ) ,
:tx_hash = > binary ( )
}
} ,
[ EthereumJSONRPC.Transport . request ( ) ] ,
[ EthereumJSONRPC.Transport . request ( ) ] ,
[ EthereumJSONRPC.Transport . request ( ) ] ,
[ EthereumJSONRPC.Transport . request ( ) ] ,
%{ binary ( ) = > non_neg_integer ( ) }
%{ binary ( ) = > non_neg_integer ( ) }
@ -611,6 +652,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
end
end
# Parses SequencerBatchDelivered event to get batch sequence number and associated accumulators
# Parses SequencerBatchDelivered event to get batch sequence number and associated accumulators
@spec sequencer_batch_delivered_event_parse ( %{ String . t ( ) = > any ( ) } ) :: { non_neg_integer ( ) , binary ( ) , binary ( ) }
defp sequencer_batch_delivered_event_parse ( event ) do
defp sequencer_batch_delivered_event_parse ( event ) do
[ _ , batch_sequence_number , before_acc , after_acc ] = event [ " topics " ]
[ _ , batch_sequence_number , before_acc , after_acc ] = event [ " topics " ]
@ -622,7 +664,9 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# This function processes a list of RPC `eth_getTransactionByHash` requests, extracts
# This function processes a list of RPC `eth_getTransactionByHash` requests, extracts
# and decodes the calldata from the transactions to obtain batch details. It updates
# and decodes the calldata from the transactions to obtain batch details. It updates
# the provided batch map with block ranges for new batches and constructs a map of
# the provided batch map with block ranges for new batches and constructs a map of
# lifecycle transactions with their timestamps and finalization status.
# lifecycle transactions with their timestamps and finalization status. Additionally,
# it examines the data availability (DA) information for Anytrust or Celestia and
# constructs a list of DA info structs.
#
#
# ## Parameters
# ## Parameters
# - `txs_requests`: The list of RPC requests to fetch transaction data.
# - `txs_requests`: The list of RPC requests to fetch transaction data.
@ -631,15 +675,46 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# - `blocks_to_ts`: A map of block numbers to their timestamps, required to complete
# - `blocks_to_ts`: A map of block numbers to their timestamps, required to complete
# data for corresponding lifecycle transactions.
# data for corresponding lifecycle transactions.
# - `batches`: The current batch data to be updated.
# - `batches`: The current batch data to be updated.
# - A configuration map containing JSON RPC arguments, a track finalization flag,
# - A configuration map containing:
# and a chunk size for batch processing.
# - `json_rpc_named_arguments`: Configuration parameters for the JSON RPC connection.
# - `track_finalization`: A boolean flag indicating if finalization tracking is needed.
# - `chunk_size`: The size of chunks for batch processing.
#
#
# ## Returns
# ## Returns
# - A tuple containing:
# - A tuple containing:
# - A map of lifecycle (L1) transactions, which are not yet compatible with
# - A map of lifecycle (L1) transactions, including their hashes, block numbers,
# database import and require further processing.
# timestamps, and statuses (finalized or unfinalized).
# - An updated map of batch descriptions, also requiring further processing
# - An updated map of batch descriptions with block ranges and data availability
# before database import.
# information.
# - A list of data availability information structs for Anytrust or Celestia.
@spec execute_tx_requests_parse_txs_calldata (
[ EthereumJSONRPC.Transport . request ( ) ] ,
non_neg_integer ( ) ,
%{ EthereumJSONRPC . block_number ( ) = > DateTime . t ( ) } ,
%{ non_neg_integer ( ) = > map ( ) } ,
%{
:chunk_size = > non_neg_integer ( ) ,
:json_rpc_named_arguments = > EthereumJSONRPC . json_rpc_named_arguments ( ) ,
:track_finalization = > boolean ( ) ,
optional ( any ( ) ) = > any ( )
}
) ::
{ %{
binary ( ) = > %{
:hash = > binary ( ) ,
:block_number = > non_neg_integer ( ) ,
:timestamp = > DateTime . t ( ) ,
:status = > :unfinalized | :finalized
}
} ,
%{
non_neg_integer ( ) = > %{
:start_block = > non_neg_integer ( ) ,
:end_block = > non_neg_integer ( ) ,
:data_available = > atom ( ) | nil ,
optional ( any ( ) ) = > any ( )
}
} , [ Anytrust . t ( ) | Celestia . t ( ) ] }
defp execute_tx_requests_parse_txs_calldata ( txs_requests , msg_to_block_shift , blocks_to_ts , batches , %{
defp execute_tx_requests_parse_txs_calldata ( txs_requests , msg_to_block_shift , blocks_to_ts , batches , %{
json_rpc_named_arguments : json_rpc_named_arguments ,
json_rpc_named_arguments : json_rpc_named_arguments ,
track_finalization : track_finalization? ,
track_finalization : track_finalization? ,
@ -647,20 +722,26 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
} ) do
} ) do
txs_requests
txs_requests
|> Enum . chunk_every ( chunk_size )
|> Enum . chunk_every ( chunk_size )
|> Enum . reduce ( { %{ } , batches } , fn chunk , { l1_txs , updated_batches } ->
|> Enum . reduce ( { %{ } , batches , [ ] } , fn chunk , { l1_txs , updated_batches , da_info } ->
chunk
chunk
# each eth_getTransactionByHash will take time since it returns entire batch
# each eth_getTransactionByHash will take time since it returns entire batch
# in `input` which is heavy because contains dozens of rollup blocks
# in `input` which is heavy because contains dozens of rollup blocks
|> Rpc . make_chunked_request ( json_rpc_named_arguments , " eth_getTransactionByHash " )
|> Rpc . make_chunked_request ( json_rpc_named_arguments , " eth_getTransactionByHash " )
|> Enum . reduce ( { l1_txs , updated_batches } , fn resp , { txs_map , batches_map } ->
|> Enum . reduce ( { l1_txs , updated_batches , da_info } , fn resp , { txs_map , batches_map , da_info_list } ->
block_num = quantity_to_integer ( resp [ " blockNumber " ] )
block_num = quantity_to_integer ( resp [ " blockNumber " ] )
tx_hash = Rpc . string_hash_to_bytes_hash ( resp [ " hash " ] )
tx_hash = Rpc . string_hash_to_bytes_hash ( resp [ " hash " ] )
# Although they are called messages in the functions' ABI, in fact they are
# Although they are called messages in the functions' ABI, in fact they are
# rollup blocks
# rollup blocks
{ batch_num , prev_message_count , new_message_count } =
{ batch_num , prev_message_count , new_message_count , extra_data } =
add_sequencer_l2_batch_from_origin_calldata_parse ( resp [ " input " ] )
add_sequencer_l2_batch_from_origin_calldata_parse ( resp [ " input " ] )
{ da_type , da_data } =
case DataAvailabilityInfo . examine_batch_accompanying_data ( batch_num , extra_data ) do
{ :ok , t , d } -> { t , d }
{ :error , _ , _ } -> { nil , nil }
end
# In some cases extracted numbers for messages does not linked directly
# In some cases extracted numbers for messages does not linked directly
# with rollup blocks, for this, the numbers are shifted by a value specific
# with rollup blocks, for this, the numbers are shifted by a value specific
# for particular rollup
# for particular rollup
@ -670,7 +751,8 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
batch_num ,
batch_num ,
Map . merge ( batches_map [ batch_num ] , %{
Map . merge ( batches_map [ batch_num ] , %{
start_block : prev_message_count + msg_to_block_shift ,
start_block : prev_message_count + msg_to_block_shift ,
end_block : new_message_count + msg_to_block_shift - 1
end_block : new_message_count + msg_to_block_shift - 1 ,
batch_container : da_type
} )
} )
)
)
@ -687,18 +769,28 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
end
end
} )
} )
{ updated_txs_map , updated_batches_map }
# credo:disable-for-lines:6 Credo.Check.Refactor.Nesting
updated_da_info_list =
if DataAvailabilityInfo . required_import? ( da_type ) do
[ da_data | da_info_list ]
else
da_info_list
end
{ updated_txs_map , updated_batches_map , updated_da_info_list }
end )
end )
end )
end )
end
end
# Parses calldata of `addSequencerL2BatchFromOrigin` or `addSequencerL2BatchFromBlobs`
# Parses calldata of `addSequencerL2BatchFromOrigin` or `addSequencerL2BatchFromBlobs`
# functions to extract batch information.
# functions to extract batch information.
@spec add_sequencer_l2_batch_from_origin_calldata_parse ( binary ( ) ) ::
{ non_neg_integer ( ) , non_neg_integer ( ) , non_neg_integer ( ) , binary ( ) | nil }
defp add_sequencer_l2_batch_from_origin_calldata_parse ( calldata ) do
defp add_sequencer_l2_batch_from_origin_calldata_parse ( calldata ) do
case calldata do
case calldata do
" 0x8f111f3c " <> encoded_params ->
" 0x8f111f3c " <> encoded_params ->
# addSequencerL2BatchFromOrigin(uint256 sequenceNumber, bytes calldata data, uint256 afterDelayedMessagesRead, address gasRefunder, uint256 prevMessageCount, uint256 newMessageCount)
# addSequencerL2BatchFromOrigin(uint256 sequenceNumber, bytes calldata data, uint256 afterDelayedMessagesRead, address gasRefunder, uint256 prevMessageCount, uint256 newMessageCount)
[ sequence_number , _ data, _after_delayed_messages_read , _gas_refunder , prev_message_count , new_message_count ] =
[ sequence_number , data , _after_delayed_messages_read , _gas_refunder , prev_message_count , new_message_count ] =
TypeDecoder . decode (
TypeDecoder . decode (
Base . decode16! ( encoded_params , case : :lower ) ,
Base . decode16! ( encoded_params , case : :lower ) ,
% FunctionSelector {
% FunctionSelector {
@ -714,7 +806,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
}
}
)
)
{ sequence_number , prev_message_count , new_message_count }
{ sequence_number , prev_message_count , new_message_count , data }
" 0x3e5aa082 " <> encoded_params ->
" 0x3e5aa082 " <> encoded_params ->
# addSequencerL2BatchFromBlobs(uint256 sequenceNumber, uint256 afterDelayedMessagesRead, address gasRefunder, uint256 prevMessageCount, uint256 newMessageCount)
# addSequencerL2BatchFromBlobs(uint256 sequenceNumber, uint256 afterDelayedMessagesRead, address gasRefunder, uint256 prevMessageCount, uint256 newMessageCount)
@ -733,7 +825,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
}
}
)
)
{ sequence_number , prev_message_count , new_message_count }
{ sequence_number , prev_message_count , new_message_count , nil }
end
end
end
end
@ -861,6 +953,14 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# ## Returns
# ## Returns
# - A map where each key is a rollup block number and its value is the
# - A map where each key is a rollup block number and its value is the
# corresponding batch number.
# corresponding batch number.
@spec unwrap_rollup_block_ranges ( %{
non_neg_integer ( ) = > %{
:start_block = > non_neg_integer ( ) ,
:end_block = > non_neg_integer ( ) ,
:number = > non_neg_integer ( ) ,
optional ( any ( ) ) = > any ( )
}
} ) :: %{ non_neg_integer ( ) = > non_neg_integer ( ) }
defp unwrap_rollup_block_ranges ( batches ) do
defp unwrap_rollup_block_ranges ( batches ) do
batches
batches
|> Map . values ( )
|> Map . values ( )
@ -933,6 +1033,18 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# ## Returns
# ## Returns
# - A tuple containing the updated map of rollup blocks and the updated list of
# - A tuple containing the updated map of rollup blocks and the updated list of
# transactions, both are ready for database import.
# transactions, both are ready for database import.
@spec recover_data_if_necessary (
%{ non_neg_integer ( ) = > Arbitrum.BatchBlock . to_import ( ) } ,
[ Arbitrum.BatchTransaction . to_import ( ) ] ,
[ non_neg_integer ( ) ] ,
%{ non_neg_integer ( ) = > non_neg_integer ( ) } ,
%{
:json_rpc_named_arguments = > EthereumJSONRPC . json_rpc_named_arguments ( ) ,
:chunk_size = > non_neg_integer ( ) ,
optional ( any ( ) ) = > any ( )
}
) ::
{ %{ non_neg_integer ( ) = > Arbitrum.BatchBlock . to_import ( ) } , [ Arbitrum.BatchTransaction . to_import ( ) ] }
defp recover_data_if_necessary (
defp recover_data_if_necessary (
current_rollup_blocks ,
current_rollup_blocks ,
current_rollup_txs ,
current_rollup_txs ,
@ -988,6 +1100,18 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# - A list of transactions, each associated with its respective rollup block
# - A list of transactions, each associated with its respective rollup block
# and batch number, ready for database import.
# and batch number, ready for database import.
# - The updated counter of processed chunks (usually ignored).
# - The updated counter of processed chunks (usually ignored).
@spec recover_rollup_blocks_and_txs_from_rpc (
[ non_neg_integer ( ) ] ,
[ non_neg_integer ( ) ] ,
%{ non_neg_integer ( ) = > non_neg_integer ( ) } ,
%{
:json_rpc_named_arguments = > EthereumJSONRPC . json_rpc_named_arguments ( ) ,
:chunk_size = > non_neg_integer ( ) ,
optional ( any ( ) ) = > any ( )
}
) ::
{ %{ non_neg_integer ( ) = > Arbitrum.BatchBlock . to_import ( ) } , [ Arbitrum.BatchTransaction . to_import ( ) ] ,
non_neg_integer ( ) }
defp recover_rollup_blocks_and_txs_from_rpc (
defp recover_rollup_blocks_and_txs_from_rpc (
required_blocks_numbers ,
required_blocks_numbers ,
found_blocks_numbers ,
found_blocks_numbers ,
@ -1054,6 +1178,11 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
# for database import.
# for database import.
# - An updated list of transactions, each associated with its respective rollup
# - An updated list of transactions, each associated with its respective rollup
# block and batch number, ready for database import.
# block and batch number, ready for database import.
@spec prepare_rollup_block_map_and_transactions_list (
[ %{ id : non_neg_integer ( ) , result : %{ String . t ( ) = > any ( ) } } ] ,
%{ non_neg_integer ( ) = > Arbitrum.BatchBlock . to_import ( ) } ,
[ Arbitrum.BatchTransaction . to_import ( ) ]
) :: { %{ non_neg_integer ( ) = > Arbitrum.BatchBlock . to_import ( ) } , [ Arbitrum.BatchTransaction . to_import ( ) ] }
defp prepare_rollup_block_map_and_transactions_list ( json_responses , rollup_blocks , rollup_txs ) do
defp prepare_rollup_block_map_and_transactions_list ( json_responses , rollup_blocks , rollup_txs ) do
json_responses
json_responses
|> Enum . reduce ( { rollup_blocks , rollup_txs } , fn resp , { blocks_map , txs_list } ->
|> Enum . reduce ( { rollup_blocks , rollup_txs } , fn resp , { blocks_map , txs_list } ->
@ -1100,6 +1229,7 @@ defmodule Indexer.Fetcher.Arbitrum.Workers.NewBatches do
end
end
# Retrieves initiated L2-to-L1 messages up to specified block number and marks them as 'sent'.
# Retrieves initiated L2-to-L1 messages up to specified block number and marks them as 'sent'.
@spec get_committed_l2_to_l1_messages ( non_neg_integer ( ) ) :: [ Arbitrum.Message . to_import ( ) ]
defp get_committed_l2_to_l1_messages ( block_number ) do
defp get_committed_l2_to_l1_messages ( block_number ) do
block_number
block_number
|> Db . initiated_l2_to_l1_messages ( )
|> Db . initiated_l2_to_l1_messages ( )