4343
4444 // aggregatorItemLimit is an approximate number of items that will end up
4545 // in the agregator layer before it's flushed out to disk. A plain account
46- // weighs around 14B (+hash), a storage slot 32B (+hash), so 50 is a very
47- // rough average of what we might see.
48- aggregatorItemLimit = aggregatorMemoryLimit / 55
46+ // weighs around 14B (+hash), a storage slot 32B (+hash), a deleted slot
47+ // 0B (+hash). Slots are mostly set/unset in lockstep, so thet average at
48+ // 16B (+hash). All in all, the average entry seems to be 15+32=47B. Use a
49+ // smaller number to be on the safe side.
50+ aggregatorItemLimit = aggregatorMemoryLimit / 42
4951
5052 // bloomTargetError is the target false positive rate when the aggregator
5153 // layer is at its fullest. The actual value will probably move around up
@@ -269,13 +271,13 @@ func (dl *diffLayer) AccountRLP(hash common.Hash) ([]byte, error) {
269271 return dl .origin .AccountRLP (hash )
270272 }
271273 // The bloom filter hit, start poking in the internal maps
272- return dl .accountRLP (hash )
274+ return dl .accountRLP (hash , 0 )
273275}
274276
275277// accountRLP is an internal version of AccountRLP that skips the bloom filter
276278// checks and uses the internal maps to try and retrieve the data. It's meant
277279// to be used if a higher layer's bloom filter hit already.
278- func (dl * diffLayer ) accountRLP (hash common.Hash ) ([]byte , error ) {
280+ func (dl * diffLayer ) accountRLP (hash common.Hash , depth int ) ([]byte , error ) {
279281 dl .lock .RLock ()
280282 defer dl .lock .RUnlock ()
281283
@@ -288,13 +290,18 @@ func (dl *diffLayer) accountRLP(hash common.Hash) ([]byte, error) {
288290 // deleted, and is a different notion than an unknown account!
289291 if data , ok := dl .accountData [hash ]; ok {
290292 snapshotDirtyAccountHitMeter .Mark (1 )
291- snapshotDirtyAccountReadMeter .Mark (int64 (len (data )))
293+ snapshotDirtyAccountHitDepthHist .Update (int64 (depth ))
294+ if n := len (data ); n > 0 {
295+ snapshotDirtyAccountReadMeter .Mark (int64 (n ))
296+ } else {
297+ snapshotDirtyAccountInexMeter .Mark (1 )
298+ }
292299 snapshotBloomAccountTrueHitMeter .Mark (1 )
293300 return data , nil
294301 }
295302 // Account unknown to this diff, resolve from parent
296303 if diff , ok := dl .parent .(* diffLayer ); ok {
297- return diff .accountRLP (hash )
304+ return diff .accountRLP (hash , depth + 1 )
298305 }
299306 // Failed to resolve through diff layers, mark a bloom error and use the disk
300307 snapshotBloomAccountFalseHitMeter .Mark (1 )
@@ -318,13 +325,13 @@ func (dl *diffLayer) Storage(accountHash, storageHash common.Hash) ([]byte, erro
318325 return dl .origin .Storage (accountHash , storageHash )
319326 }
320327 // The bloom filter hit, start poking in the internal maps
321- return dl .storage (accountHash , storageHash )
328+ return dl .storage (accountHash , storageHash , 0 )
322329}
323330
324331// storage is an internal version of Storage that skips the bloom filter checks
325332// and uses the internal maps to try and retrieve the data. It's meant to be
326333// used if a higher layer's bloom filter hit already.
327- func (dl * diffLayer ) storage (accountHash , storageHash common.Hash ) ([]byte , error ) {
334+ func (dl * diffLayer ) storage (accountHash , storageHash common.Hash , depth int ) ([]byte , error ) {
328335 dl .lock .RLock ()
329336 defer dl .lock .RUnlock ()
330337
@@ -338,19 +345,26 @@ func (dl *diffLayer) storage(accountHash, storageHash common.Hash) ([]byte, erro
338345 if storage , ok := dl .storageData [accountHash ]; ok {
339346 if storage == nil {
340347 snapshotDirtyStorageHitMeter .Mark (1 )
348+ snapshotDirtyStorageHitDepthHist .Update (int64 (depth ))
349+ snapshotDirtyStorageInexMeter .Mark (1 )
341350 snapshotBloomStorageTrueHitMeter .Mark (1 )
342351 return nil , nil
343352 }
344353 if data , ok := storage [storageHash ]; ok {
345354 snapshotDirtyStorageHitMeter .Mark (1 )
346- snapshotDirtyStorageReadMeter .Mark (int64 (len (data )))
355+ snapshotDirtyStorageHitDepthHist .Update (int64 (depth ))
356+ if n := len (data ); n > 0 {
357+ snapshotDirtyStorageReadMeter .Mark (int64 (n ))
358+ } else {
359+ snapshotDirtyStorageInexMeter .Mark (1 )
360+ }
347361 snapshotBloomStorageTrueHitMeter .Mark (1 )
348362 return data , nil
349363 }
350364 }
351365 // Storage slot unknown to this diff, resolve from parent
352366 if diff , ok := dl .parent .(* diffLayer ); ok {
353- return diff .storage (accountHash , storageHash )
367+ return diff .storage (accountHash , storageHash , depth + 1 )
354368 }
355369 // Failed to resolve through diff layers, mark a bloom error and use the disk
356370 snapshotBloomStorageFalseHitMeter .Mark (1 )
0 commit comments