Writing

Draft Design Document: Supporting Sync from Non-Finalized Checkpoints in Grandine

Reading time: 18 minutes

Note This document contains the detailed technical design for my EPF7 project proposal.

It represents my current understanding of Grandine’s checkpoint-sync architecture after tracing the implementation and comparing it with related work in Lighthouse.

The design is still evolving and is intended to gather feedback before implementation.

A shorter version of the project proposal is available here: Updated Project Proposal

Abstract

Grandine currently supports checkpoint sync using a recent finalized checkpoint. This gives beacon-node operators a fast and safe way to start a node without replaying the entire chain from genesis.

The client downloads a finalized block and its corresponding beacon state, initializes fork choice using that checkpoint as its anchor, and then syncs forward toward the current chain head.

However, during extended periods of non-finality, the latest finalized checkpoint may become significantly older than the wall-clock head. A node starting from that finalized checkpoint may still need to process a large range of blocks before becoming useful.

This design proposes support for syncing from a trusted non-finalized checkpoint closer to the current wall-clock slot.

The main architectural challenge is that Grandine currently treats the checkpoint-sync anchor as both:

  1. the node’s trusted local startup anchor, and
  2. the chain’s actual finalized and justified checkpoint.

These concepts are equivalent when syncing from a finalized checkpoint, but they are not equivalent when the selected startup checkpoint is non-finalized.

The proposed design introduces a separation between:

Local trusted / irreversible anchor

and:

On-chain finalized and justified checkpoints

The local anchor would provide rollback protection and establish the lower boundary for sync, while fork-choice voting, validator duties, Beacon API responses, and P2P status messages would continue to use the real finalized and justified checkpoints contained in the downloaded beacon state.

Motivation

Checkpoint sync is normally based on a recent finalized state because finalized checkpoints provide a strong and simple startup boundary.

Once a checkpoint has been finalized, the client can safely assume that the canonical chain will not revert behind it under normal protocol conditions. The downloaded checkpoint can therefore serve as:

  • the fork-choice anchor,
  • the database split point,
  • the forward-sync starting point,
  • the local finalized checkpoint, and the starting point for historical back-sync.

The difficulty appears during prolonged periods of non-finality.

Suppose the network continues producing blocks but does not finalize for an extended period. The wall-clock head may advance thousands of slots beyond the latest finalized checkpoint. A newly started node that uses normal checkpoint sync must still begin from that old finalized checkpoint and process the entire non-finalized range. A trusted checkpoint closer to the current head could significantly improve recovery time.

However, simply downloading a newer state and pretending it is finalized would be unsafe. The downloaded state may be trusted locally by the operator, but the Ethereum consensus protocol may not have finalized it.

This project is therefore not just about adding another Beacon API state ID. It requires refactoring areas of Grandine that currently assume:

checkpoint sync anchor == finalized checkpoint

The implementation must instead support:

checkpoint sync anchor != finalized checkpoint

while keeping Grandine’s existing finalized checkpoint-sync behavior unchanged.

My Design Goals

  • allow Grandine to start from a trusted non-finalized checkpoint near the current wall-clock head;
  • preserve the actual finalized and justified checkpoints from the downloaded beacon state;
  • introduce a local trusted anchor that establishes the minimum acceptable chain ancestor;
  • prevent fork choice from selecting chains that do not descend from the trusted anchor;
  • avoid reporting the local anchor as finalized to peers;
  • avoid using the local anchor as a Casper FFG source checkpoint;
  • keep finalized checkpoint sync unchanged by default;
  • keep the first implementation small enough to review and test safely;
  • add explicit tests for startup, fork-choice initialization, P2P status, persistence, and sync boundaries.

Non-goals for the first implementation

The first implementation does not need to solve every checkpoint-distribution or recovery problem. Anyway, the following may remain out of scope initially:

  • automatic discovery of trusted non-finalized checkpoint providers;
  • resolving conflicting checkpoints from multiple providers;
  • full historical back-sync before the non-finalized anchor;
  • support for arbitrary non-epoch-aligned anchors;
  • serving complete historical Beacon API data before the local anchor;
  • redesigning weak-subjectivity checkpoint distribution;
  • automatically choosing whether to use finalized or non-finalized checkpoint sync.

