Commit 1b3bc386 authored by George Hotz's avatar George Hotz

parse trie better

parent 04ff70f6
...@@ -42,7 +42,7 @@ func getTrieNode(str common.Hash, interpreter *vm.EVMInterpreter, statedb *State ...@@ -42,7 +42,7 @@ func getTrieNode(str common.Hash, interpreter *vm.EVMInterpreter, statedb *State
ret, err := interpreter.Run(contract, input, false) ret, err := interpreter.Run(contract, input, false)
check(err) check(err)
fmt.Println("getTrieNode", str, ret) //fmt.Println("getTrieNode", str, ret)
return ret[64:] return ret[64:]
} }
......
...@@ -7,7 +7,7 @@ import ( ...@@ -7,7 +7,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
) )
func TestFull(t *testing.T) { func TestFullSlow(t *testing.T) {
RunFull() RunFull()
} }
......
...@@ -54,18 +54,10 @@ func (kw PreimageKeyValueWriter) Delete(key []byte) error { ...@@ -54,18 +54,10 @@ func (kw PreimageKeyValueWriter) Delete(key []byte) error {
return nil return nil
} }
// full nodes / BRANCH_NODE have 17 values, each a hash func ParseNodeInternal(elems []byte, depth int, callback func(common.Hash) []byte) {
// LEAF or EXTENSION nodes have 2 values, a path and value
func ParseNode(node common.Hash, depth int, callback func(common.Hash) []byte) {
if depth > 3 {
return
}
sprefix := strings.Repeat(" ", depth) sprefix := strings.Repeat(" ", depth)
buf := callback(node)
elems, _, err := rlp.SplitList(buf)
check(err)
c, _ := rlp.CountValues(elems) c, _ := rlp.CountValues(elems)
fmt.Println(sprefix, "parsing", node, depth, "elements", c) fmt.Println(sprefix, "parsing", depth, "elements", c)
rest := elems rest := elems
for i := 0; i < c; i++ { for i := 0; i < c; i++ {
kind, val, lrest, err := rlp.Split(rest) kind, val, lrest, err := rlp.Split(rest)
...@@ -74,12 +66,27 @@ func ParseNode(node common.Hash, depth int, callback func(common.Hash) []byte) { ...@@ -74,12 +66,27 @@ func ParseNode(node common.Hash, depth int, callback func(common.Hash) []byte) {
fmt.Println(sprefix, i, kind, val, len(val)) fmt.Println(sprefix, i, kind, val, len(val))
if len(val) == 32 { if len(val) == 32 {
hh := common.BytesToHash(val) hh := common.BytesToHash(val)
fmt.Println(sprefix, "node found with len", len(Preimages[hh])) //fmt.Println(sprefix, "node found with len", len(Preimages[hh]))
ParseNode(hh, depth+1, callback) ParseNode(hh, depth+1, callback)
} }
if kind == rlp.List && len(val) > 0 && len(val) < 32 {
ParseNodeInternal(val, depth+1, callback)
}
} }
} }
// full nodes / BRANCH_NODE have 17 values, each a hash
// LEAF or EXTENSION nodes have 2 values, a path and value
func ParseNode(node common.Hash, depth int, callback func(common.Hash) []byte) {
if depth > 4 {
return
}
buf := callback(node)
elems, _, err := rlp.SplitList(buf)
check(err)
ParseNodeInternal(elems, depth, callback)
}
func RamToTrie(ram map[uint32](uint32)) common.Hash { func RamToTrie(ram map[uint32](uint32)) common.Hash {
mt := trie.NewStackTrie(PreimageKeyValueWriter{}) mt := trie.NewStackTrie(PreimageKeyValueWriter{})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment