mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-08 13:03:47 +00:00
eth/protocols/snap: advance catch-up pivot after batch commit (#35463)
This commit is contained in:
parent
2a439ba452
commit
7e520c4310
1 changed files with 12 additions and 9 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue