trie/triedb/pathdb: fix initialization flaws

This commit is contained in:
Martin Holst Swende 2023-12-21 11:00:39 +01:00
parent 435bed5da0
commit 8d22d9a3b3
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0
2 changed files with 7 additions and 2 deletions

View file

@ -431,6 +431,9 @@ func (db *Database) Initialized(genesisRoot common.Hash) bool {
inited = true inited = true
} }
}) })
if !inited {
inited = rawdb.ReadSnapSyncStatusFlag(db.diskdb) != rawdb.StateSyncUnknown
}
return inited return inited
} }

View file

@ -576,9 +576,11 @@ func truncateFromHead(db ethdb.Batcher, freezer *rawdb.ResettableFreezer, nhead
return 0, err return 0, err
} }
// Ensure that the truncation target falls within the specified range. // Ensure that the truncation target falls within the specified range.
if nhead != 0 { // truncating to zero is always possible
if ohead < nhead || nhead < otail { if ohead < nhead || nhead < otail {
return 0, fmt.Errorf("out of range, tail: %d, head: %d, target: %d", otail, ohead, nhead) return 0, fmt.Errorf("out of range, tail: %d, head: %d, target: %d", otail, ohead, nhead)
} }
}
// Short circuit if nothing to truncate. // Short circuit if nothing to truncate.
if ohead == nhead { if ohead == nhead {
return 0, nil return 0, nil