From b68e88af2986d2474f16d36b66629ec622b24501 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Wed, 4 Mar 2026 10:31:33 +0800 Subject: [PATCH] triedb/pathdb: return an error if the trienode history is not empty --- triedb/pathdb/history.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/triedb/pathdb/history.go b/triedb/pathdb/history.go index 4883d0d8a9..0a9f7091fa 100644 --- a/triedb/pathdb/history.go +++ b/triedb/pathdb/history.go @@ -429,18 +429,14 @@ func repairHistory(db ethdb.Database, isVerkle bool, readOnly bool, stateID uint if stateID <= thead { truncTo = min(truncTo, thead) } else { - ttail, err := trienodes.Tail() - if err != nil { - return nil, nil, err - } - _, err = trienodes.TruncateTail(stateID) - if err != nil { - return nil, nil, err - } if thead == 0 { + _, err = trienodes.TruncateTail(stateID) + if err != nil { + return nil, nil, err + } log.Warn("Initialized trienode history") } else { - log.Warn("Purged stale trienode history", "from", ttail, "to", thead-1, "count", thead-ttail) + return nil, nil, fmt.Errorf("gap between state [#%d] and trienode history [#%d]", stateID, thead) } } }