Skip to content

Commit 412075b

Browse files
committed
core, trie: fix failed test
1 parent 40ebb2b commit 412075b

File tree

3 files changed

+43
-44
lines changed

3 files changed

+43
-44
lines changed

core/genesis_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,8 +321,7 @@ func TestVerkleGenesisCommit(t *testing.T) {
321321
t.Fatalf("expected trie to be verkle")
322322
}
323323

324-
serialized := rawdb.ReadTrieNode(db, common.Hash{}, []byte{}, common.Hash{}, "path")
325-
if len(serialized) == 0 {
324+
if !rawdb.ExistsAccountTrieNode(db, nil) {
326325
t.Fatal("could not find node")
327326
}
328327
}

trie/trienode/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (n *Node) Size() int {
3939

4040
// IsDeleted returns the indicator if the node is marked as deleted.
4141
func (n *Node) IsDeleted() bool {
42-
return n.Hash == (common.Hash{})
42+
return len(n.Blob) == 0
4343
}
4444

4545
// New constructs a node with provided node information.

trie/verkle.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ type VerkleTrie struct {
4242
reader *trieReader
4343
}
4444

45-
func (vt *VerkleTrie) ToDot() string {
46-
return verkle.ToDot(vt.root)
45+
func (t *VerkleTrie) ToDot() string {
46+
return verkle.ToDot(t.root)
4747
}
4848

4949
func NewVerkleTrie(rootHash common.Hash, root verkle.VerkleNode, db *Database, pointCache *utils.PointCache, ended bool) (*VerkleTrie, error) {
@@ -61,31 +61,31 @@ func NewVerkleTrie(rootHash common.Hash, root verkle.VerkleNode, db *Database, p
6161
}, nil
6262
}
6363

64-
func (trie *VerkleTrie) FlatdbNodeResolver(path []byte) ([]byte, error) {
65-
return trie.reader.reader.Node(trie.reader.owner, path, common.Hash{})
64+
func (t *VerkleTrie) FlatdbNodeResolver(path []byte) ([]byte, error) {
65+
return t.reader.reader.Node(t.reader.owner, path, common.Hash{})
6666
}
6767

6868
var errInvalidRootType = errors.New("invalid node type for root")
6969

7070
// GetKey returns the sha3 preimage of a hashed key that was previously used
7171
// to store a value.
72-
func (trie *VerkleTrie) GetKey(key []byte) []byte {
72+
func (t *VerkleTrie) GetKey(key []byte) []byte {
7373
return key
7474
}
7575

76-
// Get returns the value for key stored in the trie. The value bytes must
77-
// not be modified by the caller. If a node was not found in the database, a
78-
// trie.MissingNodeError is returned.
79-
func (trie *VerkleTrie) GetStorage(addr common.Address, key []byte) ([]byte, error) {
80-
pointEval := trie.pointCache.GetTreeKeyHeader(addr[:])
76+
// GetStorage returns the value for key stored in the trie. The value bytes
77+
// must not be modified by the caller. If a node was not found in the database,
78+
// a trie.MissingNodeError is returned.
79+
func (t *VerkleTrie) GetStorage(addr common.Address, key []byte) ([]byte, error) {
80+
pointEval := t.pointCache.GetTreeKeyHeader(addr[:])
8181
k := utils.GetTreeKeyStorageSlotWithEvaluatedAddress(pointEval, key)
82-
return trie.root.Get(k, trie.FlatdbNodeResolver)
82+
return t.root.Get(k, t.FlatdbNodeResolver)
8383
}
8484

8585
// GetWithHashedKey returns the value, assuming that the key has already
8686
// been hashed.
87-
func (trie *VerkleTrie) GetWithHashedKey(key []byte) ([]byte, error) {
88-
return trie.root.Get(key, trie.FlatdbNodeResolver)
87+
func (t *VerkleTrie) GetWithHashedKey(key []byte) ([]byte, error) {
88+
return t.root.Get(key, t.FlatdbNodeResolver)
8989
}
9090

9191
func (t *VerkleTrie) GetAccount(addr common.Address) (*types.StateAccount, error) {
@@ -161,28 +161,28 @@ func (t *VerkleTrie) UpdateAccount(addr common.Address, acc *types.StateAccount)
161161
return nil
162162
}
163163

164-
func (trie *VerkleTrie) UpdateStem(key []byte, values [][]byte) error {
165-
switch root := trie.root.(type) {
164+
func (t *VerkleTrie) UpdateStem(key []byte, values [][]byte) error {
165+
switch root := t.root.(type) {
166166
case *verkle.InternalNode:
167-
return root.InsertStem(key, values, trie.FlatdbNodeResolver)
167+
return root.InsertStem(key, values, t.FlatdbNodeResolver)
168168
default:
169169
panic("invalid root type")
170170
}
171171
}
172172

173-
// Update associates key with value in the trie. If value has length zero, any
174-
// existing value is deleted from the trie. The value bytes must not be modified
173+
// UpdateStorage associates key with value in the trie. If value has length zero,
174+
// any existing value is deleted from the trie. The value bytes must not be modified
175175
// by the caller while they are stored in the trie. If a node was not found in the
176176
// database, a trie.MissingNodeError is returned.
177-
func (trie *VerkleTrie) UpdateStorage(address common.Address, key, value []byte) error {
178-
k := utils.GetTreeKeyStorageSlotWithEvaluatedAddress(trie.pointCache.GetTreeKeyHeader(address[:]), key)
177+
func (t *VerkleTrie) UpdateStorage(address common.Address, key, value []byte) error {
178+
k := utils.GetTreeKeyStorageSlotWithEvaluatedAddress(t.pointCache.GetTreeKeyHeader(address[:]), key)
179179
var v [32]byte
180180
if len(value) >= 32 {
181181
copy(v[:], value[:32])
182182
} else {
183183
copy(v[32-len(value):], value[:])
184184
}
185-
return trie.root.Insert(k, v[:], trie.FlatdbNodeResolver)
185+
return t.root.Insert(k, v[:], t.FlatdbNodeResolver)
186186
}
187187

188188
func (t *VerkleTrie) DeleteAccount(addr common.Address) error {
@@ -210,19 +210,19 @@ func (t *VerkleTrie) DeleteAccount(addr common.Address) error {
210210
return nil
211211
}
212212

213-
// Delete removes any existing value for key from the trie. If a node was not
214-
// found in the database, a trie.MissingNodeError is returned.
215-
func (trie *VerkleTrie) DeleteStorage(addr common.Address, key []byte) error {
216-
pointEval := trie.pointCache.GetTreeKeyHeader(addr[:])
213+
// DeleteStorage removes any existing value for key from the trie. If a node was
214+
// not found in the database, a trie.MissingNodeError is returned.
215+
func (t *VerkleTrie) DeleteStorage(addr common.Address, key []byte) error {
216+
pointEval := t.pointCache.GetTreeKeyHeader(addr[:])
217217
k := utils.GetTreeKeyStorageSlotWithEvaluatedAddress(pointEval, key)
218218
var zero [32]byte
219-
return trie.root.Insert(k, zero[:], trie.FlatdbNodeResolver)
219+
return t.root.Insert(k, zero[:], t.FlatdbNodeResolver)
220220
}
221221

222222
// Hash returns the root hash of the trie. It does not write to the database and
223223
// can be used even if the trie doesn't have one.
224-
func (trie *VerkleTrie) Hash() common.Hash {
225-
return trie.root.Commit().Bytes()
224+
func (t *VerkleTrie) Hash() common.Hash {
225+
return t.root.Commit().Bytes()
226226
}
227227

228228
func nodeToDBKey(n verkle.VerkleNode) []byte {
@@ -232,8 +232,8 @@ func nodeToDBKey(n verkle.VerkleNode) []byte {
232232

233233
// Commit writes all nodes to the trie's memory database, tracking the internal
234234
// and external (for account tries) references.
235-
func (trie *VerkleTrie) Commit(_ bool) (common.Hash, *trienode.NodeSet, error) {
236-
root, ok := trie.root.(*verkle.InternalNode)
235+
func (t *VerkleTrie) Commit(_ bool) (common.Hash, *trienode.NodeSet, error) {
236+
root, ok := t.root.(*verkle.InternalNode)
237237
if !ok {
238238
return common.Hash{}, nil, errors.New("unexpected root node type")
239239
}
@@ -249,14 +249,14 @@ func (trie *VerkleTrie) Commit(_ bool) (common.Hash, *trienode.NodeSet, error) {
249249
}
250250

251251
// Serialize root commitment form
252-
trie.rootHash = trie.Hash()
253-
return trie.rootHash, nodeset, nil
252+
t.rootHash = t.Hash()
253+
return t.rootHash, nodeset, nil
254254
}
255255

256256
// NodeIterator returns an iterator that returns nodes of the trie. Iteration
257257
// starts at the key after the given start key.
258-
func (trie *VerkleTrie) NodeIterator(startKey []byte) (NodeIterator, error) {
259-
return newVerkleNodeIterator(trie, nil)
258+
func (t *VerkleTrie) NodeIterator(startKey []byte) (NodeIterator, error) {
259+
return newVerkleNodeIterator(t, nil)
260260
}
261261

262262
// Prove constructs a Merkle proof for key. The result contains all encoded nodes
@@ -266,21 +266,21 @@ func (trie *VerkleTrie) NodeIterator(startKey []byte) (NodeIterator, error) {
266266
// If the trie does not contain a value for key, the returned proof contains all
267267
// nodes of the longest existing prefix of the key (at least the root), ending
268268
// with the node that proves the absence of the key.
269-
func (trie *VerkleTrie) Prove(key []byte, proofDb ethdb.KeyValueWriter) error {
269+
func (t *VerkleTrie) Prove(key []byte, proofDb ethdb.KeyValueWriter) error {
270270
panic("not implemented")
271271
}
272272

273-
func (trie *VerkleTrie) Copy() *VerkleTrie {
273+
func (t *VerkleTrie) Copy() *VerkleTrie {
274274
return &VerkleTrie{
275-
root: trie.root.Copy(),
276-
db: trie.db,
277-
pointCache: trie.pointCache,
278-
reader: trie.reader,
275+
root: t.root.Copy(),
276+
db: t.db,
277+
pointCache: t.pointCache,
278+
reader: t.reader,
279279
}
280280
}
281281

282282
// IsVerkle indicates if the trie is a Verkle trie.
283-
func (trie *VerkleTrie) IsVerkle() bool {
283+
func (t *VerkleTrie) IsVerkle() bool {
284284
return true
285285
}
286286

0 commit comments

Comments
 (0)