Current Checkpoint-Sync Flow

Grandine currently supports checkpoint sync through:

--checkpoint-sync-url <BEACON_NODE_URL>

The CLI describes this as loading a recent finalized checkpoint.

The runtime selects a loading strategy such as:

StateLoadStrategy::Auto { /* ... */ }
StateLoadStrategy::Remote { checkpoint_sync_url }
StateLoadStrategy::Anchor { block, state }

For remote sync, Grandine eventually calls:

load_finalized_from_remote(...)

The loader fetches:

BlockId::Finalized

If the block is not at the start of an epoch, Grandine walks backward to the epoch-start block and downloads the state at that slot:

StateId::Slot(slot)

The result is returned as:

FinalizedCheckpoint<P> {
    block,
    state,
}

This type is then passed through the runtime, genesis, storage and fork-choice initialization paths.

Why Finalized Checkpoint Sync Works

With finalized checkpoint sync, the following values are effectively the same:

local trusted anchor
    ==
on-chain finalized checkpoint
    ==
safe sync lower bound

Because of this, Grandine can initialize fork choice using one checkpoint:

justified_checkpoint = checkpoint;
finalized_checkpoint = checkpoint;
unrealized_justified_checkpoint = checkpoint;
unrealized_finalized_checkpoint = checkpoint;

This works because the startup anchor is actually finalized. The same checkpoint can safely control:

  • fork-choice initialization;
  • pruning;
  • P2P finalized status;
  • peer grouping;
  • forward-sync boundaries;
  • storage;
  • historical back-sync.

The current model is simple because local trust and protocol finality are represented by the same checkpoint.

The Problem During Extended Non-Finality

This assumption breaks when the selected anchor is not finalized.

For example:

Local trusted anchor:  epoch 120
On-chain justified:    epoch 118
On-chain finalized:    epoch 115

The node should not accept a chain that conflicts with epoch 120, because that is the checkpoint trusted by the operator.

However, it must not report epoch 120 as finalized. The real finalized checkpoint is still epoch 115.

Grandine therefore needs to maintain two separate views:

Local view:
Do not roll back behind the trusted anchor.

Protocol view:
Use the justified and finalized checkpoints recorded in the state.

The local anchor should control rollback protection and sync boundaries, while the real justified and finalized checkpoints should continue controlling protocol behaviour.

So the Current Architecture

Runtime flow

The current runtime flow can be summarized as seen below in a diagram:

flowchart TD
    A[Grandine runtime starts] --> B[Parse checkpoint-sync arguments]
    B --> C[Construct AnchorCheckpointProvider]
    C --> D{Choose StateLoadStrategy}
    D -->|Local state available| E[Load local fork-choice state]
    D -->|Remote checkpoint sync| F[load_finalized_from_remote]
    D -->|Explicit anchor| G[Load supplied block and state]
    F --> H[Create FinalizedCheckpoint]
    G --> H
    H --> I[Storage::load]
    I --> J[Store::new]
    J --> K[Initialize fork choice]
    K --> L[Start P2P sync]

Inside the Grandine codebase this are the relevant areas:

runtime/src/grandine_args.rs
runtime/src/runtime.rs
genesis/src/lib.rs
fork_choice_control/src/storage.rs
fork_choice_control/src/checkpoint_sync.rs
fork_choice_store/src/store.rs

Remote checkpoint loading

The central remote checkpoint function currently has finalized semantics:

load_finalized_from_remote(...)

Its high-level behavior is:

async fn load_finalized_from_remote(...) -> Result<FinalizedCheckpoint<P>> {
    let finalized_block = client
        .get_block(BlockId::Finalized)
        .await?;

    let anchor_block = find_epoch_start_block(finalized_block).await?;

    let anchor_state = client
        .get_state(StateId::Slot(anchor_block.slot()))
        .await?;

    Ok(FinalizedCheckpoint {
        block: anchor_block,
        state: anchor_state,
    })
}

The exact implementation differs, but the important behavior is:

  • fetch the finalized block;
  • find an epoch-start block;
  • fetch the state at that slot;
  • return a checkpoint that is assumed to be finalized

