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