triedb: manually truncate ancient db

Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
jsvisa 2025-06-20 19:25:13 +08:00
parent cbf0b5bc92
commit f5183eb1db
2 changed files with 17 additions and 4 deletions

View file

@ -280,6 +280,17 @@ func (db *Database) Recover(target common.Hash) error {
return pdb.Recover(target) return pdb.Recover(target)
} }
// TruncateHead truncates all state histories in the freezer above the bottom state layer.
// This operation is only supported by path-based database It's typically used during
// state recovery to align the state histories with the current state.
func (db *Database) TruncateHead() error {
pdb, ok := db.backend.(*pathdb.Database)
if !ok {
return errors.New("not supported")
}
return pdb.TruncateHead()
}
// Recoverable returns the indicator if the specified state is enabled to be // Recoverable returns the indicator if the specified state is enabled to be
// recovered. It's only supported by path-based database and will return an // recovered. It's only supported by path-based database and will return an
// error for others. // error for others.

View file

@ -502,14 +502,16 @@ func (db *Database) Recover(root common.Hash) error {
if err := db.diskdb.SyncKeyValue(); err != nil { if err := db.diskdb.SyncKeyValue(); err != nil {
return err return err
} }
_, err := truncateFromHead(db.stateFreezer, dl.stateID())
if err != nil {
return err
}
log.Debug("Recovered state", "root", root, "elapsed", common.PrettyDuration(time.Since(start))) log.Debug("Recovered state", "root", root, "elapsed", common.PrettyDuration(time.Since(start)))
return nil return nil
} }
// TruncateHead truncates all state histories in the freezer above the bottom state layer.
func (db *Database) TruncateHead() error {
_, err := truncateFromHead(db.stateFreezer, db.tree.bottom().stateID())
return err
}
// Recoverable returns the indicator if the specified state is recoverable. // Recoverable returns the indicator if the specified state is recoverable.
// //
// The supplied root must be a valid trie hash value. // The supplied root must be a valid trie hash value.