Skip to content

Commit 4ee0a46

Browse files
authored
fix(l1): don't trigger snap sync if fcu head is already canonical (#4985)
**Motivation** In hive tests we often receive an fcu with either the genesis or last imported block as head to notify the node that it is already synced. As this is not usual in a real-case scenario, we just trigger a snap sync to the advertised head. This PR solves this by first checking if the fcu head is already part of our canonic chain before triggering a sync <!-- Why does this pull request exist? What are its goals? --> **Description** * When handling a forkchoice in snap sync mode, check that the head is not already canonical before triggering a sync, if it is already canonical, apply the forkchoice <!-- A clear and concise general description of the changes this PR introduces --> <!-- Link to issues: Resolves #111, Resolves #222 --> Closes #4846
1 parent c394979 commit 4ee0a46

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

crates/networking/p2p/sync_manager.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ impl SyncManager {
9696
}
9797
}
9898

99+
/// Disables snapsync mode
100+
pub fn disable_snap(&self) {
101+
self.snap_enabled.store(false, Ordering::Relaxed);
102+
}
103+
99104
/// Updates the last fcu head. This may be used on the next sync cycle if needed
100105
fn set_head(&self, fcu_head: H256) {
101106
if let Ok(mut latest_fcu_head) = self.last_fcu_head.try_lock() {

crates/networking/rpc/engine/fork_choice.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,19 @@ async fn handle_forkchoice(
216216
}
217217

218218
if context.syncer.sync_mode() == SyncMode::Snap {
219-
context
220-
.syncer
221-
.sync_to_head(fork_choice_state.head_block_hash);
222-
return Ok((None, PayloadStatus::syncing().into()));
219+
// Don't trigger a sync if the block is already canonical
220+
if context
221+
.storage
222+
.is_canonical_sync(fork_choice_state.head_block_hash)?
223+
{
224+
// Disable snapsync mode so we can process incoming payloads
225+
context.syncer.disable_snap();
226+
} else {
227+
context
228+
.syncer
229+
.sync_to_head(fork_choice_state.head_block_hash);
230+
return Ok((None, PayloadStatus::syncing().into()));
231+
}
223232
}
224233

225234
match apply_fork_choice(

0 commit comments

Comments
 (0)