From 6f8293d272317053ed43b1b48935f875b9f4cebd Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Fri, 14 Mar 2025 14:57:42 +0100 Subject: [PATCH] update based on freeezr --- cmd/geth/chaincmd.go | 2 +- core/rawdb/database.go | 25 ++++++++----------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index a3e51796d0..e915e0e6cb 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -665,7 +665,7 @@ func pruneHistory(ctx *cli.Context) error { // TODO(s1na): what if there is a crash between the two prune operations? // 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) } diff --git a/core/rawdb/database.go b/core/rawdb/database.go index c3bafdfe76..4c87e66cfd 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -222,25 +222,16 @@ func NewDatabaseWithFreezer(db ethdb.KeyValueStore, ancient string, namespace st // it to the freezer content. if kvgenesis, _ := db.Get(headerHashKey(0)); len(kvgenesis) > 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 { printChainMetadata(db) - return nil, fmt.Errorf("failed to retrieve tail from freezer %v", err) - } - // If tail > 0, the history has been pruned and genesis block is not anymore in the freezer. - // TODO: we need another way to verify the network for kvdb and freezer match. - 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) - } + 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 // are contiguous, otherwise we might end up with a non-functional freezer.