diff --git a/cmd/geth/dbcmd.go b/cmd/geth/dbcmd.go index d29e2d2101..143686067f 100644 --- a/cmd/geth/dbcmd.go +++ b/cmd/geth/dbcmd.go @@ -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" ) @@ -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()) diff --git a/trie/inspect_trie.go b/trie/inspect_trie.go index f9dad7bd98..fd05229414 100644 --- a/trie/inspect_trie.go +++ b/trie/inspect_trie.go @@ -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 { @@ -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