starknet_patricia_storage: wrap cache of cached storage in Arc#12252
starknet_patricia_storage: wrap cache of cached storage in Arc#12252nimrod-starkware wants to merge 1 commit intonimrod/parallel-reads/non-mut-getfrom
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
a4552a0 to
aa7cced
Compare
fd181ac to
9682a10
Compare
9682a10 to
8cf9c0f
Compare
8c20344 to
a2c1ea7
Compare
8cf9c0f to
99478b0
Compare
| self.cache.put(key.clone(), Some(value.clone())); | ||
| Arc::get_mut(&mut self.cache) | ||
| .expect("Failed to get mutable reference to cache.") | ||
| .put(key.clone(), Some(value.clone())); |
There was a problem hiding this comment.
Arc::get_mut panics if cache is cloned
Medium Severity
The use of Arc::get_mut(&mut self.cache).expect(...) will panic at runtime if the Arc is ever cloned. Since the cache field is pub, external code can call .clone() on it to share the cache. Once cloned, Arc::get_mut() returns None because other references exist, causing the .expect() to panic. This creates a latent panic trap in update_cached_value, set, mset, and delete operations. Using Arc typically implies shared ownership, but this pattern prevents any sharing.
Additional Locations (1)
a2c1ea7 to
d50807e
Compare
99478b0 to
a72eee1
Compare



Note
Medium Risk
Changes
CachedStorage’s internal cache ownership and mutation paths; incorrectArc::get_mutassumptions could cause panics at runtime if the cache becomes shared.Overview
Wraps
CachedStorage’sLruCachein anArc, changing the cache field type fromLruCache<...>toArc<LruCache<...>>and updating initialization accordingly.Updates write/delete cache mutation to go through
Arc::get_mut(...).expect(...)before callingput/pop, while read paths continue to use cachepeek/containsvia theArc.Written by Cursor Bugbot for commit a72eee1. This will update automatically on new commits. Configure here.