From 542def6d87fe1118187cd3ca829ea193521717f7 Mon Sep 17 00:00:00 2001 From: Maciej Date: Thu, 7 Mar 2024 15:53:28 +0100 Subject: [PATCH] partial-batch simplified --- src/specular/stages/batches.rs | 45 +++++++++++++--------------------- 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/src/specular/stages/batches.rs b/src/specular/stages/batches.rs index 3d7bedf..007c944 100644 --- a/src/specular/stages/batches.rs +++ b/src/specular/stages/batches.rs @@ -234,36 +234,31 @@ fn decode_batches_v0( // Decode the first l2 block number at offset 0. let batch_first_l2_num: u64 = batch_list.val_at(0)?; let last_in_batch: u64; - let mut to_skip: u64 = 0; + + // Assuming all items included are consequtive, last block l2 block number in batch would be: + last_in_batch = batch_first_l2_num + batch_list.size() as u64 - 1; + // Check for duplicates. tracing::info!( - "batch_first_l2_num = {} local_l2_num = {}", + "batch_first_l2_num = {} local_l2_num = {} last_in_batch = {}", batch_first_l2_num, local_l2_num, + last_in_batch, ); - if batch_first_l2_num < local_l2_num { - tracing::warn!( - "BatcherTx batches already seen | safe_head={} first_l2_block_num={}", - local_l2_num, - batch_first_l2_num - ); - - // Assuming all items included are consequtive, last block l2 block number in batch would be: - last_in_batch = batch_first_l2_num + batch_list.size() as u64 - 1; - tracing::info!("last_in_batch={}", last_in_batch); - if last_in_batch > local_l2_num { - // L2 blocks sequence range missed to redo: (start_from, local_l2_num) - to_skip = last_in_batch - local_l2_num; - tracing::info!("recovering part of batches after to_skip={}", to_skip); - } else { - eyre::bail!("BatcherTx all batches already seen"); - } + if last_in_batch > local_l2_num { + // L2 blocks sequence range missed to redo: (local_l2_num + to_skip, local_l2_num) + let to_skip: u64 = last_in_batch - local_l2_num; + // We start from adjusted range down if some batches were missed due to unexpected iterruption. + local_l2_num += to_skip; + tracing::info!("recovering part of batches to_skip = {} local_l2_num = {}", to_skip, local_l2_num); + } else { + // No gap, nothing to do + eyre::bail!("BatcherTx all batches already seen"); } // Insert empty batches for missing blocks. - // We start from adjusted range down if some batches were missed due to unexpected iterruption. - for i in batch_first_l2_num + to_skip + 1..batch_first_l2_num { + for i in local_l2_num + 1..batch_first_l2_num { let batch = SpecularBatchV0 { epoch_num, epoch_hash, @@ -280,18 +275,12 @@ fn decode_batches_v0( ); batches.push(batch); } + // Update the local l2 block number. - // We're supposed to have inserted empty batches until right before the first batch in the list. - local_l2_num = batch_first_l2_num - 1; let batch_first_l2_ts = (batch_first_l2_num - safe_l2_num) * config.chain.blocktime + safe_l2_ts; // Decode the transaction batches at offset 1. for (batch, idx) in batch_list.at(1)?.iter().zip(0u64..) { - // In case of partial batch sequencing, we should skip sequencing batches which were already covered - if idx < to_skip { - continue; - } - let transactions: Vec = batch.as_list()?; // Try decode the `setL1OacleValues` call if it is the first batch in the list. let l1_oracle_values = if idx == 0 {