Storage flow

Grandine’s storage architecture currently distinguishes broadly between:

  • finalized chain data, which is persisted to disk;
  • non-finalized chain data, which is primarily maintained in memory.

A checkpoint-sync anchor is persisted using finalized-chain semantics because the current anchor is always finalized and This becomes complicated for non-finalized checkpoint sync.

A non-finalized startup anchor must survive restart, but it should not automatically be classified as finalized chain history. So the client may therefore need a distinct persistence category: checkpoint anchor data separate from:

finalized chain data
unfinalized chain data

The persisted metadata should be sufficient to recover:

  • the local trusted anchor;
  • the actual on-chain finalized checkpoint;
  • the actual on-chain justified checkpoint;
  • the anchor’s origin and state ID;
  • any restrictions applied to sync before the anchor.

Fork-choice initialization

Grandine currently initializes fork choice from an anchor checkpoint and assigns that same checkpoint to all finalized and justified fields.

Conceptually:

let checkpoint = Checkpoint {
    epoch: anchor_epoch,
    root: anchor_root,
};

Self {
    justified_checkpoint: checkpoint,
    finalized_checkpoint: checkpoint,
    unrealized_justified_checkpoint: checkpoint,
    unrealized_finalized_checkpoint: checkpoint,
    // ...
}

This is one of the main areas that must change. For a non-finalized anchor, Grandine should initialize:

local trusted anchor       = downloaded checkpoint
justified checkpoint       = state.current_justified_checkpoint()
finalized checkpoint       = state.finalized_checkpoint()

The local anchor must influence chain viability and rollback protection, but it must not replace the on-chain FFG checkpoints.

P2P interaction

Grandine’s P2P status logic currently reports values derived from:

controller.finalized_epoch()
controller.finalized_root()

Those values are used in the Ethereum consensus-layer Status message. This behavior should remain based on the real on-chain finalized checkpoint. And for a non-finalized anchor, Grandine must not report:

local trusted anchor root
local trusted anchor epoch

as:

finalized_root
finalized_epoch

Doing so would advertise false finality to peers and could affect peer compatibility and sync behavior.

The P2P status message should continue using the checkpoint represented by:

state.finalized_checkpoint()

and not the local irreversible anchor.

Sync flow

Current forward sync derives its lower boundary from the local finalized checkpoint.

So conceptually:

let local_finalized_slot =
    compute_start_slot_at_epoch(snapshot.finalized_epoch());

This works when:

local anchor == finalized checkpoint

It does not work when the local trusted anchor is newer than finality.

For non-finalized checkpoint sync, forward sync should use:

local irreversible slot

as the minimum range-sync boundary.

At the same time:

  • P2P status should use real finality;
  • attestation logic should use real justification;
  • sync rollback protection should use the local anchor.

This distinction means the client needs explicit APIs for both concepts.

Problem Analysis

Where the finalized assumption exists

The current implementation assumes every startup anchor is finalized. This appears in several places:

  • FinalizedCheckpoint<P> is used as the main anchor type.
  • AnchorCheckpointProvider<P> stores a finalized checkpoint.
  • Remote loading uses:
load_finalized_from_remote(...)

and requests:

BlockId::Finalized
  • Store::new initializes justified and finalized checkpoints from the startup anchor.
  • Storage treats checkpoint data as finalized history.
  • P2P reports the startup anchor through finalized root and epoch values.
  • Forward sync starts from the local finalized slot.
  • Peer grouping may depend on:
finalized_root
finalized_epoch
  • Back-sync also starts from what the client considers the latest finalized checkpoint.

These assumptions work today because checkpoint sync only uses finalized anchors. They need to be reviewed once non-finalized anchors are supported.

Why this becomes a problem

A non-finalized anchor only means:

The operator trusts this block and state as the local starting point.

It does not mean:

The network has finalized this checkpoint.

Treating a trusted anchor as finalized could cause Grandine to:

  • report incorrect finality to peers;
  • initialize fork choice with the wrong justified or finalized checkpoints;
  • use the wrong Casper FFG source;
  • reject valid chains because of inconsistent checkpoint state;
  • store or prune non-finalized data as finalized;
  • start sync from the wrong slot;
  • group peers using misleading finalized information;
  • return the wrong result for Beacon API finalized requests.

