triedb/pathdb: only call postFlush callback on successful buffer flush

This commit is contained in:
Vicky 2026-01-31 04:08:24 +08:00
parent cb97c48cb6
commit bca21b95a5

View file

@ -141,12 +141,7 @@ func (b *buffer) flush(root common.Hash, db ethdb.KeyValueStore, freezers []ethd
// Schedule the background thread to construct the batch, which usually
// take a few seconds.
go func() {
defer func() {
if postFlush != nil {
postFlush()
}
close(b.done)
}()
defer close(b.done)
// Ensure the target state id is aligned with the internal counter.
head := rawdb.ReadPersistentStateID(db)
@ -193,6 +188,12 @@ func (b *buffer) flush(root common.Hash, db ethdb.KeyValueStore, freezers []ethd
// protection if try to reset the buffer here.
// b.reset()
log.Debug("Persisted buffer content", "nodes", nodes, "accounts", accounts, "slots", slots, "bytes", common.StorageSize(size), "elapsed", common.PrettyDuration(time.Since(start)))
// Only invoke postFlush callback after successful flush to avoid
// resuming snapshot generator against non-persisted disk state.
if postFlush != nil {
postFlush()
}
}()
}