Skip to content

Commit a26a5d5

Browse files
committed
it works now in dev mode
1 parent fa51e56 commit a26a5d5

File tree

9 files changed

+37
-21
lines changed

9 files changed

+37
-21
lines changed

core/state/statedb.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,6 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
902902
}
903903
}
904904
}
905-
workers.Wait()
906905
s.StorageUpdates += time.Since(start)
907906

908907
// Now we're about to start to write changes to the trie. The trie is so far
@@ -970,6 +969,7 @@ func (s *StateDB) IntermediateRoot(deleteEmptyObjects bool) common.Hash {
970969
s.witnessStats.Add(witness, common.Hash{})
971970
}
972971
}
972+
973973
return hash
974974
}
975975

trie/committer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ func (c *committer) store(path []byte, n node) node {
158158
if c.collectLeaf {
159159
if sn, ok := n.(*shortNode); ok {
160160
if val, ok := sn.Val.(valueNode); ok {
161-
c.nodes.AddLeaf(nhash, val())
161+
c.nodes.AddLeaf(nhash, val.resolve())
162162
}
163163
}
164164
}
@@ -182,7 +182,7 @@ func forGatherChildren(n node, onChild func(hash common.Hash)) {
182182
}
183183
case hashNode:
184184
onChild(common.BytesToHash(n))
185-
case valueNode, nil:
185+
case *valueNode, nil:
186186
default:
187187
panic(fmt.Sprintf("unknown node type: %T", n))
188188
}

trie/hasher.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func (h *hasher) encodeShortNode(n *shortNode) []byte {
110110
if hasTerm(n.Key) {
111111
var ln leafNodeEncoder
112112
ln.Key = hexToCompact(n.Key)
113-
ln.Val = n.Val.(valueNode)()
113+
ln.Val = n.Val.(*valueNode).resolve()
114114
ln.encode(h.encbuf)
115115
return h.encodedBytes()
116116
}
@@ -162,7 +162,7 @@ func (h *hasher) encodeFullNode(n *fullNode) []byte {
162162
}
163163
}
164164
if n.Children[16] != nil {
165-
fn.Children[16] = n.Children[16].(valueNode)()
165+
fn.Children[16] = n.Children[16].(*valueNode).resolve()
166166
}
167167
fn.encode(h.encbuf)
168168
fnEncoderPool.Put(fn)

