core/rawdb, eth/downloader: fix stale comments about re-enabling snap sync on rewind

This commit is contained in:
jonny rhea 2026-07-08 15:34:48 -05:00
parent 593b9d82bb
commit af1a52e610
5 changed files with 11 additions and 11 deletions

View file

@ -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 {

View file

@ -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.

View file

@ -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())
}
}

View file

@ -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)
}
}

View file

@ -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 {