Skip to content

Commit ddfd70c

Browse files
committed
ref: remove reorg check
1 parent e2ae3ff commit ddfd70c

File tree

1 file changed

+8
-41
lines changed

1 file changed

+8
-41
lines changed

src/block_range_scanner.rs

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ use alloy::{
7676
consensus::BlockHeader,
7777
eips::{BlockId, BlockNumberOrTag},
7878
network::{BlockResponse, Network, primitives::HeaderResponse},
79-
primitives::{B256, BlockHash, BlockNumber},
79+
primitives::{B256, BlockNumber},
8080
pubsub::Subscription,
8181
transports::{RpcError, TransportErrorKind},
8282
};
@@ -330,13 +330,11 @@ impl<N: Network> Service<N> {
330330
let start_block_num = start_block.header().number();
331331
let end_block_num = end_block.header().number();
332332

333-
let (start_block_num, start_id, end_block_num) = match start_block_num.cmp(&end_block_num) {
334-
Ordering::Greater => (end_block_num, end_id, start_block_num),
335-
_ => (start_block_num, start_id, end_block_num),
333+
let (start_block_num, end_block_num) = match start_block_num.cmp(&end_block_num) {
334+
Ordering::Greater => (end_block_num, start_block_num),
335+
_ => (start_block_num, end_block_num),
336336
};
337337

338-
self.verify_start_block_hash(start_block_num, start_id, &sender).await?;
339-
340338
info!(start_block = start_block_num, end_block = end_block_num, "Syncing historical data");
341339

342340
tokio::spawn(async move {
@@ -427,8 +425,6 @@ impl<N: Network> Service<N> {
427425
.await;
428426
});
429427

430-
self.verify_start_block_hash(start_block, start_id, &sender).await?;
431-
432428
tokio::spawn(async move {
433429
// Step 4: Perform historical synchronization
434430
// This processes blocks from start_block to end_block (cutoff)
@@ -470,14 +466,10 @@ impl<N: Network> Service<N> {
470466
try_join!(self.provider.get_block(start_id), self.provider.get_block(end_id),)?;
471467

472468
// normalize block range
473-
let (from, start_id, to) =
474-
match start_block.header().number().cmp(&end_block.header().number()) {
475-
Ordering::Greater => (start_block, start_id, end_block),
476-
_ => (end_block, end_id, start_block),
477-
};
478-
479-
// One off reorg check before streaming if start is a hash
480-
self.verify_start_block_hash(from.header().number(), start_id, &sender).await?;
469+
let (from, to) = match start_block.header().number().cmp(&end_block.header().number()) {
470+
Ordering::Greater => (start_block, end_block),
471+
_ => (end_block, start_block),
472+
};
481473

482474
tokio::spawn(async move {
483475
Self::stream_rewind(from, to, max_block_range, &sender, &provider).await;
@@ -486,31 +478,6 @@ impl<N: Network> Service<N> {
486478
Ok(())
487479
}
488480

489-
async fn verify_start_block_hash(
490-
&self,
491-
start_block: BlockNumber,
492-
start_id: BlockId,
493-
sender: &mpsc::Sender<Message>,
494-
) -> Result<(), ScannerError> {
495-
if let BlockId::Hash(expected_hash) = start_id {
496-
let block_hash = self
497-
.provider
498-
.get_block_by_number(BlockNumberOrTag::Number(start_block))
499-
.await?
500-
.header()
501-
.hash();
502-
let expected_hash: BlockHash = expected_hash.into();
503-
504-
if block_hash != expected_hash &&
505-
!sender.try_stream(Message::Notification(Notification::ReorgDetected)).await
506-
{
507-
return Err(ScannerError::ServiceShutdown);
508-
}
509-
}
510-
511-
Ok(())
512-
}
513-
514481
/// Streams blocks in reverse order from `from` to `to`.
515482
///
516483
/// The `from` block is assumed to be greater than or equal to the `to` block.

0 commit comments

Comments
 (0)