Skip to content

Commit

Permalink
fix: fix inspect proof & preimages
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjunLi committed Jul 26, 2024
1 parent 9596fd2 commit 8e0d63b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 26 deletions.
10 changes: 6 additions & 4 deletions core/rawdb/ancient_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand All @@ -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()

Expand Down
25 changes: 3 additions & 22 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
Expand All @@ -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(), " "})
Expand Down

0 comments on commit 8e0d63b

Please sign in to comment.