@@ -124,47 +124,20 @@ type diffLayer struct {
124
124
lock sync.RWMutex
125
125
}
126
126
127
- // destructBloomHasher is a wrapper around a common.Hash to satisfy the interface
128
- // API requirements of the bloom library used. It's used to convert a destruct
129
- // event into a 64 bit mini hash.
130
- type destructBloomHasher common.Hash
131
-
132
- func (h destructBloomHasher ) Write (p []byte ) (n int , err error ) { panic ("not implemented" ) }
133
- func (h destructBloomHasher ) Sum (b []byte ) []byte { panic ("not implemented" ) }
134
- func (h destructBloomHasher ) Reset () { panic ("not implemented" ) }
135
- func (h destructBloomHasher ) BlockSize () int { panic ("not implemented" ) }
136
- func (h destructBloomHasher ) Size () int { return 8 }
137
- func (h destructBloomHasher ) Sum64 () uint64 {
127
+ // destructBloomHash is used to convert a destruct event into a 64 bit mini hash.
128
+ func destructBloomHash (h common.Hash ) uint64 {
138
129
return binary .BigEndian .Uint64 (h [bloomDestructHasherOffset : bloomDestructHasherOffset + 8 ])
139
130
}
140
131
141
- // accountBloomHasher is a wrapper around a common.Hash to satisfy the interface
142
- // API requirements of the bloom library used. It's used to convert an account
143
- // hash into a 64 bit mini hash.
144
- type accountBloomHasher common.Hash
145
-
146
- func (h accountBloomHasher ) Write (p []byte ) (n int , err error ) { panic ("not implemented" ) }
147
- func (h accountBloomHasher ) Sum (b []byte ) []byte { panic ("not implemented" ) }
148
- func (h accountBloomHasher ) Reset () { panic ("not implemented" ) }
149
- func (h accountBloomHasher ) BlockSize () int { panic ("not implemented" ) }
150
- func (h accountBloomHasher ) Size () int { return 8 }
151
- func (h accountBloomHasher ) Sum64 () uint64 {
132
+ // accountBloomHash is used to convert an account hash into a 64 bit mini hash.
133
+ func accountBloomHash (h common.Hash ) uint64 {
152
134
return binary .BigEndian .Uint64 (h [bloomAccountHasherOffset : bloomAccountHasherOffset + 8 ])
153
135
}
154
136
155
- // storageBloomHasher is a wrapper around a [2]common.Hash to satisfy the interface
156
- // API requirements of the bloom library used. It's used to convert an account
157
- // hash into a 64 bit mini hash.
158
- type storageBloomHasher [2 ]common.Hash
159
-
160
- func (h storageBloomHasher ) Write (p []byte ) (n int , err error ) { panic ("not implemented" ) }
161
- func (h storageBloomHasher ) Sum (b []byte ) []byte { panic ("not implemented" ) }
162
- func (h storageBloomHasher ) Reset () { panic ("not implemented" ) }
163
- func (h storageBloomHasher ) BlockSize () int { panic ("not implemented" ) }
164
- func (h storageBloomHasher ) Size () int { return 8 }
165
- func (h storageBloomHasher ) Sum64 () uint64 {
166
- return binary .BigEndian .Uint64 (h [0 ][bloomStorageHasherOffset :bloomStorageHasherOffset + 8 ]) ^
167
- binary .BigEndian .Uint64 (h [1 ][bloomStorageHasherOffset :bloomStorageHasherOffset + 8 ])
137
+ // storageBloomHash is used to convert an account hash and a storage hash into a 64 bit mini hash.
138
+ func storageBloomHash (h0 , h1 common.Hash ) uint64 {
139
+ return binary .BigEndian .Uint64 (h0 [bloomStorageHasherOffset :bloomStorageHasherOffset + 8 ]) ^
140
+ binary .BigEndian .Uint64 (h1 [bloomStorageHasherOffset :bloomStorageHasherOffset + 8 ])
168
141
}
169
142
170
143
// newDiffLayer creates a new diff on top of an existing snapshot, whether that's a low
@@ -233,14 +206,14 @@ func (dl *diffLayer) rebloom(origin *diskLayer) {
233
206
}
234
207
// Iterate over all the accounts and storage slots and index them
235
208
for hash := range dl .destructSet {
236
- dl .diffed .Add ( destructBloomHasher (hash ))
209
+ dl .diffed .AddHash ( destructBloomHash (hash ))
237
210
}
238
211
for hash := range dl .accountData {
239
- dl .diffed .Add ( accountBloomHasher (hash ))
212
+ dl .diffed .AddHash ( accountBloomHash (hash ))
240
213
}
241
214
for accountHash , slots := range dl .storageData {
242
215
for storageHash := range slots {
243
- dl .diffed .Add ( storageBloomHasher { accountHash , storageHash } )
216
+ dl .diffed .AddHash ( storageBloomHash ( accountHash , storageHash ) )
244
217
}
245
218
}
246
219
// Calculate the current false positive rate and update the error rate meter.
@@ -301,9 +274,9 @@ func (dl *diffLayer) AccountRLP(hash common.Hash) ([]byte, error) {
301
274
}
302
275
// Check the bloom filter first whether there's even a point in reaching into
303
276
// all the maps in all the layers below
304
- hit := dl .diffed .Contains ( accountBloomHasher (hash ))
277
+ hit := dl .diffed .ContainsHash ( accountBloomHash (hash ))
305
278
if ! hit {
306
- hit = dl .diffed .Contains ( destructBloomHasher (hash ))
279
+ hit = dl .diffed .ContainsHash ( destructBloomHash (hash ))
307
280
}
308
281
var origin * diskLayer
309
282
if ! hit {
@@ -372,9 +345,9 @@ func (dl *diffLayer) Storage(accountHash, storageHash common.Hash) ([]byte, erro
372
345
dl .lock .RUnlock ()
373
346
return nil , ErrSnapshotStale
374
347
}
375
- hit := dl .diffed .Contains ( storageBloomHasher { accountHash , storageHash } )
348
+ hit := dl .diffed .ContainsHash ( storageBloomHash ( accountHash , storageHash ) )
376
349
if ! hit {
377
- hit = dl .diffed .Contains ( destructBloomHasher (accountHash ))
350
+ hit = dl .diffed .ContainsHash ( destructBloomHash (accountHash ))
378
351
}
379
352
var origin * diskLayer
380
353
if ! hit {
0 commit comments