The main issue is that local trust and protocol finality currently share the same representation, even though they are not always the same.

Comparison with Lighthouse

Lighthouse’s proposed non-finalized checkpoint-sync work provides a useful conceptual reference.

The key idea is to separate: on-chain checkpoint from: local irreversible checkpoint

The on-chain checkpoint is what the beacon state reports as justified or finalized. While, the local checkpoint is the trusted anchor that the client refuses to roll back behind.

A simplified model looks like:

pub struct ForkChoiceCheckpoint {
    local: Checkpoint,
    on_chain: Checkpoint,
}

The local view may effectively clamp the checkpoint to the newer of:

on-chain checkpoint local irreversible checkpoint

while the protocol-facing view continues to return the real on-chain checkpoint. This design helps preserve the following invariant:

Local trust can be stronger than on-chain finality, but it must not be presented as on-chain finality.

Grandine does not need to copy Lighthouse’s implementation exactly that’s not what I’m going to do anyway. Its fork-choice and storage architecture differ. However, the conceptual separation is directly relevant to Grandine’s design.

Relevant Lighthouse work:

Proposed Design

The main goal is to separate the local trusted anchor from protocol finality. The design will:

  1. generalize the checkpoint-sync anchor;
  2. keep the real justified and finalized checkpoints from the downloaded state;
  3. introduce a local irreversible checkpoint;
  4. use each checkpoint only where it belongs.
flowchart LR
    A[Downloaded block/state] --> B[AnchorCheckpoint]

    B --> C[Local irreversible checkpoint]
    B --> D[On-chain justified checkpoint]
    B --> E[On-chain finalized checkpoint]

    C --> F[Rollback protection]
    C --> G[Sync lower bound]
    C --> H[Local chain viability]

    D --> I[Fork-choice justification]

    E --> J[P2P status]
    E --> K[Beacon API]
    E --> L[Protocol finality]

AnchorCheckpoint

FinalizedCheckpoint<P> is too specific because the startup anchor may not be finalized. A more general type could be:

pub struct AnchorCheckpoint<P: Preset> {
    pub block: Arc<SignedBeaconBlock<P>>,
    pub state: Arc<BeaconState<P>>,
    pub checkpoint: Checkpoint,
    pub origin: AnchorCheckpointOrigin,
}

The checkpoint represents the selected startup block and state. The origin explains how the anchor was loaded.

pub enum AnchorCheckpointOrigin {
    Genesis,

    FinalizedCheckpointSync,

    NonFinalizedCheckpointSync {
        on_chain_justified: Checkpoint,
        on_chain_finalized: Checkpoint,
    },
}

The exact naming can follow Grandine’s existing conventions. The important rule is:

Finalized sync:
local anchor == on-chain finalized

Non-finalized sync:
local anchor != on-chain finalized

The real protocol checkpoints must always come from:

state.finalized_checkpoint()
state.current_justified_checkpoint()

They should not be inferred from the startup block.

ForkChoiceInit

Fork-choice initialization should clearly show whether the anchor is finalized.

pub enum ForkChoiceInit {
    FinalizedAnchor,

    NonFinalizedAnchor {
        local_anchor: Checkpoint,
        on_chain_justified: Checkpoint,
        on_chain_finalized: Checkpoint,
    },
}

It can then be passed into:

Store::new(
    anchor_block,
    anchor_state,
    fork_choice_init,
    // ...
)

For finalized checkpoint sync:

justified_checkpoint = anchor;
finalized_checkpoint = anchor;
local_irreversible_checkpoint = anchor;

For non-finalized checkpoint sync:

justified_checkpoint = on_chain_justified;
finalized_checkpoint = on_chain_finalized;
local_irreversible_checkpoint = local_anchor;

This prevents the code from assuming that every startup anchor is finalized.

Local Irreversible Checkpoint

Add a separate local boundary:

local_irreversible_checkpoint: Checkpoint

This represents the earliest ancestor the node is willing to accept.

It should control:

  • rollback protection;
  • descendant checks;
  • forward-sync lower bounds;
  • local pruning;
  • restart recovery.

It should not replace protocol finality in:

  • P2P status;
  • validator checkpoints;
  • Beacon API finalized responses;
  • justified or finalized checkpoint reporting.

Possible accessors:

fn local_irreversible_checkpoint(&self) -> Checkpoint;
fn local_irreversible_epoch(&self) -> Epoch;
fn local_irreversible_root(&self) -> Root;
fn local_irreversible_slot(&self) -> Slot;

CLI Changes

Add:

--checkpoint-sync-state-id <STATE_ID>

The default should remain:

finalized

The first version could support:

finalized
justified
<slot>

Example:

grandine \
  --checkpoint-sync-url <BEACON_NODE_URL> \
  --checkpoint-sync-state-id justified

Or:

grandine \
  --checkpoint-sync-url <BEACON_NODE_URL> \
  --checkpoint-sync-state-id 12345678

Keeping finalized as the default preserves the current behaviour.

Remote Loading

Generalize:

load_finalized_from_remote(...)

into:

load_checkpoint_from_remote(
    config,
    client,
    url,
    state_id,
)

For finalized sync:

  1. Fetch the finalized block.
  2. Find the required epoch-start anchor.
  3. Fetch the matching state.
  4. Validate the block and state.
  5. Return a finalized AnchorCheckpoint.

For non-finalized sync:

  1. Fetch the selected state.
  2. Get its latest block root.
  3. Fetch the matching block.
  4. Validate the block and state.
  5. Validate the network.
  6. Read the real justified and finalized checkpoints.
  7. Build the local anchor.
  8. Return a non-finalized AnchorCheckpoint.

Simplified flow:

async fn load_checkpoint_from_remote<P: Preset>(
    client: &BeaconNodeHttpClient,
    state_id: StateId,
) -> Result<AnchorCheckpoint<P>> {
    match state_id {
        StateId::Finalized => {
            load_finalized_anchor(client).await
        }

        state_id => {
            let state = client.get_state(state_id).await?;
            let anchor_root =
                state.latest_block_header().canonical_root();

            let block = client
                .get_block(BlockId::Root(anchor_root))
                .await?;

            validate_block_state_pair(&block, &state)?;
            validate_network_identity(&state)?;

            let local_anchor = Checkpoint {
                epoch: block.slot().epoch(P::slots_per_epoch()),
                root: anchor_root,
            };

            Ok(AnchorCheckpoint {
                block: Arc::new(block),
                state: Arc::new(state),
                checkpoint: local_anchor,
                origin: AnchorCheckpointOrigin::NonFinalizedCheckpointSync {
                    on_chain_justified:
                        state.current_justified_checkpoint(),
                    on_chain_finalized:
                        state.finalized_checkpoint(),
                },
            })
        }
    }
}

This is only an example of the expected flow, not the final Grandine API.

Epoch Alignment

There are three possible approaches:

  • Require the selected anchor to be at an epoch boundary.
  • Walk backward and load the epoch-start ancestor.
  • Refactor fork choice to support anchors at any slot.

For the first implementation, I think requiring epoch-aligned anchors is the safest option.

It keeps the changes smaller, preserves the current Store::new assumptions and makes testing easier. Arbitrary-slot support can be considered later.

Storage Changes

The local anchor must survive restart, but it should not be stored as finalized history. A possible structure is:

pub struct PersistedAnchorMetadata {
    pub anchor_checkpoint: Checkpoint,
    pub on_chain_justified: Checkpoint,
    pub on_chain_finalized: Checkpoint,
    pub origin: AnchorCheckpointOrigin,
}

Storage should preserve:

  • the anchor block and state;
  • the anchor root and slot;
  • the on-chain justified checkpoint;
  • the on-chain finalized checkpoint;
  • the anchor origin.

On restart, Grandine should restore:

local irreversible checkpoint
real justified checkpoint
real finalized checkpoint

For the first version, the anchor can be stored in a dedicated checkpoint-anchor location instead of redesigning the full storage structure.

Sync Changes

Forward sync should use:

controller.local_irreversible_slot()

as its lower bound.

