@@ -48,15 +48,27 @@ func New(disk db.KeyValueStore, config *Config) *Database {
4848 }
4949}
5050
51- func (d * Database ) insert (owner * felt.Felt , path * trieutils.Path , hash * felt.Felt , isClass bool , node trienode.TrieNode ) {
51+ func (d * Database ) insert (
52+ owner * felt.Address ,
53+ path * trieutils.Path ,
54+ hash * felt.Felt ,
55+ isClass bool ,
56+ node trienode.TrieNode ,
57+ ) {
5258 _ , found := d .dirtyCache .getNode (owner , path , hash , isClass )
5359 if found {
5460 return
5561 }
5662 d .dirtyCache .putNode (owner , path , hash , isClass , node )
5763}
5864
59- func (d * Database ) readNode (bucket db.Bucket , owner * felt.Felt , path * trieutils.Path , hash * felt.Felt , isLeaf bool ) ([]byte , error ) {
65+ func (d * Database ) readNode (
66+ bucket db.Bucket ,
67+ owner * felt.Address ,
68+ path * trieutils.Path ,
69+ hash * felt.Felt ,
70+ isLeaf bool ,
71+ ) ([]byte , error ) {
6072 if blob := d .cleanCache .getNode (path , hash ); blob != nil {
6173 return blob , nil
6274 }
@@ -82,7 +94,7 @@ func (d *Database) readNode(bucket db.Bucket, owner *felt.Felt, path *trieutils.
8294func (d * Database ) NewIterator (id trieutils.TrieID ) (db.Iterator , error ) {
8395 key := id .Bucket ().Key ()
8496 owner := id .Owner ()
85- if ! owner . Equal ( & felt . Zero ) {
97+ if ! felt . IsZero ( & owner ) {
8698 oBytes := owner .Bytes ()
8799 key = append (key , oBytes [:]... )
88100 }
@@ -101,7 +113,16 @@ func (d *Database) Commit(_ *felt.Felt) error {
101113 if err != nil {
102114 return err
103115 }
104- if err := trieutils .WriteNodeByHash (batch , db .ClassTrie , & felt .Zero , & path , & hash , node .IsLeaf (), node .Blob ()); err != nil {
116+ err = trieutils .WriteNodeByHash (
117+ batch ,
118+ db .ClassTrie ,
119+ & felt.Address {},
120+ & path ,
121+ & hash ,
122+ node .IsLeaf (),
123+ node .Blob (),
124+ )
125+ if err != nil {
105126 return err
106127 }
107128 d .cleanCache .putNode (& path , & hash , node .Blob ())
@@ -112,7 +133,16 @@ func (d *Database) Commit(_ *felt.Felt) error {
112133 if err != nil {
113134 return err
114135 }
115- if err := trieutils .WriteNodeByHash (batch , db .ContractTrieContract , & felt .Zero , & path , & hash , node .IsLeaf (), node .Blob ()); err != nil {
136+ err = trieutils .WriteNodeByHash (
137+ batch ,
138+ db .ContractTrieContract ,
139+ & felt.Address {},
140+ & path ,
141+ & hash ,
142+ node .IsLeaf (),
143+ node .Blob (),
144+ )
145+ if err != nil {
116146 return err
117147 }
118148 d .cleanCache .putNode (& path , & hash , node .Blob ())
@@ -124,7 +154,16 @@ func (d *Database) Commit(_ *felt.Felt) error {
124154 if err != nil {
125155 return err
126156 }
127- if err := trieutils .WriteNodeByHash (batch , db .ContractTrieStorage , & owner , & path , & hash , node .IsLeaf (), node .Blob ()); err != nil {
157+ err = trieutils .WriteNodeByHash (
158+ batch ,
159+ db .ContractTrieStorage ,
160+ & owner ,
161+ & path ,
162+ & hash ,
163+ node .IsLeaf (),
164+ node .Blob (),
165+ )
166+ if err != nil {
128167 return err
129168 }
130169 d .cleanCache .putNode (& path , & hash , node .Blob ())
@@ -158,7 +197,7 @@ func (d *Database) Update(
158197
159198 var classNodes map [trieutils.Path ]trienode.TrieNode
160199 var contractNodes map [trieutils.Path ]trienode.TrieNode
161- var contractStorageNodes map [felt.Felt ]map [trieutils.Path ]trienode.TrieNode
200+ var contractStorageNodes map [felt.Address ]map [trieutils.Path ]trienode.TrieNode
162201
163202 if mergedClassNodes != nil {
164203 classNodes , _ = mergedClassNodes .Flatten ()
@@ -170,15 +209,15 @@ func (d *Database) Update(
170209 contractNodes , contractStorageNodes = mergedContractNodes .Flatten ()
171210 } else {
172211 contractNodes = make (map [trieutils.Path ]trienode.TrieNode )
173- contractStorageNodes = make (map [felt.Felt ]map [trieutils.Path ]trienode.TrieNode )
212+ contractStorageNodes = make (map [felt.Address ]map [trieutils.Path ]trienode.TrieNode )
174213 }
175214
176215 for path , node := range classNodes {
177216 if _ , ok := node .(* trienode.DeletedNode ); ok {
178217 continue // Since the hashdb is used for archive node only, there is no need to remove nodes
179218 } else {
180219 nodeHash := node .Hash ()
181- d .insert (& felt .Zero , & path , & nodeHash , true , node )
220+ d .insert (& felt.Address {} , & path , & nodeHash , true , node )
182221 }
183222 }
184223
@@ -187,7 +226,7 @@ func (d *Database) Update(
187226 continue
188227 } else {
189228 nodeHash := node .Hash ()
190- d .insert (& felt .Zero , & path , & nodeHash , false , node )
229+ d .insert (& felt.Address {} , & path , & nodeHash , false , node )
191230 }
192231 }
193232
@@ -209,7 +248,12 @@ type reader struct {
209248 d * Database
210249}
211250
212- func (r * reader ) Node (owner * felt.Felt , path * trieutils.Path , hash * felt.Felt , isLeaf bool ) ([]byte , error ) {
251+ func (r * reader ) Node (
252+ owner * felt.Address ,
253+ path * trieutils.Path ,
254+ hash * felt.Felt ,
255+ isLeaf bool ,
256+ ) ([]byte , error ) {
213257 return r .d .readNode (r .id .Bucket (), owner , path , hash , isLeaf )
214258}
215259
@@ -228,15 +272,29 @@ func (d *Database) Close() error {
228272func (d * Database ) GetTrieRootNodes (classRootHash , contractRootHash * felt.Felt ) (trienode.Node , trienode.Node , error ) {
229273 const contractClassTrieHeight = 251
230274
231- classRootBlob , err := trieutils .GetNodeByHash (d .disk , db .ClassTrie , & felt .Zero , & trieutils.Path {}, classRootHash , false )
275+ classRootBlob , err := trieutils .GetNodeByHash (
276+ d .disk ,
277+ db .ClassTrie ,
278+ & felt.Address {},
279+ & trieutils.Path {},
280+ classRootHash ,
281+ false ,
282+ )
232283 if err != nil {
233284 return nil , nil , fmt .Errorf ("class root node not found: %w" , err )
234285 }
235286 if classRootBlob == nil {
236287 return nil , nil , fmt .Errorf ("class root node not found" )
237288 }
238289
239- contractRootBlob , err := trieutils .GetNodeByHash (d .disk , db .ContractTrieContract , & felt .Zero , & trieutils.Path {}, contractRootHash , false )
290+ contractRootBlob , err := trieutils .GetNodeByHash (
291+ d .disk ,
292+ db .ContractTrieContract ,
293+ & felt.Address {},
294+ & trieutils.Path {},
295+ contractRootHash ,
296+ false ,
297+ )
240298 if err != nil {
241299 return nil , nil , fmt .Errorf ("contract root node not found: %w" , err )
242300 }
0 commit comments