From 8e0d63b5f72c6de7d709353ee71f1ba0b931e7ec Mon Sep 17 00:00:00 2001 From: Chris Li <271678682li@gmail.com> Date: Fri, 26 Jul 2024 13:28:12 +0800 Subject: [PATCH] fix: fix inspect proof & preimages --- core/rawdb/ancient_utils.go | 10 ++++++---- core/rawdb/database.go | 25 +++---------------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/core/rawdb/ancient_utils.go b/core/rawdb/ancient_utils.go index 2f7fd466c7..6697d5975b 100644 --- a/core/rawdb/ancient_utils.go +++ b/core/rawdb/ancient_utils.go @@ -22,6 +22,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/log" ) type tableSize struct { @@ -82,17 +83,17 @@ func inspectFreezers(db ethdb.Database) ([]freezerInfo, error) { for _, freezer := range freezers { switch freezer { case ChainFreezerName: - info, err := inspect(ChainFreezerName, chainFreezerNoSnappy, db) + info, err := inspect(ChainFreezerName, chainFreezerNoSnappy, db.BlockStore()) if err != nil { return nil, err } infos = append(infos, info) case StateFreezerName: - if ReadStateScheme(db) != PathScheme || db.StateStore() != nil { + if ReadStateScheme(db) != PathScheme { continue } - datadir, err := db.AncientDatadir() + datadir, err := db.StateStore().AncientDatadir() if err != nil { return nil, err } @@ -118,7 +119,8 @@ func inspectFreezers(db ethdb.Database) ([]freezerInfo, error) { } f, err := NewProofFreezer(datadir, true) if err != nil { - return nil, err + log.Warn("If proof keeper is not enabled, there will be no ProofFreezer.") + return nil, nil } defer f.Close() diff --git a/core/rawdb/database.go b/core/rawdb/database.go index 37d5a2c2ca..7bd2f2e52e 100644 --- a/core/rawdb/database.go +++ b/core/rawdb/database.go @@ -801,6 +801,8 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { accountTries.Add(size) case IsStorageTrieNode(key): storageTries.Add(size) + case bytes.HasPrefix(key, PreimagePrefix) && len(key) == (len(PreimagePrefix)+common.HashLength): + preimages.Add(size) default: var accounted bool for _, meta := range [][]byte{ @@ -895,7 +897,7 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { {"Light client", "Bloom trie nodes", bloomTrieNodes.Size(), bloomTrieNodes.Count()}, } // Inspect all registered append-only file store then. - ancients, err := inspectFreezers(db.BlockStore()) + ancients, err := inspectFreezers(db) if err != nil { return err } @@ -911,27 +913,6 @@ func InspectDatabase(db ethdb.Database, keyPrefix, keyStart []byte) error { total += ancient.size() } - // inspect ancient state in separate trie db if exist - if trieIter != nil { - stateAncients, err := inspectFreezers(db.StateStore()) - if err != nil { - return err - } - for _, ancient := range stateAncients { - for _, table := range ancient.sizes { - if ancient.name == "chain" { - break - } - stats = append(stats, []string{ - fmt.Sprintf("Ancient store (%s)", strings.Title(ancient.name)), - strings.Title(table.name), - table.size.String(), - fmt.Sprintf("%d", ancient.count()), - }) - } - total += ancient.size() - } - } table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"Database", "Category", "Size", "Items"}) table.SetFooter([]string{"", "Total", total.String(), " "})