The local irreversible checkpoint can always exist:

Genesis:
local irreversible = genesis

Finalized checkpoint sync:
local irreversible = finalized anchor

Non-finalized checkpoint sync:
local irreversible = trusted anchor

This allows sync to consistently use the local boundary while protocol status continues using:

controller.finalized_epoch()
controller.finalized_root()

P2P Changes

P2P must continue reporting the real on-chain finalized checkpoint:

controller.finalized_epoch()
controller.finalized_root()

The local anchor should never be presented to peers as finalized.

Internal sync and rollback logic can use:

controller.local_irreversible_epoch()
controller.local_irreversible_root()
controller.local_irreversible_slot()

Beacon API Behaviour

Beacon API semantics should remain unchanged.

Requests such as:

/eth/v2/debug/beacon/states/finalized

must still return the real finalized state, not the local trusted anchor.

Likewise:

BlockId::Finalized
StateId::Finalized

must continue resolving through protocol finality.

A separate local-anchor endpoint is not necessary for the first implementation. It can remain internal or be exposed later through metrics or debug APIs.

My Refactor Plan

Runtime

Add:

--checkpoint-sync-state-id

and pass it into the state-loading strategy:

StateLoadStrategy::Remote {
    checkpoint_sync_url,
    checkpoint_sync_state_id,
}

Possible structure:

enum StateLoadStrategy {
    Auto {
        checkpoint_sync_url: Option<RedactingUrl>,
        checkpoint_sync_state_id: StateId,
    },
    Remote {
        checkpoint_sync_url: RedactingUrl,
        checkpoint_sync_state_id: StateId,
    },
    Anchor {
        block: PathBuf,
        state: PathBuf,
    },
}

Likely files:

runtime/src/grandine_args.rs
runtime/src/runtime.rs
runtime/src/predefined_network.rs

Genesis

Generalize AnchorCheckpointProvider so it can hold any trusted anchor, not only a finalized checkpoint:

pub struct AnchorCheckpointProvider<P: Preset> {
    checkpoint: AnchorCheckpoint<P>,
}

I would prefer keeping the existing provider name if it avoids unnecessary changes.

genesis/src/lib.rs

fork_choice_control

Rename:

load_finalized_from_remote(...)

to something more general:

load_checkpoint_from_remote(...)

Add validation for:

  • state and block consistency;
  • network identity;
  • state ID;
  • epoch alignment;
  • required finalized and justified blocks.

Storage::load should also accept an AnchorCheckpoint instead of a FinalizedCheckpoint.

fork_choice_control/src/checkpoint_sync.rs
fork_choice_control/src/storage.rs

fork_choice_store

Add an explicit initialization mode:

pub enum ForkChoiceInit {
    FinalizedAnchor,
    NonFinalizedAnchor {
        local_anchor: Checkpoint,
        on_chain_justified: Checkpoint,
        on_chain_finalized: Checkpoint,
    },
}

Also add:

local_irreversible_checkpoint: Checkpoint

Fork choice should only accept heads that descend from this local anchor.

Possible helper:

fn is_descendant_of_local_anchor(
    &self,
    block_root: Root,
) -> Result<bool>
fork_choice_store/src/store.rs

P2P

Audit all uses of:

finalized_epoch()
finalized_root()

Each call should be classified as either:

  • protocol finality;
  • local sync boundary.

Protocol-finality usage stays unchanged. Local-boundary usage should move to:

local_irreversible_epoch()
local_irreversible_root()
local_irreversible_slot()

Likely files:

p2p/src/network.rs
p2p/src/block_sync_service.rs
p2p/src/sync_manager.rs

Storage

Persist the trusted anchor separately instead of storing it as finalized history.

On restart, the client should restore both:

  • the local trusted anchor;
  • the on-chain justified and finalized checkpoints.

The first version can use a dedicated metadata key or checkpoint namespace.

fork_choice_control/src/storage.rs
storage-related fork-choice components

Beacon API

Reuse or align the new CLI state ID parser with the existing StateId parser.

The meaning of:

finalized
justified

should remain unchanged for Beacon API requests.

A local-anchor debug endpoint can be considered later, but it is outside the first implementation.

