Skip to content

Commit 702680f

Browse files
authored
reset parent block hash when reset progress (#188)
* reset parent block hash when reset progress
1 parent 678d233 commit 702680f

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

node/log_entry_sync/src/sync_manager/log_entry_fetcher.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,12 @@ impl LogEntryFetcher {
309309
check_watch_process(
310310
&mut watch_progress_rx,
311311
&mut progress,
312+
&mut parent_block_hash,
312313
&mut progress_reset_history,
313314
watch_loop_wait_time_ms,
314-
);
315+
&block_hash_cache,
316+
)
317+
.await;
315318

316319
match Self::watch_loop(
317320
provider.as_ref(),
@@ -555,11 +558,13 @@ impl LogEntryFetcher {
555558
}
556559
}
557560

558-
fn check_watch_process(
561+
async fn check_watch_process(
559562
watch_progress_rx: &mut UnboundedReceiver<u64>,
560563
progress: &mut u64,
564+
parent_block_hash: &mut H256,
561565
progress_reset_history: &mut BTreeMap<u64, (Instant, usize)>,
562566
watch_loop_wait_time_ms: u64,
567+
block_hash_cache: &Arc<RwLock<BTreeMap<u64, Option<BlockHashAndSubmissionIndex>>>>,
563568
) {
564569
let mut min_received_progress = None;
565570
while let Ok(v) = watch_progress_rx.try_recv() {
@@ -570,6 +575,7 @@ fn check_watch_process(
570575
};
571576
}
572577

578+
let mut reset = false;
573579
if let Some(v) = min_received_progress {
574580
if *progress <= v {
575581
error!(
@@ -595,16 +601,36 @@ fn check_watch_process(
595601
*progress = v;
596602
*last_update = now;
597603
*counter += 1;
604+
reset = true;
598605
}
599606
}
600607
None => {
601608
info!("reset to progress from {} to {}", *progress, v);
602609
*progress = v;
603610
progress_reset_history.insert(v, (now, 1usize));
611+
reset = true;
604612
}
605613
}
606614
}
607615

616+
if reset {
617+
*parent_block_hash = loop {
618+
if let Some(block) = block_hash_cache.read().await.get(&(*progress - 1)) {
619+
if let Some(v) = block {
620+
break v.block_hash;
621+
} else {
622+
debug!(
623+
"block_hash_cache wait for SyncedBlock processed for {}",
624+
*progress - 1
625+
);
626+
tokio::time::sleep(Duration::from_secs(RETRY_WAIT_MS)).await;
627+
}
628+
} else {
629+
panic!("parent block {} expect exist", *progress - 1);
630+
}
631+
};
632+
}
633+
608634
progress_reset_history.retain(|k, _| k + 1000 >= *progress);
609635
}
610636

0 commit comments

Comments
 (0)