trie/iterator.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ func (it *nodeIterator) LeafKey() []byte {
224224

225225
func (it *nodeIterator) LeafBlob() []byte {
226226
if len(it.stack) > 0 {
227-
if node, ok := it.stack[len(it.stack)-1].node.(valueNode); ok {
228-
return node()
227+
if node, ok := it.stack[len(it.stack)-1].node.(*valueNode); ok {
228+
return node.resolve()
229229
}
230230
}
231231
panic("not at leaf")

trie/node.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ type (
4444
flags nodeFlag
4545
}
4646
hashNode []byte
47-
valueNode func() []byte
47+
valueNode struct {
48+
resolver func() []byte
49+
val []byte
50+
}
4851

4952
// fullnodeEncoder is a type used exclusively for encoding fullNode.
5053
// Briefly instantiating a fullnodeEncoder and initializing with
@@ -68,6 +71,19 @@ type (
6871
}
6972
)
7073

74+
func newValueNode(resolver func() []byte) *valueNode {
75+
return &valueNode{
76+
resolver: resolver,
77+
}
78+
}
79+
80+
func (v *valueNode) resolve() []byte {
81+
if v.val == nil {
82+
v.val = v.resolver()
83+
}
84+
return v.val
85+
}
86+
7187
// EncodeRLP encodes a full node into the consensus RLP format.
7288
func (n *fullNode) EncodeRLP(w io.Writer) error {
7389
eb := rlp.NewEncoderBuffer(w)
@@ -118,7 +134,7 @@ func (n hashNode) fstring(ind string) string {
118134
return fmt.Sprintf("<%x> ", []byte(n))
119135
}
120136
func (n valueNode) fstring(ind string) string {
121-
return fmt.Sprintf("%x ", n())
137+
return fmt.Sprintf("%x ", n.resolve())
122138
}
123139

124140
// mustDecodeNode is a wrapper of decodeNode and panic if any error is encountered.
@@ -185,7 +201,7 @@ func decodeShort(hash, elems []byte) (node, error) {
185201
if err != nil {
186202
return nil, fmt.Errorf("invalid value node: %v", err)
187203
}
188-
return &shortNode{key, valueNode(func() []byte { return val }), flag}, nil
204+
return &shortNode{key, newValueNode(func() []byte { return val }), flag}, nil
189205
}
190206
r, _, err := decodeRef(rest)
191207
if err != nil {
@@ -208,7 +224,7 @@ func decodeFull(hash, elems []byte) (*fullNode, error) {
208224
return n, err
209225
}
210226
if len(val) > 0 {
211-
n.Children[16] = valueNode(func() []byte { return val })
227+
n.Children[16] = newValueNode(func() []byte { return val })
212228
}
213229
return n, nil
214230
}

trie/node_enc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,5 @@ func (n hashNode) encode(w rlp.EncoderBuffer) {
102102
}
103103

104104
func (n valueNode) encode(w rlp.EncoderBuffer) {
105-
w.WriteBytes(n())
105+
w.WriteBytes(n.resolve())
106106
}

trie/proof.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func VerifyProof(rootHash common.Hash, key []byte, proofDb ethdb.KeyValueReader)
129129
key = keyrest
130130
copy(wantHash[:], cld)
131131
case valueNode:
132-
return cld(), nil
132+
return cld.resolve(), nil
133133
}
134134
}
135135
}
@@ -192,7 +192,7 @@ func proofToPath(rootHash common.Hash, root node, key []byte, proofDb ethdb.KeyV
192192
return nil, nil, err
193193
}
194194
case valueNode:
195-
valnode = cld()
195+
valnode = cld.resolve()
196196
}
197197
// Link the parent and child.
198198
switch pnode := parent.(type) {

trie/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ func (s *Sync) children(req *nodeRequest, object node) ([]*nodeRequest, error) {
620620
paths = append(paths, hexToKeybytes(child.path[:2*common.HashLength]))
621621
paths = append(paths, hexToKeybytes(child.path[2*common.HashLength:]))
622622
}
623-
if err := req.callback(paths, child.path, node(), req.hash, req.path); err != nil {
623+
if err := req.callback(paths, child.path, node.resolve(), req.hash, req.path); err != nil {
624624
return nil, err
625625
}
626626
}

trie/trie.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ func (t *Trie) get(origNode node, key []byte, pos int) (value []byte, newnode no
193193
switch n := (origNode).(type) {
194194
case nil:
195195
return nil, nil, false, nil
196-
case valueNode:
197-
return n(), n, false, nil
196+
case *valueNode:
197+
return n.resolve(), n, false, nil
198198
case *shortNode:
199199
if !bytes.HasPrefix(key[pos:], n.Key) {
200200
// key not found in trie
@@ -388,7 +388,7 @@ func (t *Trie) UpdateAsync(key []byte, valueResolver func() []byte) error {
388388
k := keybytesToHex(key)
389389

390390
// NOTE: this does not support deletions (the length of the value is not known until it is resolved)
391-
_, n, err := t.insert(t.root, nil, k, valueNode(valueResolver))
391+
_, n, err := t.insert(t.root, nil, k, newValueNode(valueResolver))
392392
if err != nil {
393393
return err
394394
}
@@ -401,7 +401,7 @@ func (t *Trie) update(key, value []byte) error {
401401
t.uncommitted++
402402
k := keybytesToHex(key)
403403
if len(value) != 0 {
404-
_, n, err := t.insert(t.root, nil, k, valueNode(func() []byte { return value }))
404+
_, n, err := t.insert(t.root, nil, k, newValueNode(func() []byte { return value }))
405405
if err != nil {
406406
return err
407407
}
@@ -657,8 +657,8 @@ func copyNode(n node) node {
657657
switch n := (n).(type) {
658658
case nil:
659659
return nil
660-
case valueNode:
661-
return valueNode(func() []byte { return common.CopyBytes(n()) })
660+
case *valueNode:
661+
return newValueNode(func() []byte { return common.CopyBytes(n.resolve()) })
662662

663663
case *shortNode:
664664
return &shortNode{

0 commit comments

Comments
 (0)