eth/protocols/snap: advance catch-up pivot after batch commit (#35463)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

This commit is contained in:
daixiheguu 2026-08-08 16:24:04 +08:00 committed by GitHub
parent 2a439ba452
commit 7e520c4310
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -918,16 +918,18 @@ func (s *syncerV2) catchUp(target *types.Header, cancel chan struct{}) error {
}
// Persist incremental progress so a crash mid-catchUp can resume
// from the next unapplied block.
s.lock.Lock()
s.pivot = headers[hash]
s.lock.Unlock()
s.saveSyncStatusWithDB(batch)
// from the next unapplied block. Serialize the next pivot without
// advancing the in-memory pivot until the batch has committed.
nextPivot := headers[hash]
s.saveSyncStatusWith(batch, nextPivot)
// Commit the state transition alongside the sync progress atomically.
if err := batch.Write(); err != nil {
return err
}
s.lock.Lock()
s.pivot = nextPivot
s.lock.Unlock()
}
log.Info("BAL catch-up progress", "applied", end, "target", to, "remaining", to-end)
}
@ -1414,11 +1416,12 @@ func (s *syncerV2) resetSyncState() {
// saveSyncStatus marshals the remaining sync tasks into db.
func (s *syncerV2) saveSyncStatus() {
s.saveSyncStatusWithDB(s.db)
s.saveSyncStatusWith(s.db, s.pivot)
}
// saveSyncStatusWithDB marshals the remaining sync tasks into the given database.
func (s *syncerV2) saveSyncStatusWithDB(db ethdb.KeyValueWriter) {
// saveSyncStatusWith marshals the remaining sync tasks alongside the provided
// pivot header into the database.
func (s *syncerV2) saveSyncStatusWith(db ethdb.KeyValueWriter, pivot *types.Header) {
// Serialize any partial progress to disk before spinning down
for _, task := range s.tasks {
// Save the account hashes of completed storage.
@ -1432,7 +1435,7 @@ func (s *syncerV2) saveSyncStatusWithDB(db ethdb.KeyValueWriter) {
}
// Store the actual progress markers.
progress := &syncProgressV2{
Pivot: s.pivot,
Pivot: pivot,
Tasks: s.tasks,
Phase: s.getPhase(),
AccountSynced: s.accountSynced,