Skip to content

Conversation

@dapplion
Copy link
Collaborator

Issue Addressed

From #8382 I noted that the logic in range sync to decide where to start syncing from is scattered. When manual finalization is triggered, sync will fetch useless epochs.

Proposed Changes

This is a somewhat sensitive change that I don't want to have buried in #8382. Since manual finalization is an avaialble feature in current stable I think it's okay to fix separately to #8382.

This PR merges the logic to decide if a peer:

  • is advanced or not
  • should trigger head or finalized sync

In a single function. Plus, the variant PeerSyncType::Advanced includes which slot sync should start from.

@dapplion dapplion requested a review from jxs as a code owner November 15, 2025 00:23
@dapplion dapplion added syncing ready-for-review The code is ready for review labels Nov 15, 2025

pub enum PeerSyncTypeAdvanced {
Finalized {
target_slot: Slot,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs comment

Finalized {
target_slot: Slot,
target_root: Hash256,
start_epoch: Epoch,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be per-peer?

}

#[derive(Clone)]
pub(crate) struct LocalSyncInfo {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a comment

let status = chain.status_message();
// Max with the store in case the node has triggered manual finalization
let local_irreversible_epoch = std::cmp::max(
chain.head().finalized_checkpoint().epoch,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May as well use status.finalized_epoch() here to avoid potential inconsistencies. It's also likely to be marginally quicker

PeerSyncType::FullySynced
} else {
PeerSyncType::Advanced
let finality_advanced = remote.finalized_epoch > local.finalized_epoch + 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A comment or a const for this + 1 would be good I think

@dapplion dapplion requested a review from eserilev November 25, 2025 22:15
@michaelsproul michaelsproul added waiting-on-author The reviewer has suggested changes and awaits thier implementation. and removed ready-for-review The code is ready for review labels Dec 2, 2025
@michaelsproul
Copy link
Member

Changing this to waiting-on-author, I think you said last week you were planning to make some more changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

syncing waiting-on-author The reviewer has suggested changes and awaits thier implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants