Skip to content

Commit

Permalink
partial-batch simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
macwis committed Mar 7, 2024
1 parent a11d24e commit 542def6
Showing 1 changed file with 17 additions and 28 deletions.
45 changes: 17 additions & 28 deletions src/specular/stages/batches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Check failure on line 236 in src/specular/stages/batches.rs

View workflow job for this annotation

GitHub Actions / clippy

unneeded late initialization
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,
Expand All @@ -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<RawTransaction> = batch.as_list()?;
// Try decode the `setL1OacleValues` call if it is the first batch in the list.
let l1_oracle_values = if idx == 0 {
Expand Down

0 comments on commit 542def6

Please sign in to comment.