From af1a52e610324ace9c9cb055b59d00f7ab99fb9c Mon Sep 17 00:00:00 2001 From: jonny rhea <5555162+jrhea@users.noreply.github.com> Date: Wed, 8 Jul 2026 15:34:48 -0500 Subject: [PATCH] core/rawdb, eth/downloader: fix stale comments about re-enabling snap sync on rewind --- core/rawdb/accessors_chain.go | 4 ++-- core/rawdb/schema.go | 2 +- eth/downloader/beaconsync.go | 4 ++-- eth/downloader/downloader.go | 4 ++-- eth/downloader/syncmode.go | 8 ++++---- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go index d8825b6b8f..e82a15877e 100644 --- a/core/rawdb/accessors_chain.go +++ b/core/rawdb/accessors_chain.go @@ -176,8 +176,8 @@ func WriteFinalizedBlockHash(db ethdb.KeyValueWriter, hash common.Hash) { // ReadLastPivotNumber retrieves the number of the last pivot block. If the node // has never attempted snap sync, the last pivot will always be nil. The marker -// is written during snap sync and never cleared, so that a rollback past the -// pivot can re-enable snap sync. +// is written during snap sync and never cleared, so that a rewind below the +// pivot can be detected. func ReadLastPivotNumber(db ethdb.KeyValueReader) *uint64 { data, _ := db.Get(lastPivotKey) if len(data) == 0 { diff --git a/core/rawdb/schema.go b/core/rawdb/schema.go index 54c76143b4..ec72294354 100644 --- a/core/rawdb/schema.go +++ b/core/rawdb/schema.go @@ -46,7 +46,7 @@ var ( // persistentStateIDKey tracks the id of latest stored state(for path-based only). persistentStateIDKey = []byte("LastStateID") - // lastPivotKey tracks the last pivot block used by fast sync (to reenable on sethead). + // lastPivotKey tracks the last pivot block used by snap sync (to reject sethead below it). lastPivotKey = []byte("LastPivot") // fastTrieProgressKey tracks the number of trie entries imported during fast sync. diff --git a/eth/downloader/beaconsync.go b/eth/downloader/beaconsync.go index 246fe7637b..2905b664ed 100644 --- a/eth/downloader/beaconsync.go +++ b/eth/downloader/beaconsync.go @@ -333,8 +333,8 @@ func (d *Downloader) fetchHeaders(from uint64) error { return errNoPivotHeader } // Write out the pivot into the database so a rollback beyond - // it will reenable snap sync and update the state root that - // the state syncer will be downloading + // it can be detected, and update the state root that the + // state syncer will be downloading rawdb.WriteLastPivotNumber(d.stateDB, d.pivotHeader.Number.Uint64()) } } diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 60b04e945b..876115ea97 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -542,8 +542,8 @@ func (d *Downloader) syncToHead() (err error) { if pivotNumber <= origin { origin = pivotNumber - 1 } - // Write out the pivot into the database so a rollback beyond it will - // reenable snap sync + // Write out the pivot into the database so a rollback beyond it + // can be detected rawdb.WriteLastPivotNumber(d.stateDB, pivotNumber) } } diff --git a/eth/downloader/syncmode.go b/eth/downloader/syncmode.go index 036119ce3d..a7792eb5fc 100644 --- a/eth/downloader/syncmode.go +++ b/eth/downloader/syncmode.go @@ -40,8 +40,8 @@ func newSyncModer(mode ethconfig.SyncMode, chain BlockChain, disk ethdb.KeyValue // The database seems empty as the current block is the genesis. Yet the snap // block is ahead, so snap sync was enabled for this node at a certain point. // The scenarios where this can happen is - // * if the user manually (or via a bad block) rolled back a snap sync node - // below the sync point. + // * if an internal reset (a fork config change or corruption recovery) + // rolled a snap sync node back below the sync point. // * the last snap sync is not finished while user specifies a full sync this // time. But we don't have any recent state for full sync. // In these cases however it's safe to reenable snap sync. @@ -87,8 +87,8 @@ func (m *syncModer) get(report bool) ethconfig.SyncMode { if report { logger = log.Info } - // We are probably in full sync, but we might have rewound to before the - // snap sync pivot, check if we should re-enable snap sync. + // We are probably in full sync, but an internal reset may have rewound the + // chain below the snap sync pivot, check if we should re-enable snap sync. head := m.chain.CurrentBlock() if pivot := rawdb.ReadLastPivotNumber(m.disk); pivot != nil { if head.Number.Uint64() < *pivot {