diff --git a/core/state/snapshot/snapshot.go b/core/state/snapshot/snapshot.go index fe5381ef69..84b3c8fa12 100644 --- a/core/state/snapshot/snapshot.go +++ b/core/state/snapshot/snapshot.go @@ -390,15 +390,17 @@ func (t *Tree) Cap(root common.Hash, layers int) error { } // Update the cache stats - var stats fastcache.Stats - diff.origin.cache.UpdateStats(&stats) - snapshotCacheGetGauge.Update(int64(stats.GetCalls)) - snapshotCacheSetGauge.Update(int64(stats.SetCalls)) - snapshotCacheMissGauge.Update(int64(stats.Misses)) - snapshotCacheSizeGauge.Update(int64(stats.BytesSize)) - snapshotCacheCapacityGauge.Update(int64(stats.MaxBytesSize)) - snapshotCacheEntriesGauge.Update(int64(stats.EntriesCount)) - snapshotCacheCollisionGauge.Update(int64(stats.Collisions)) + if diff.origin != nil && diff.origin.cache != nil { + var stats fastcache.Stats + diff.origin.cache.UpdateStats(&stats) + snapshotCacheGetGauge.Update(int64(stats.GetCalls)) + snapshotCacheSetGauge.Update(int64(stats.SetCalls)) + snapshotCacheMissGauge.Update(int64(stats.Misses)) + snapshotCacheSizeGauge.Update(int64(stats.BytesSize)) + snapshotCacheCapacityGauge.Update(int64(stats.MaxBytesSize)) + snapshotCacheEntriesGauge.Update(int64(stats.EntriesCount)) + snapshotCacheCollisionGauge.Update(int64(stats.Collisions)) + } // If the generator is still running, use a more aggressive cap diff.origin.lock.RLock() diff --git a/triedb/pathdb/disklayer.go b/triedb/pathdb/disklayer.go index da25cd83c7..f8c93ca7cd 100644 --- a/triedb/pathdb/disklayer.go +++ b/triedb/pathdb/disklayer.go @@ -306,15 +306,17 @@ func (dl *diskLayer) update(root common.Hash, id uint64, block uint64, nodes *no // and returns a newly constructed disk layer. Note the current disk // layer must be tagged as stale first to prevent re-access. func (dl *diskLayer) commit(bottom *diffLayer, force bool) (*diskLayer, error) { - var stats fastcache.Stats - dl.nodes.UpdateStats(&stats) - snapshotCacheGetGauge.Update(int64(stats.GetCalls)) - snapshotCacheSetGauge.Update(int64(stats.SetCalls)) - snapshotCacheMissGauge.Update(int64(stats.Misses)) - snapshotCacheSizeGauge.Update(int64(stats.BytesSize)) - snapshotCacheCapacityGauge.Update(int64(stats.MaxBytesSize)) - snapshotCacheEntriesGauge.Update(int64(stats.EntriesCount)) - snapshotCacheCollisionGauge.Update(int64(stats.Collisions)) + if dl.nodes != nil { + var stats fastcache.Stats + dl.nodes.UpdateStats(&stats) + snapshotCacheGetGauge.Update(int64(stats.GetCalls)) + snapshotCacheSetGauge.Update(int64(stats.SetCalls)) + snapshotCacheMissGauge.Update(int64(stats.Misses)) + snapshotCacheSizeGauge.Update(int64(stats.BytesSize)) + snapshotCacheCapacityGauge.Update(int64(stats.MaxBytesSize)) + snapshotCacheEntriesGauge.Update(int64(stats.EntriesCount)) + snapshotCacheCollisionGauge.Update(int64(stats.Collisions)) + } dl.lock.Lock() defer dl.lock.Unlock()