Skip to content

Commit

Permalink
fix(fetcher): l1_head < latest l1 header (#269)
Browse files Browse the repository at this point in the history
* fix: safe head range calc

* feat: add

* Fix
  • Loading branch information
ratankaliani authored Dec 10, 2024
1 parent b33d8d4 commit 70112c5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion utils/host/src/block_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub async fn split_range_based_on_safe_heads(

// Loop over all of the safe heads and create ranges.
for safe_head in safe_heads {
if safe_head > current_l2_start {
if safe_head > current_l2_start && current_l2_start < l2_end {
let mut range_start = current_l2_start;
while range_start + max_range_size < min(l2_end, safe_head) {
ranges.push(SpanBatchRange {
Expand Down
13 changes: 11 additions & 2 deletions utils/host/src/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,16 @@ impl OPSuccinctDataFetcher {
};
let claimed_l2_output_root = keccak256(l2_claim_encoded.abi_encode());

let (l1_head_hash, _) = self.get_l1_head(l2_end_block).await?;
let (_, l1_head_number) = self.get_l1_head(l2_end_block).await?;

// FIXME: Investigate requirement for L1 head offset beyond batch posting block with safe head > L2 end block.
let l1_head_number = l1_head_number + 20;
// The new L1 header requested should not be greater than the latest L1 header.
let latest_l1_header = self.get_l1_header(BlockId::latest()).await?;
let l1_head_hash = match l1_head_number > latest_l1_header.number {
true => latest_l1_header.hash_slow(),
false => self.get_l1_header(l1_head_number.into()).await?.hash_slow(),
};

// Get the workspace root, which is where the data directory is.
let data_directory =
Expand Down Expand Up @@ -887,7 +896,7 @@ impl OPSuccinctDataFetcher {
)
.await?;
let l2_safe_head = result.safe_head.number;
// If the safe head is greater than or equal to the L2 end block at this L1 block, then we can derive the L2 end block from this L1 block.
// If the safe head is GTE to the L2 end block at this L1 block, then we can derive the L2 end block from this L1 block.
if l2_safe_head >= l2_end_block {
return Ok((result.l1_block.hash, result.l1_block.number));
}
Expand Down

0 comments on commit 70112c5

Please sign in to comment.