Skip to content

Commit 358d584

Browse files
authoredFeb 11, 2025··
Merge pull request #82 from Blobscan/fix/common-ancient-block-search
fix: resolve issue with common ancient block lookup during reorg processing
2 parents f3ea424 + 30549be commit 358d584

File tree

1 file changed

+38
-45
lines changed

1 file changed

+38
-45
lines changed
 

‎src/slots_processor/mod.rs

+38-45
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl SlotsProcessor<ReqwestTransport> {
9191
{
9292
info!(
9393
new_head_slot = block_header.slot,
94-
old__head_slot = prev_block_header.slot,
94+
old_head_slot = prev_block_header.slot,
9595
new_head_block_root = ?block_header.root,
9696
old_head_block_root = ?prev_block_header.root,
9797
"Reorg detected!",
@@ -270,65 +270,58 @@ impl SlotsProcessor<ReqwestTransport> {
270270
let mut rewinded_blocks: Vec<B256> = vec![];
271271

272272
while reorg_depth <= MAX_ALLOWED_REORG_DEPTH && current_old_slot > 0 {
273-
reorg_depth += 1;
274-
275273
// We iterate over blocks by slot and not block root as blobscan blocks don't
276274
// have parent root we can use to traverse the chain
277-
let old_blobscan_block = match self
275+
if let Some(old_blobscan_block) = self
278276
.context
279277
.blobscan_client()
280278
.get_block(current_old_slot)
281279
.await?
282280
{
283-
Some(block) => block,
284-
None => {
285-
current_old_slot -= 1;
286-
287-
continue;
288-
}
289-
};
281+
let canonical_block_path = self
282+
.get_canonical_block_path(&old_blobscan_block, new_head_header.root)
283+
.await?;
290284

291-
let canonical_block_path = self
292-
.get_canonical_block_path(&old_blobscan_block, new_head_header.root)
293-
.await?;
294-
295-
// If a path exists, we've found the common ancient block
296-
// and can proceed with handling the reorg.
297-
if !canonical_block_path.is_empty() {
298-
let canonical_block_path =
299-
canonical_block_path.into_iter().rev().collect::<Vec<_>>();
300-
301-
let canonical_block_headers: Vec<BlockHeader> = canonical_block_path
302-
.iter()
303-
.map(|block| block.into())
304-
.collect::<Vec<_>>();
305-
306-
// If the new canonical block path includes blocks beyond the new head block,
307-
// they were skipped and must be processed.
308-
for block in canonical_block_headers.iter() {
309-
if block.slot != new_head_header.slot {
310-
self.process_block(block)
311-
.await
312-
.with_context(|| format!("Failed to sync forwarded block"))?;
285+
// If a path exists, we've found the common ancient block
286+
if !canonical_block_path.is_empty() {
287+
let canonical_block_path =
288+
canonical_block_path.into_iter().rev().collect::<Vec<_>>();
289+
290+
let canonical_block_headers: Vec<BlockHeader> = canonical_block_path
291+
.iter()
292+
.map(|block| block.into())
293+
.collect::<Vec<_>>();
294+
295+
// If the new canonical block path includes blocks beyond the new head block,
296+
// they were skipped and must be processed.
297+
for block in canonical_block_headers.iter() {
298+
if block.slot != new_head_header.slot {
299+
self.process_block(block)
300+
.await
301+
.with_context(|| format!("Failed to sync forwarded block"))?;
302+
}
313303
}
314-
}
315304

316-
let forwarded_blocks = canonical_block_path
317-
.iter()
318-
.map(|block| block.execution_block_hash)
319-
.collect::<Vec<_>>();
305+
let forwarded_blocks = canonical_block_path
306+
.iter()
307+
.map(|block| block.execution_block_hash)
308+
.collect::<Vec<_>>();
320309

321-
self.context
322-
.blobscan_client()
323-
.handle_reorg(rewinded_blocks.clone(), forwarded_blocks.clone())
324-
.await?;
310+
self.context
311+
.blobscan_client()
312+
.handle_reorg(rewinded_blocks.clone(), forwarded_blocks.clone())
313+
.await?;
325314

326-
info!(rewinded_blocks = ?rewinded_blocks, forwarded_blocks = ?forwarded_blocks, "Reorg handled!",);
315+
info!(rewinded_blocks = ?rewinded_blocks, forwarded_blocks = ?forwarded_blocks, "Reorg handled!");
327316

328-
return Ok(());
317+
return Ok(());
318+
}
319+
320+
rewinded_blocks.push(old_blobscan_block.hash);
329321
}
330322

331-
rewinded_blocks.push(old_blobscan_block.hash);
323+
current_old_slot -= 1;
324+
reorg_depth += 1;
332325
}
333326

334327
Err(anyhow!("No common block found").into())

0 commit comments

Comments
 (0)
Please sign in to comment.