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 // 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 // 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 // is written during snap sync and never cleared, so that a rewind below the
// pivot can re-enable snap sync. // pivot can be detected.
func ReadLastPivotNumber(db ethdb.KeyValueReader) *uint64 { func ReadLastPivotNumber(db ethdb.KeyValueReader) *uint64 {
data, _ := db.Get(lastPivotKey) data, _ := db.Get(lastPivotKey)
if len(data) == 0 { if len(data) == 0 {

View file

@ -46,7 +46,7 @@ var (
// persistentStateIDKey tracks the id of latest stored state(for path-based only). // persistentStateIDKey tracks the id of latest stored state(for path-based only).
persistentStateIDKey = []byte("LastStateID") 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") lastPivotKey = []byte("LastPivot")
// fastTrieProgressKey tracks the number of trie entries imported during fast sync. // 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 return errNoPivotHeader
} }
// Write out the pivot into the database so a rollback beyond // Write out the pivot into the database so a rollback beyond
// it will reenable snap sync and update the state root that // it can be detected, and update the state root that the
// the state syncer will be downloading // state syncer will be downloading
rawdb.WriteLastPivotNumber(d.stateDB, d.pivotHeader.Number.Uint64()) rawdb.WriteLastPivotNumber(d.stateDB, d.pivotHeader.Number.Uint64())
} }
} }

View file

@ -542,8 +542,8 @@ func (d *Downloader) syncToHead() (err error) {
if pivotNumber <= origin { if pivotNumber <= origin {
origin = pivotNumber - 1 origin = pivotNumber - 1
} }
// Write out the pivot into the database so a rollback beyond it will // Write out the pivot into the database so a rollback beyond it
// reenable snap sync // can be detected
rawdb.WriteLastPivotNumber(d.stateDB, pivotNumber) 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 // 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. // block is ahead, so snap sync was enabled for this node at a certain point.
// The scenarios where this can happen is // The scenarios where this can happen is
// * if the user manually (or via a bad block) rolled back a snap sync node // * if an internal reset (a fork config change or corruption recovery)
// below the sync point. // rolled a snap sync node back below the sync point.
// * the last snap sync is not finished while user specifies a full sync this // * 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. // time. But we don't have any recent state for full sync.
// In these cases however it's safe to reenable snap 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 { if report {
logger = log.Info logger = log.Info
} }
// We are probably in full sync, but we might have rewound to before the // We are probably in full sync, but an internal reset may have rewound the
// snap sync pivot, check if we should re-enable snap sync. // chain below the snap sync pivot, check if we should re-enable snap sync.
head := m.chain.CurrentBlock() head := m.chain.CurrentBlock()
if pivot := rawdb.ReadLastPivotNumber(m.disk); pivot != nil { if pivot := rawdb.ReadLastPivotNumber(m.disk); pivot != nil {
if head.Number.Uint64() < *pivot { if head.Number.Uint64() < *pivot {