http_api/src/state_id.rs
http_api/src/block_id.rs

Implementation Plan

Design Validation and Checkpoint Loading

No. Goals Tasks
1 Review the proposed anchor model with mentors. Add --checkpoint-sync-state-id.
2 Confirm whether epoch-aligned anchors are acceptable for the first version. Default the value to finalized.
3 Add CLI parsing for the checkpoint-sync state ID. Parse finalized, justified, and slot IDs.
4 Generalize remote checkpoint loading. Introduce AnchorCheckpoint or an equivalent structure.
5 Preserve the existing finalized checkpoint-sync behavior. Generalize load_finalized_from_remote.
6 Add initial tests for checkpoint metadata extraction. Extract the actual finalized and justified checkpoints from the downloaded state.
7 Validate state and block consistency.
8 Add finalized-path regression tests.
9 Add non-finalized anchor-loading tests.

Fork Choice and Sync Integration

No. Goals Tasks
1 Update fork-choice initialization. Add ForkChoiceInit.
2 Add local irreversible checkpoint tracking. Refactor Store::new.
3 Separate protocol-finality queries from local-anchor queries. Add local_irreversible_checkpoint.
4 Update forward-sync lower bounds. Add controller accessors.
5 Preserve correct P2P status semantics. Update forward-sync start logic.
6 Audit P2P finalized-checkpoint usage.
7 Add P2P status tests.
8 Add fork-choice descendant tests.
9 Document the initial limitations.

Stretch goals

Depending on time, review feedback, and implementation complexity:

  • persist non-finalized anchor metadata across restart;
  • enable restart tests from a non-finalized anchor;
  • support head or state-root checkpoint IDs;
  • support derived epoch-start anchors;
  • support limited historical back-sync;
  • add metrics for local anchor slot and root;
  • expose anchor information through a debug endpoint;
  • test recovery during a simulated non-finality scenario;
  • compare behavior with Lighthouse PR #8382.

Testing Strategy

Unit Tests

Finalized Checkpoint Regression

Verify that the existing finalized checkpoint flow remains unchanged:

local anchor = finalized checkpoint
justified checkpoint = anchor
finalized checkpoint = anchor

Non-Finalized Initialization

Verify that:

local irreversible checkpoint = selected anchor
justified checkpoint = state.current_justified_checkpoint()
finalized checkpoint = state.finalized_checkpoint()

State and Block Validation

Reject:

  • block and state mismatches;
  • checkpoints from the wrong network;
  • missing checkpoint blocks;
  • unsupported non-epoch-aligned anchors;
  • invalid state IDs.

Fork-Choice Protection

Verify that fork choice rejects any block or chain that does not descend from the local irreversible anchor.

P2P Status

Verify that P2P status reports the real:

finalized_root
finalized_epoch

and not the local trusted anchor.

Sync Boundary

Verify that forward sync starts from:

local_irreversible_slot

instead of the older finalized slot.

Integration Tests

Finalized Startup

Start Grandine from a finalized checkpoint and confirm the existing sync flow still works.

Non-Finalized Startup

Start from an epoch-aligned non-finalized checkpoint and confirm the node syncs forward correctly.

Restart

Restart the node after non-finalized checkpoint sync and verify that:

  • anchor metadata is restored;
  • real justified and finalized checkpoints are restored;
  • the node does not roll back behind the anchor.

Peer With Older Finality

Simulate a peer whose finalized checkpoint is older than the local anchor, but whose head still descends from it.

Verify that sync continues without treating the local anchor as finalized.

Validator Behaviour

Confirm that validator duties use:

state.current_justified_checkpoint()

for Casper FFG source semantics, not the local irreversible checkpoint.

Negative Tests

Reject:

  • checkpoints from the wrong network;
  • block and state mismatches;
  • missing anchor blocks;
  • unsupported non-epoch-aligned checkpoints;
  • chains that conflict with the local anchor;
  • unresolved justified or finalized checkpoint references;
  • inconsistent anchor metadata after restart.

The main testing areas are startup, fork choice, P2P status, sync boundaries, restart recovery and conflicting-anchor behaviour.

Open questions and concerns

Open Questions

