Skip to content

Commit aa94053

Browse files
triedb/pathdb: sync ancient store before journal (ethereum#32557) (ethereum#718)
This pull request addresses the corrupted path database with log indicating: `history head truncation out of range, tail: 122557, head: 212208, target: 212557` This is a rare edge case where the in-memory layers, including the write buffer in the disk layer, are fully persisted (e.g., written to file), but the state history freezer is not properly closed (e.g., Geth is terminated after journaling but before freezer.Close). In this situation, the recent state history writes will be truncated on the next startup, while the in-memory layers resolve correctly. As a result, the state history falls behind the disk layer (including the write buffer). In this pull request, the state history freezer is always synced before journal, ensuring the state history writes are always persisted before the others. Edit: It's confirmed that devops team has 10s container termination setting. It explains why Geth didn't finish the entire termination without state history being closed. https://github.com/ethpandaops/fusaka-devnets/pull/63/files Co-authored-by: rjl493456442 <[email protected]>
1 parent 9a4dd63 commit aa94053

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

triedb/pathdb/journal.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,16 @@ func (db *Database) Journal(root common.Hash) error {
333333
if db.readOnly {
334334
return errDatabaseReadOnly
335335
}
336-
336+
// Forcibly sync the ancient store before persisting the in-memory layers.
337+
// This prevents an edge case where the in-memory layers are persisted
338+
// but the ancient store is not properly closed, resulting in recent writes
339+
// being lost. After a restart, the ancient store would then be misaligned
340+
// with the disk layer, causing data corruption.
341+
if db.stateFreezer != nil {
342+
if err := db.stateFreezer.SyncAncient(); err != nil {
343+
return err
344+
}
345+
}
337346
// Store the journal into the database and return
338347
var (
339348
file *os.File

0 commit comments

Comments
 (0)