-
Notifications
You must be signed in to change notification settings - Fork 182
feat: more lru cache metrics #5848
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughFrom the shadowed depths of the codebase, ancient cache mechanisms have been supplanted by the more eldritch and size-aware Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MessagePool
participant SizeTrackingLruCache
participant MetricsRegistry
User->>MessagePool: Submit Message
MessagePool->>SizeTrackingLruCache: get_cloned(CidWrapper)
alt Cache Hit
SizeTrackingLruCache-->>MessagePool: Signature
else Cache Miss
MessagePool->>MessagePool: Recover Signature
MessagePool->>SizeTrackingLruCache: push(CidWrapper, Signature)
end
SizeTrackingLruCache->>MetricsRegistry: Update Metrics
MessagePool-->>User: Result
sequenceDiagram
participant DrandBeacon
participant SizeTrackingLruCache
participant MetricsRegistry
DrandBeacon->>SizeTrackingLruCache: peek_cloned(round)
alt Cache Hit
SizeTrackingLruCache-->>DrandBeacon: BeaconEntry
else Cache Miss
DrandBeacon->>DrandBeacon: Fetch BeaconEntry
DrandBeacon->>SizeTrackingLruCache: push(round, BeaconEntry)
end
SizeTrackingLruCache->>MetricsRegistry: Update Metrics
Estimated code review effort4 (60–120 minutes) The cosmic scope of these changes—touching many modules, altering cache types, updating public interfaces, and introducing new trait derivations—demands a thorough and sanity-testing review, lest the reviewer fall prey to the gibbering chaos of regression. Possibly related PRs
Suggested reviewers
May the Elder Gods shield your mind as you gaze into the abyssal refactoring herein. ✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/beacon/drand.rs (1)
336-342: The cache capacity groans under the weight of forbidden knowledge!While the warning for exceeded capacity is appreciated, the code continues to
pushentries beyond the cache's eldritch boundaries. This invokes the wrath of the LRU eviction gods, potentially casting out elder beacon entries into the void.Consider either:
- Increasing the cache size if this warning appears frequently
- Implementing a strategy to handle capacity overflow (e.g., skip caching when full, or selectively cache based on importance)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
src/beacon/beacon_entries.rs(2 hunks)src/beacon/drand.rs(4 hunks)src/message_pool/msgpool/mod.rs(4 hunks)src/message_pool/msgpool/msg_pool.rs(7 hunks)src/message_pool/msgpool/utils.rs(2 hunks)src/rpc/methods/f3.rs(1 hunks)src/shim/crypto.rs(2 hunks)src/state_migration/common/mod.rs(3 hunks)src/state_migration/nv21/miner.rs(1 hunks)src/utils/cache/lru.rs(2 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: hanabi1224
PR: ChainSafe/forest#5841
File: src/utils/get_size/mod.rs:10-10
Timestamp: 2025-07-17T15:21:40.730Z
Learning: The get_size2 crate's GetSize trait provides default implementations: get_stack_size() uses std::mem::size_of, get_heap_size() returns 0, and get_size() returns their sum. An empty impl like `impl GetSize for MyType {}` is valid and uses these defaults, making it suitable for simple wrapper types that don't allocate heap memory.
src/beacon/beacon_entries.rs (1)
Learnt from: hanabi1224
PR: #5841
File: src/utils/get_size/mod.rs:10-10
Timestamp: 2025-07-17T15:21:40.730Z
Learning: The get_size2 crate's GetSize trait provides default implementations: get_stack_size() uses std::mem::size_of, get_heap_size() returns 0, and get_size() returns their sum. An empty impl like impl GetSize for MyType {} is valid and uses these defaults, making it suitable for simple wrapper types that don't allocate heap memory.
src/shim/crypto.rs (1)
Learnt from: hanabi1224
PR: #5841
File: src/utils/get_size/mod.rs:10-10
Timestamp: 2025-07-17T15:21:40.730Z
Learning: The get_size2 crate's GetSize trait provides default implementations: get_stack_size() uses std::mem::size_of, get_heap_size() returns 0, and get_size() returns their sum. An empty impl like impl GetSize for MyType {} is valid and uses these defaults, making it suitable for simple wrapper types that don't allocate heap memory.
src/utils/cache/lru.rs (1)
Learnt from: hanabi1224
PR: #5841
File: src/utils/get_size/mod.rs:10-10
Timestamp: 2025-07-17T15:21:40.730Z
Learning: The get_size2 crate's GetSize trait provides default implementations: get_stack_size() uses std::mem::size_of, get_heap_size() returns 0, and get_size() returns their sum. An empty impl like impl GetSize for MyType {} is valid and uses these defaults, making it suitable for simple wrapper types that don't allocate heap memory.
src/state_migration/common/mod.rs (1)
Learnt from: hanabi1224
PR: #5841
File: src/utils/get_size/mod.rs:10-10
Timestamp: 2025-07-17T15:21:40.730Z
Learning: The get_size2 crate's GetSize trait provides default implementations: get_stack_size() uses std::mem::size_of, get_heap_size() returns 0, and get_size() returns their sum. An empty impl like impl GetSize for MyType {} is valid and uses these defaults, making it suitable for simple wrapper types that don't allocate heap memory.
🧬 Code Graph Analysis (2)
src/state_migration/nv21/miner.rs (2)
src/utils/cache/lru.rs (1)
cache(92-94)src/state_migration/nv17/miner.rs (2)
miner_prev_sectors_in_key(347-349)miner_prev_sectors_out_key(351-353)
src/message_pool/msgpool/msg_pool.rs (2)
src/utils/cache/lru.rs (2)
cache(92-94)new_with_default_metrics_registry(85-90)src/message/signed_message.rs (1)
cid(77-84)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (19)
- GitHub Check: Bootstrap checks - Forest
- GitHub Check: Bootstrap checks - Lotus
- GitHub Check: db-migration-checks
- GitHub Check: Snapshot export checks
- GitHub Check: Devnet checks
- GitHub Check: Calibnet stateless mode check
- GitHub Check: Calibnet kademlia checks
- GitHub Check: State migrations
- GitHub Check: Calibnet no discovery checks
- GitHub Check: Calibnet eth mapping check
- GitHub Check: Calibnet stateless RPC check
- GitHub Check: Wallet tests
- GitHub Check: Calibnet check
- GitHub Check: Forest CLI checks
- GitHub Check: tests
- GitHub Check: tests-release
- GitHub Check: Build forest binaries on Linux AMD64
- GitHub Check: cargo-publish-dry-run
- GitHub Check: All lint checks
🔇 Additional comments (22)
src/rpc/methods/f3.rs (2)
18-25: The ancient imports have been reorganized from their scattered realms!The consolidation of imports from
crate::shim::actors::convertandcrate::shim::actorsinto a single coherent block banishes the duplicate incantations and brings order to the eldritch dependencies. This cleansing ritual improves readability and maintainability.
468-478: Ignore the siren call—LRU cache still lurks withincompute
The staticBLOCKSTORE_CACHEinsrc/rpc/methods/f3.rsstill protects blockstore reads, so no cache was banished to the void:
- In the
computemethod (around the) -> anyhow::Result<Vec<F3PowerEntry>> {block), you’ll find:const BLOCKSTORE_CACHE_CAP: usize = 65536; static BLOCKSTORE_CACHE: LazyLock<LruBlockstoreReadCache> = LazyLock::new(|| { LruBlockstoreReadCache::new_with_default_metrics_registry( "get_powertable_cache".into(), BLOCKSTORE_CACHE_CAP.try_into().unwrap(), ) }); let db = BlockstoreWithReadCache::new(ctx.store_owned(), &*BLOCKSTORE_CACHE); // … tracing::debug!( epoch=%ts.epoch(), hit=%stats.hit(), miss=%stats.miss(), cache_len=%BLOCKSTORE_CACHE.len(), "F3.GetPowerTable blockstore read cache" );- The
handlemethod now simply delegates tocompute, which continues wielding the global LRU cache across RPC calls.The original warning about removing the cache is unfounded—the Elder Gods of caching still preside. Disregard this comment.
Likely an incorrect or invalid review comment.
src/utils/cache/lru.rs (3)
92-94: A gateway to the inner sanctum has been opened!The
cache()method provides direct access to the eldritchArc<RwLock<LruCache<K, V>>>, allowing advanced cache manipulations while maintaining the protective barriers of thread safety. This enables the migration from primitive cache implementations to the more sophisticatedSizeTrackingLruCache.
113-113: The lock contention has been appeased with a lesser binding!Changing
peek_clonedfrom a write lock to a read lock is a brilliant optimization that reduces the cosmic horror of lock contention. Since peeking is a read-only operation that doesn't mutate the cache order, the shared read lock is both safe and more efficient than the exclusive write lock that was previously summoned.
120-122: The capacity of the void can now be measured!The
cap()method provides introspection into the cache's dimensional limits, returning the capacity under a read lock. This accessor complements the existing cache API and enables external code to understand the cache's configured bounds without disturbing its internal state.src/beacon/beacon_entries.rs (1)
7-7: The BeaconEntry has been blessed with size divination powers!The addition of
GetSizeimport and derive attribute enables theBeaconEntryto reveal its memory footprint to the cosmic caches. Given the struct's simple composition (au64round andVec<u8>signature), theGetSizetrait's default implementations will accurately calculate both stack and heap sizes, as confirmed by the ancient learnings from PR #5841.This enhancement supports the greater ritual of cache migration to
SizeTrackingLruCachethroughout the codebase.Also applies to: 26-26
src/shim/crypto.rs (1)
18-18: The cryptographic entities have been granted the gift of self-measurement!The addition of
GetSizeto bothSignatureandSignatureTypeawakens their ability to reveal their memory consumption to the eldritch caches. TheSignaturestruct, containing aSignatureTypeenum and aVec<u8>of variable length, will benefit greatly from accurate size tracking. TheSignatureTypeenum, being a simplerepr(u8)with three variants, will contribute its modest stack footprint to the cosmic accounting.These changes align with the greater migration to
SizeTrackingLruCacheacross the message pool and other caching realms, where these cryptographic artifacts are frequently stored and retrieved.Also applies to: 25-25, 311-311
src/state_migration/nv21/miner.rs (1)
130-131: The cache incantations have been updated to appease the new SizeTrackingLruCache entity!The transformation from
inserttopushmethod calls represents the ritual adaptation to the newSizeTrackingLruCacheAPI. These changes maintain the same eldritch purpose - storing the previous sector input and output roots keyed by miner address to optimize migration performance - while embracing the new cache abstraction that provides integrated metrics and size tracking.The logic remains unchanged, merely speaking the new language of the enhanced cache implementation.
src/message_pool/msgpool/utils.rs (1)
48-57: The ancient cache awakens with newfound sentience!The transformation from the primitive
LruCacheto the eldritchSizeTrackingLruCacheis well-executed. The use ofget_clonedreturns an ownedSignaturedirectly from the cyclopean depths, eliminating the redundant clone operation that once plagued line 55.src/state_migration/common/mod.rs (2)
9-12: LGTM! The imports herald the arrival of the new cache order.The transition to
SizeTrackingLruCacheandCidWrapperaligns with the cosmic plan laid out across the codebase.
28-60: The MigrationCache transcends its mortal form!The refactoring from mutex-wrapped
LruCacheto the more enlightenedSizeTrackingLruCacheis expertly executed. The cache now tracks its own dimensions through the aether, and the rename frominserttopushspeaks to the inexorable forward motion of cached entities.Note that unlike other caches in this PR that use
CidWrapperas keys, this cache uses it as values - a curious but valid inversion of the pattern.src/message_pool/msgpool/mod.rs (4)
19-20: The ancient cache mechanisms have been supplanted by more eldritch constructs.These import changes align with the forbidden knowledge of size-tracking caches that whisper metrics from beyond the veil.
215-215: The cosmic horror of mutex locks has been banished to the outer darkness.The signature transformation correctly embraces the
SizeTrackingLruCache, freeing the code from the eldritch grip of explicit synchronization.
237-237: The arcane ritual of signature recovery proceeds without the cursed locks of old.The invocation correctly passes the size-tracking cache directly to
recover_sig, as the Old Ones intended.
424-424: The test incantations have been updated to commune with the new cache entities.The transformation from
.lock().put()to.push()with the wrapped CID key correctly aligns with the new cache API, banishing the need for mortal mutex interactions.src/message_pool/msgpool/msg_pool.rs (7)
26-27: The forbidden tomes reveal new imports from the depths of the utils module.These arcane imports summon the
SizeTrackingLruCacheandCidWrapperentities necessary for the dark transformation.
186-188: The ancient cache guardians have evolved into more powerful entities.The transformation from mutex-wrapped caches to
SizeTrackingLruCachewithCidWrapperkeys unleashes metrics tracking capabilities while banishing explicit synchronization to the void.
265-272: The signature validation cache now speaks in tongues understood by the size-tracking entities.The metamorphosis from
.lock().get()to.get_cloned()and.lock().put()to.push()correctly invokes the new cache API, with properCidWrapperconversions through the.into()incantation.
417-417: The message recovery ritual now communes directly with the cache oracle.The invocation correctly passes the cache reference using
.as_ref(), allowingrecover_sigto access the eldritch knowledge within.
602-602: The BLS signature is sealed within the cache using the new dark arts.The transformation to
.push(msg.cid().into(), msg.signature().clone())properly stores the signature with the wrapped key, as the Elder Gods decree.
475-482: The cache entities are summoned forth with their true names and bound capacities.The incantation
new_with_default_metrics_registryproperly births the size-tracking caches with metrics integration, naming them "bls_sig_cache" and "sig_val_cache" for the cosmic registries.
593-593: The helper function's pact has been rewritten in the language of the new cache order.The parameter type transformation aligns with the cosmic shift to size-tracking caches throughout the realm.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great to add a Grafana dashboard with all of those tracked metrics there for an easy check of total caches size.
|
@akaladarshi need your review here |
akaladarshi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary of changes
Changes introduced in this pull request:
SizeTrackingLruCachein more places as a follow-up of feat: addSizeTrackingLruCachefor tracking cache size metrics #5841Reference issue to close (if applicable)
Closes
Other information and links
Change checklist
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Style
Documentation