Skip to content

Commit 7854c8e

Browse files
authored
Merge pull request #86 from Blobscan/fix/forwarded-blocks-fix
fix: update reorg logic
2 parents d41a594 + 953ca06 commit 7854c8e

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

src/slots_processor/mod.rs

+19-13
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alloy::{
44
use anyhow::{anyhow, Context as AnyhowContext, Result};
55

66
use crate::clients::beacon::types::BlockHeader;
7-
use tracing::{debug, info};
7+
use tracing::{debug, info, Instrument};
88

99
use crate::{
1010
clients::{
@@ -287,6 +287,18 @@ impl SlotsProcessor<ReqwestTransport> {
287287
let canonical_block_path =
288288
canonical_block_path.into_iter().rev().collect::<Vec<_>>();
289289

290+
let forwarded_blocks = canonical_block_path
291+
.iter()
292+
.map(|block| block.execution_block_hash)
293+
.collect::<Vec<_>>();
294+
295+
self.context
296+
.blobscan_client()
297+
.handle_reorg(rewinded_blocks.clone(), forwarded_blocks.clone())
298+
.await?;
299+
300+
info!(rewinded_blocks = ?rewinded_blocks, forwarded_blocks = ?forwarded_blocks, "Reorg handled!");
301+
290302
let canonical_block_headers: Vec<BlockHeader> = canonical_block_path
291303
.iter()
292304
.map(|block| block.into())
@@ -296,24 +308,18 @@ impl SlotsProcessor<ReqwestTransport> {
296308
// they were skipped and must be processed.
297309
for block in canonical_block_headers.iter() {
298310
if block.slot != new_head_header.slot {
311+
let reorg_span = tracing::info_span!(
312+
parent: &tracing::Span::current(),
313+
"forwarded_block",
314+
);
315+
299316
self.process_block(block)
317+
.instrument(reorg_span)
300318
.await
301319
.with_context(|| format!("Failed to sync forwarded block"))?;
302320
}
303321
}
304322

305-
let forwarded_blocks = canonical_block_path
306-
.iter()
307-
.map(|block| block.execution_block_hash)
308-
.collect::<Vec<_>>();
309-
310-
self.context
311-
.blobscan_client()
312-
.handle_reorg(rewinded_blocks.clone(), forwarded_blocks.clone())
313-
.await?;
314-
315-
info!(rewinded_blocks = ?rewinded_blocks, forwarded_blocks = ?forwarded_blocks, "Reorg handled!");
316-
317323
return Ok(());
318324
}
319325

0 commit comments

Comments
 (0)