Skip to content

Commit

Permalink
cmd/geth: adapt pbss
Browse files Browse the repository at this point in the history
  • Loading branch information
fynnss committed Dec 26, 2023
1 parent e2a7dea commit 59d4a47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 13 additions & 1 deletion cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"github.com/ethereum/go-ethereum/internal/flags"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/trie"
"github.com/ethereum/go-ethereum/trie/triedb/pathdb"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
)
Expand Down Expand Up @@ -383,7 +384,18 @@ func inspectTrie(ctx *cli.Context) error {
log.Error("Empty root hash")
}
fmt.Printf("ReadBlockHeader, root: %v, blocknum: %v\n", trieRootHash, blockNumber)
triedb := trie.NewDatabase(db, nil)

dbScheme := rawdb.ReadStateScheme(db)
var config *trie.Config
if dbScheme == rawdb.PathScheme {
config = &trie.Config{
PathDB: pathdb.ReadOnly,
}
} else if dbScheme == rawdb.HashScheme {
config = trie.HashDefaults
}

triedb := trie.NewDatabase(db, config)
theTrie, err := trie.New(trie.TrieID(trieRootHash), triedb)
if err != nil {
fmt.Printf("fail to new trie tree, err: %v, rootHash: %v\n", err, trieRootHash.String())
Expand Down
14 changes: 7 additions & 7 deletions trie/inspect_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func (inspect *Inspector) ConcurrentTraversal(theTrie *Trie, theTrieTreeStat *Tr
if total_num%100000 == 0 {
fmt.Printf("Complete progress: %v, go routines Num: %v, inspect concurrentQueue: %v\n", total_num, runtime.NumGoroutine(), len(inspect.concurrentQueue))
}
log.Info("concurrent traversal", "height", height, "path", common.Bytes2Hex(path))

// nil node
if theNode == nil {
Expand All @@ -212,25 +213,24 @@ func (inspect *Inspector) ConcurrentTraversal(theTrie *Trie, theTrieTreeStat *Tr

switch current := (theNode).(type) {
case *shortNode:
path = append(path, current.Key...)
inspect.ConcurrentTraversal(theTrie, theTrieTreeStat, current.Val, height+1, path)
path = path[:len(path)-len(current.Key)]
inspect.ConcurrentTraversal(theTrie, theTrieTreeStat, current.Val, height, append(path, current.Key...))
case *fullNode:
for idx, child := range current.Children {
if child == nil {
continue
}
childPath := path
childPath = append(childPath, byte(idx))
childPath := append(path, byte(idx))
if len(inspect.concurrentQueue)*2 < cap(inspect.concurrentQueue) {
inspect.wg.Add(1)
go inspect.SubConcurrentTraversal(theTrie, theTrieTreeStat, child, height+1, childPath)
dst := make([]byte, len(childPath))
copy(dst, childPath)
go inspect.SubConcurrentTraversal(theTrie, theTrieTreeStat, child, height+1, dst)
} else {
inspect.ConcurrentTraversal(theTrie, theTrieTreeStat, child, height+1, childPath)
}
}
case hashNode:
n, err := theTrie.resloveWithoutTrack(current, nil)
n, err := theTrie.resloveWithoutTrack(current, path)
if err != nil {
fmt.Printf("Resolve HashNode error: %v, TrieRoot: %v, Height: %v, Path: %v\n", err, theTrie.Hash().String(), height+1, path)
return
Expand Down

0 comments on commit 59d4a47

Please sign in to comment.