From bca21b95a57f178e1ae677f97a656b90d809ec62 Mon Sep 17 00:00:00 2001 From: Vicky Date: Sat, 31 Jan 2026 04:08:24 +0800 Subject: [PATCH] triedb/pathdb: only call postFlush callback on successful buffer flush --- triedb/pathdb/buffer.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/triedb/pathdb/buffer.go b/triedb/pathdb/buffer.go index 853e1090b3..45ff9596a2 100644 --- a/triedb/pathdb/buffer.go +++ b/triedb/pathdb/buffer.go @@ -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() + } }() }