1. Should anchors be epoch-aligned?

Epoch alignment simplifies implementation but reduces checkpoint flexibility.

  • Does Grandine depend on epoch-start anchors?
  • Should the client walk backward or advance the state to an epoch boundary?

2. Where should local irreversibility live?

The current proposal stores local_irreversible_checkpoint in the fork-choice store.

Other options include:

  • fork-choice control;
  • storage metadata;
  • sync controller;
  • a shared anchor service.

The decision depends on which component should enforce ancestry and rollback restrictions.

3. How should the anchor be persisted?

The anchor must survive restarts without being treated as protocol-finalized history.

Possible approaches:

  • a dedicated metadata key;
  • a checkpoint storage namespace;
  • fork-choice state persistence;
  • existing snapshot mechanisms.

4. Should historical back-sync be disabled initially?

Back-sync from a non-finalized anchor introduces trust and state-availability concerns.

A safer rollout may be:

  • Phase 1: Forward sync only.
  • Phase 2: Add historical or back-sync support.

5. How should the CLI expose this mode?

Possible options:

--checkpoint-sync-state-id justified

or:

--checkpoint-sync-non-finalized-state-id <STATE_ID>

The first is more general, while the second makes the trust implications clearer.

6. How should trusted checkpoints be validated?

At minimum, the client should verify:

  • state and block consistency;
  • genesis validators root;
  • epoch alignment;
  • anchor root;
  • finalized and justified checkpoint availability;
  • the intended network.

A non-finalized checkpoint cannot be proven canonical through protocol rules alone. The operator is explicitly trusting the checkpoint source.

7. Should Grandine mirror Lighthouse’s model?

Lighthouse provides a useful separation between local and on-chain checkpoints, but its abstractions may not fit Grandine’s architecture.

The important invariant is:

local trust != protocol finality

8. What happens after the anchor becomes finalized?

Once on-chain finality passes the local anchor:

  • Can the special anchor restriction be removed?
  • Should the local irreversible checkpoint advance?
  • Should anchor metadata be compacted or migrated?
  • Should restarts use the normal finalized-startup path?

These can likely be addressed after the initial implementation.

Main unresolved areas

Epoch alignment, persistence, back-sync scope, CLI design, checkpoint validation, Beacon API semantics, and alignment with the Lighthouse model.

Future Work

Possible follow-up work includes:

Historical Back-Sync

Add safe back-sync from the local anchor to the real finalized checkpoint or another trusted historical boundary.

Multiple Checkpoint Providers

Allow operators to compare checkpoint roots from multiple providers before choosing an anchor.

Non-Finality Recovery

Detect extended non-finality and provide an operator-assisted recovery mode.

The client should never trust a non-finalized checkpoint automatically without clear user approval.

Anchor Metrics

Expose useful anchor information through logs and metrics:

local_anchor_slot
local_anchor_root
on_chain_finalized_epoch
distance_from_finality

Debug API

Add a debug endpoint that shows:

  • anchor origin;
  • local irreversible checkpoint;
  • real justified checkpoint;
  • real finalized checkpoint;
  • whether startup used a non-finalized anchor.

Arbitrary-Slot Anchors

Support non-epoch-aligned anchors after the core design has been tested and validated.

Checkpoint Distribution

Explore decentralized or multi-source ways of distributing recent trusted checkpoints.

Cross-Client Testing

Test Grandine startup using checkpoint data from:

  • Lighthouse;
  • Teku;
  • Nimbus;
  • Prysm;
  • Lodestar;
  • other Grandine nodes.

Resources

Grandine

Lighthouse

Ethereum consensus specifications

Relevant Grandine code paths

runtime/src/grandine_args.rs
runtime/src/runtime.rs
runtime/src/predefined_network.rs

types/src/nonstandard.rs
genesis/src/lib.rs

fork_choice_control/src/checkpoint_sync.rs
fork_choice_control/src/storage.rs

fork_choice_store/src/store.rs

p2p/src/network.rs
p2p/src/block_sync_service.rs
p2p/src/sync_manager.rs

http_api/src/state_id.rs
http_api/src/block_id.rs

Originally published on HackMD . Comments and discussion live there.