Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve issue with common ancient block lookup during reorg processing #82

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 38 additions & 45 deletions src/slots_processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
{
info!(
new_head_slot = block_header.slot,
old__head_slot = prev_block_header.slot,
old_head_slot = prev_block_header.slot,
new_head_block_root = ?block_header.root,
old_head_block_root = ?prev_block_header.root,
"Reorg detected!",
Expand Down Expand Up @@ -270,65 +270,58 @@
let mut rewinded_blocks: Vec<B256> = vec![];

while reorg_depth <= MAX_ALLOWED_REORG_DEPTH && current_old_slot > 0 {
reorg_depth += 1;

// We iterate over blocks by slot and not block root as blobscan blocks don't
// have parent root we can use to traverse the chain
let old_blobscan_block = match self
if let Some(old_blobscan_block) = self
.context
.blobscan_client()
.get_block(current_old_slot)
.await?
{
Some(block) => block,
None => {
current_old_slot -= 1;

continue;
}
};
let canonical_block_path = self
.get_canonical_block_path(&old_blobscan_block, new_head_header.root)
.await?;

let canonical_block_path = self
.get_canonical_block_path(&old_blobscan_block, new_head_header.root)
.await?;

// If a path exists, we've found the common ancient block
// and can proceed with handling the reorg.
if !canonical_block_path.is_empty() {
let canonical_block_path =
canonical_block_path.into_iter().rev().collect::<Vec<_>>();

let canonical_block_headers: Vec<BlockHeader> = canonical_block_path
.iter()
.map(|block| block.into())
.collect::<Vec<_>>();

// If the new canonical block path includes blocks beyond the new head block,
// they were skipped and must be processed.
for block in canonical_block_headers.iter() {
if block.slot != new_head_header.slot {
self.process_block(block)
.await
.with_context(|| format!("Failed to sync forwarded block"))?;
// If a path exists, we've found the common ancient block
if !canonical_block_path.is_empty() {
let canonical_block_path =
canonical_block_path.into_iter().rev().collect::<Vec<_>>();

let canonical_block_headers: Vec<BlockHeader> = canonical_block_path
.iter()
.map(|block| block.into())
.collect::<Vec<_>>();

// If the new canonical block path includes blocks beyond the new head block,
// they were skipped and must be processed.
for block in canonical_block_headers.iter() {
if block.slot != new_head_header.slot {
self.process_block(block)
.await
.with_context(|| format!("Failed to sync forwarded block"))?;
}
}
}

let forwarded_blocks = canonical_block_path
.iter()
.map(|block| block.execution_block_hash)
.collect::<Vec<_>>();
let forwarded_blocks = canonical_block_path
.iter()
.map(|block| block.execution_block_hash)
.collect::<Vec<_>>();

self.context
.blobscan_client()
.handle_reorg(rewinded_blocks.clone(), forwarded_blocks.clone())
.await?;
self.context
.blobscan_client()
.handle_reorg(rewinded_blocks.clone(), forwarded_blocks.clone())

Check warning on line 312 in src/slots_processor/mod.rs

View workflow job for this annotation

GitHub Actions / Run tests

useless use of `format!`

warning: useless use of `format!` --> src/slots_processor/mod.rs:312:46 | 312 | ... .with_context(|| format!("Failed to sync forwarded block"))?; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"Failed to sync forwarded block".to_string()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format = note: `#[warn(clippy::useless_format)]` on by default
.await?;

info!(rewinded_blocks = ?rewinded_blocks, forwarded_blocks = ?forwarded_blocks, "Reorg handled!",);
info!(rewinded_blocks = ?rewinded_blocks, forwarded_blocks = ?forwarded_blocks, "Reorg handled!");

return Ok(());
return Ok(());
}

rewinded_blocks.push(old_blobscan_block.hash);
}

rewinded_blocks.push(old_blobscan_block.hash);
current_old_slot -= 1;
reorg_depth += 1;
}

Err(anyhow!("No common block found").into())
Expand All @@ -338,7 +331,7 @@
async fn get_canonical_block_path(
&mut self,
blobscan_block: &BlobscanBlock,
head_block_root: B256,

Check warning on line 334 in src/slots_processor/mod.rs

View workflow job for this annotation

GitHub Actions / Run tests

useless conversion to the same type: `anyhow::Error`

warning: useless conversion to the same type: `anyhow::Error` --> src/slots_processor/mod.rs:334:13 | 334 | Err(anyhow!("No common block found").into()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `anyhow!("No common block found")` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
) -> Result<Vec<BlockData>, ClientError> {
let beacon_client = self.context.beacon_client();
let mut canonical_execution_blocks: Vec<BlockData> = vec![];
Expand Down
Loading