Skip to content

Commit 36c4b31

Browse files
committed
address comments
1 parent cd68f54 commit 36c4b31

File tree

9 files changed

+63
-31
lines changed

9 files changed

+63
-31
lines changed

core/felt/utils.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package felt
22

3-
func IsZero[F FeltLike](v *F) bool {
4-
f := Felt(*v)
3+
func IsZero[F FeltLike](v F) bool {
4+
f := Felt(v)
55
return f.IsZero()
66
}
77

8-
func Equal[F FeltLike](a, b *F) bool {
9-
fa := Felt(*a)
10-
fb := Felt(*b)
8+
func Equal[F FeltLike](a, b F) bool {
9+
fa := Felt(a)
10+
fb := Felt(b)
1111
return fa.Equal(&fb)
1212
}

core/state/history_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func TestNewStateHistory(t *testing.T) {
2020
assert.NotNil(t, history.state)
2121
})
2222

23-
t.Run("bigger state root", func(t *testing.T) {
23+
t.Run("invalid state root", func(t *testing.T) {
2424
invalidRoot := felt.NewUnsafeFromString[felt.Felt]("0x999")
2525
_, err := NewStateHistory(1, invalidRoot, stateDB)
2626
// TODO(maksym): error is returned only for the triedb

core/state/state.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,8 @@ func (s *State) flush(
516516
}
517517

518518
// TODO(weiihann): handle hash-based, and there should be better ways of doing this
519-
if err := trieutils.DeleteStorageNodesByPath(batch, (*felt.Address)(&addr)); err != nil {
519+
err := trieutils.DeleteStorageNodesByPath(batch, (*felt.Address)(&addr))
520+
if err != nil {
520521
return err
521522
}
522523
} else { // updated

core/trie2/triedb/hashdb/database.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ func New(disk db.KeyValueStore, config *Config) *Database {
4949
}
5050

5151
func (d *Database) insert(
52-
owner *felt.Address, path *trieutils.Path, hash *felt.Felt, isClass bool, node trienode.TrieNode,
52+
owner *felt.Address,
53+
path *trieutils.Path,
54+
hash *felt.Felt,
55+
isClass bool,
56+
node trienode.TrieNode,
5357
) {
5458
_, found := d.dirtyCache.getNode(owner, path, hash, isClass)
5559
if found {
@@ -59,7 +63,11 @@ func (d *Database) insert(
5963
}
6064

6165
func (d *Database) readNode(
62-
bucket db.Bucket, owner *felt.Address, path *trieutils.Path, hash *felt.Felt, isLeaf bool,
66+
bucket db.Bucket,
67+
owner *felt.Address,
68+
path *trieutils.Path,
69+
hash *felt.Felt,
70+
isLeaf bool,
6371
) ([]byte, error) {
6472
if blob := d.cleanCache.getNode(path, hash); blob != nil {
6573
return blob, nil
@@ -86,7 +94,7 @@ func (d *Database) readNode(
8694
func (d *Database) NewIterator(id trieutils.TrieID) (db.Iterator, error) {
8795
key := id.Bucket().Key()
8896
owner := id.Owner()
89-
if !felt.IsZero(&owner) {
97+
if !felt.IsZero(owner) {
9098
oBytes := owner.Bytes()
9199
key = append(key, oBytes[:]...)
92100
}
@@ -109,15 +117,15 @@ func (d *Database) Commit(_ *felt.Felt) error {
109117
batch,
110118
db.ClassTrie,
111119
&felt.Address{},
112-
path,
113-
hash,
120+
&path,
121+
&hash,
114122
node.IsLeaf(),
115123
node.Blob(),
116124
)
117125
if err != nil {
118126
return err
119127
}
120-
d.cleanCache.putNode(path, hash, node.Blob())
128+
d.cleanCache.putNode(&path, &hash, node.Blob())
121129
}
122130

123131
for key, node := range d.dirtyCache.contractNodes {
@@ -129,15 +137,15 @@ func (d *Database) Commit(_ *felt.Felt) error {
129137
batch,
130138
db.ContractTrieContract,
131139
&felt.Address{},
132-
path,
133-
hash,
140+
&path,
141+
&hash,
134142
node.IsLeaf(),
135143
node.Blob(),
136144
)
137145
if err != nil {
138146
return err
139147
}
140-
d.cleanCache.putNode(path, hash, node.Blob())
148+
d.cleanCache.putNode(&path, &hash, node.Blob())
141149
}
142150

143151
for owner, nodes := range d.dirtyCache.contractStorageNodes {
@@ -150,15 +158,15 @@ func (d *Database) Commit(_ *felt.Felt) error {
150158
batch,
151159
db.ContractTrieStorage,
152160
&owner,
153-
path,
154-
hash,
161+
&path,
162+
&hash,
155163
node.IsLeaf(),
156164
node.Blob(),
157165
)
158166
if err != nil {
159167
return err
160168
}
161-
d.cleanCache.putNode(path, hash, node.Blob())
169+
d.cleanCache.putNode(&path, &hash, node.Blob())
162170
}
163171
}
164172

@@ -241,7 +249,10 @@ type reader struct {
241249
}
242250

243251
func (r *reader) Node(
244-
owner *felt.Address, path *trieutils.Path, hash *felt.Felt, isLeaf bool,
252+
owner *felt.Address,
253+
path *trieutils.Path,
254+
hash *felt.Felt,
255+
isLeaf bool,
245256
) ([]byte, error) {
246257
return r.d.readNode(r.id.Bucket(), owner, path, hash, isLeaf)
247258
}
@@ -262,7 +273,12 @@ func (d *Database) GetTrieRootNodes(classRootHash, contractRootHash *felt.Felt)
262273
const contractClassTrieHeight = 251
263274

264275
classRootBlob, err := trieutils.GetNodeByHash(
265-
d.disk, db.ClassTrie, &felt.Address{}, &trieutils.Path{}, classRootHash, false,
276+
d.disk,
277+
db.ClassTrie,
278+
&felt.Address{},
279+
&trieutils.Path{},
280+
classRootHash,
281+
false,
266282
)
267283
if err != nil {
268284
return nil, nil, fmt.Errorf("class root node not found: %w", err)

core/trie2/triedb/hashdb/utils.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ func nodeKey(path *trieutils.Path, hash *felt.Felt) []byte {
1818
return key
1919
}
2020

21-
func decodeNodeKey(key []byte) (path *trieutils.Path, hash *felt.Felt, err error) {
22-
hash = new(felt.Felt)
21+
func decodeNodeKey(key []byte) (path trieutils.Path, hash felt.Felt, err error) {
2322
hash.Unmarshal(key[:felt.Bytes])
2423

2524
pathBytes := key[felt.Bytes:]
26-
path = new(trieutils.Path)
2725
if err := path.UnmarshalBinary(pathBytes); err != nil {
2826
return path, hash, err
2927
}

core/trie2/triedb/pathdb/buffer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func newBuffer(limit int, nodes *nodeSet, layer uint64) *buffer {
2828
}
2929

3030
func (b *buffer) node(
31-
owner *felt.Address, path *trieutils.Path, isClass bool,
31+
owner *felt.Address,
32+
path *trieutils.Path,
33+
isClass bool,
3234
) (trienode.TrieNode, bool) {
3335
return b.nodes.node(owner, path, isClass)
3436
}

core/trie2/triedb/pathdb/difflayer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ func newDiffLayer(parent layer, root *felt.Felt, id, block uint64, nodes *nodeSe
3434
}
3535

3636
func (dl *diffLayer) node(
37-
id trieutils.TrieID, owner *felt.Address, path *trieutils.Path, isLeaf bool,
37+
id trieutils.TrieID,
38+
owner *felt.Address,
39+
path *trieutils.Path,
40+
isLeaf bool,
3841
) ([]byte, error) {
3942
dl.lock.RLock()
4043
defer dl.lock.RUnlock()

core/trie2/triedb/pathdb/layertree_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ func (t *layerTracker) resolveNode(
243243

244244
// findNodeInLayer checks if a node exists in a specific layer (without parent traversal)
245245
func (t *layerTracker) findNodeInLayer(
246-
root *felt.Felt, owner *felt.Address, path *trieutils.Path, isClass bool,
246+
root *felt.Felt,
247+
owner *felt.Address,
248+
path *trieutils.Path,
249+
isClass bool,
247250
) ([]byte, bool) {
248251
if isClass {
249252
if nodeMap, ok := t.classNodes[*root]; ok {
@@ -254,7 +257,7 @@ func (t *layerTracker) findNodeInLayer(
254257
return nil, false
255258
}
256259

257-
if felt.IsZero(owner) {
260+
if felt.IsZero(*owner) {
258261
if nodeMap, ok := t.contractNodes[*root]; ok {
259262
if node, exists := nodeMap[*path]; exists {
260263
return node.Blob(), true
@@ -440,7 +443,10 @@ func verifyContractNodes(layer layer, root *felt.Felt, tracker *layerTracker) er
440443
for path := range tracker.contractPaths {
441444
expectedBlob, expectedErr := tracker.resolveNode(root, &felt.Address{}, &path, false)
442445
actualBlob, actualErr := layer.node(
443-
trieutils.NewContractTrieID(*root), &felt.Address{}, &path, false,
446+
trieutils.NewContractTrieID(*root),
447+
&felt.Address{},
448+
&path,
449+
false,
444450
)
445451

446452
if expectedErr != nil {
@@ -465,7 +471,10 @@ func verifyContractStorageNodes(layer layer, root *felt.Felt, tracker *layerTrac
465471
for path := range paths {
466472
expectedBlob, expectedErr := tracker.resolveNode(root, &owner, &path, false)
467473
actualBlob, actualErr := layer.node(
468-
trieutils.NewContractStorageTrieID(*root, owner), &owner, &path, false,
474+
trieutils.NewContractStorageTrieID(*root, owner),
475+
&owner,
476+
&path,
477+
false,
469478
)
470479

471480
if expectedErr != nil {

core/trie2/triedb/pathdb/reader.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ type reader struct {
1717
}
1818

1919
func (r *reader) Node(
20-
owner *felt.Address, path *trieutils.Path, hash *felt.Felt, isLeaf bool,
20+
owner *felt.Address,
21+
path *trieutils.Path,
22+
hash *felt.Felt,
23+
isLeaf bool,
2124
) ([]byte, error) {
2225
return r.l.node(r.id, owner, path, isLeaf)
2326
}

0 commit comments

Comments
 (0)