mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-13 15:33: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
|
// 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,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue