update based on freeezr

This commit is contained in:
Sina Mahmoodi 2025-03-14 14:57:42 +01:00 committed by Felix Lange
parent e933ed48a8
commit 6f8293d272
2 changed files with 9 additions and 18 deletions

View file

@ -665,7 +665,7 @@ func pruneHistory(ctx *cli.Context) error {
// TODO(s1na): what if there is a crash between the two prune operations? // TODO(s1na): what if there is a crash between the two prune operations?
// Truncate everything up to merge block // Truncate everything up to merge block
if _, err := chaindb.TruncateTail(mergeBlock); err != nil { if _, err := chaindb.TruncateTailBlocks(mergeBlock); err != nil {
return fmt.Errorf("failed to truncate ancient data: %v", err) return fmt.Errorf("failed to truncate ancient data: %v", err)
} }

View file

@ -222,25 +222,16 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace st
// it to the freezer content. // it to the freezer content.
if kvgenesis, _ := db.Get(headerHashKey(0)); len(kvgenesis) > 0 { if kvgenesis, _ := db.Get(headerHashKey(0)); len(kvgenesis) > 0 {
if frozen, _ := frdb.Ancients(); frozen > 0 { if frozen, _ := frdb.Ancients(); frozen > 0 {
tail, err := frdb.Tail() // If the freezer already contains something, ensure that the genesis blocks
// match, otherwise we might mix up freezers across chains and destroy both
// the freezer and the key-value store.
frgenesis, err := frdb.Ancient(ChainFreezerHashTable, 0)
if err != nil { if err != nil {
printChainMetadata(db) printChainMetadata(db)
return nil, fmt.Errorf("failed to retrieve tail from freezer %v", err) return nil, fmt.Errorf("failed to retrieve genesis from ancient %v", err)
} } else if !bytes.Equal(kvgenesis, frgenesis) {
// If tail > 0, the history has been pruned and genesis block is not anymore in the freezer. printChainMetadata(db)
// TODO: we need another way to verify the network for kvdb and freezer match. return nil, fmt.Errorf("genesis mismatch: %#x (leveldb) != %#x (ancients)", kvgenesis, frgenesis)
if tail == 0 {
// If the freezer already contains something, ensure that the genesis blocks
// match, otherwise we might mix up freezers across chains and destroy both
// the freezer and the key-value store.
frgenesis, err := frdb.Ancient(ChainFreezerHashTable, 0)
if err != nil {
printChainMetadata(db)
return nil, fmt.Errorf("failed to retrieve genesis from ancient %v", err)
} else if !bytes.Equal(kvgenesis, frgenesis) {
printChainMetadata(db)
return nil, fmt.Errorf("genesis mismatch: %#x (leveldb) != %#x (ancients)", kvgenesis, frgenesis)
}
} }
// Key-value store and freezer belong to the same network. Ensure that they // Key-value store and freezer belong to the same network. Ensure that they
// are contiguous, otherwise we might end up with a non-functional freezer. // are contiguous, otherwise we might end up with a non-functional freezer.