Skip to content

starknet_patricia_storage: wrap cache of cached storage in Arc#12252

Closed
nimrod-starkware wants to merge 1 commit intonimrod/parallel-reads/non-mut-getfrom
nimrod/parallel-reads/wrap-cache-in-arc
Closed

starknet_patricia_storage: wrap cache of cached storage in Arc#12252
nimrod-starkware wants to merge 1 commit intonimrod/parallel-reads/non-mut-getfrom
nimrod/parallel-reads/wrap-cache-in-arc

Conversation

@nimrod-starkware
Copy link
Contributor

@nimrod-starkware nimrod-starkware commented Feb 3, 2026

Note

Medium Risk
Changes CachedStorage’s internal cache ownership and mutation paths; incorrect Arc::get_mut assumptions could cause panics at runtime if the cache becomes shared.

Overview
Wraps CachedStorage’s LruCache in an Arc, changing the cache field type from LruCache<...> to Arc<LruCache<...>> and updating initialization accordingly.

Updates write/delete cache mutation to go through Arc::get_mut(...).expect(...) before calling put/pop, while read paths continue to use cache peek/contains via the Arc.

Written by Cursor Bugbot for commit a72eee1. This will update automatically on new commits. Configure here.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Contributor Author

nimrod-starkware commented Feb 3, 2026

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

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()));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Fix in Cursor Fix in Web

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments