triedb/pathdb: sync ancient store before journal

This commit is contained in:
Gary Rong 2025-09-09 10:16:24 +08:00
parent 2a3f4cea13
commit 2f21f7279a

View file

@ -333,7 +333,16 @@ func (db *Database) Journal(root common.Hash) error {
if db.readOnly {
return errDatabaseReadOnly
}
// Forcibly sync the ancient store before persisting the in-memory layers.
// This prevents an edge case where the in-memory layers are persisted
// but the ancient store is not properly closed, resulting in recent writes
// being lost. After a restart, the ancient store would then be misaligned
// with the disk layer, causing data corruption.
if db.stateFreezer != nil {
if err := db.stateFreezer.SyncAncient(); err != nil {
return err
}
}
// Store the journal into the database and return
var (
file *os.File