refactor: prefill RPC cache for collect_events#7077
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds sync/async get-or-insert APIs to SizeTrackingCache, promotes quick_cache dependency, standardizes CidWrapper and prelude usage, migrates all callers from resolve_to_key_addr to resolve_to_deterministic_address, refactors several cache wrappers to hold SizeTrackingCache directly, and updates ETH RPC caching and event-collection call sites. ChangesCache and Address Resolution Consolidation
Sequence DiagramsequenceDiagram
participant RPC as RPC / Daemon
participant EthHandler as EthEventHandler
participant StateMgr as StateManager
participant Cache as SizeTrackingCache
RPC->>EthHandler: collect_events(&StateMgr, tipset)
EthHandler->>StateMgr: load_executed_tipset(...)
EthHandler->>StateMgr: resolve_to_deterministic_address(...)
EthHandler->>Cache: get_or_insert_async(key, compute)
Cache-->>EthHandler: cached events / newly computed events
EthHandler-->>RPC: return events (or warn on error)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/state_manager/address_resolution.rs`:
- Around line 61-82: The initializer passed to
id_to_deterministic_address_cache.get_or_insert_async is performing an extra
insertion by calling self.id_to_deterministic_address_cache.push(id, resolved);
remove that redundant push so the initializer only computes and returns
Ok(resolved) (letting SizeTrackingCache::get_or_insert_async handle
insertion/size accounting); you can keep the resolution logic
(StateTree::new_from_root, resolve_to_deterministic_address, load_tipset_state)
unchanged—just delete the push call inside the async block.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 39d054a6-e444-407d-9bc5-765dfa106e52
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (30)
Cargo.tomlsrc/chain/store/chain_store.rssrc/chain_sync/bad_block_cache.rssrc/chain_sync/tipset_syncer.rssrc/daemon/mod.rssrc/db/blockstore_with_read_cache.rssrc/db/car/forest.rssrc/db/car/mod.rssrc/interpreter/fvm2.rssrc/interpreter/fvm3.rssrc/interpreter/fvm4.rssrc/interpreter/mod.rssrc/lib.rssrc/message_pool/msgpool/msg_pool.rssrc/message_pool/msgpool/provider.rssrc/message_pool/msgpool/selection.rssrc/rpc/methods/eth.rssrc/rpc/methods/eth/filter/mod.rssrc/rpc/methods/gas.rssrc/rpc/methods/mpool.rssrc/rpc/methods/wallet.rssrc/shim/state_tree.rssrc/state_manager/address_resolution.rssrc/state_manager/cache.rssrc/state_manager/message_simulation.rssrc/state_manager/mod.rssrc/state_migration/common/mod.rssrc/state_migration/common/state_migration.rssrc/state_migration/nv21/miner.rssrc/utils/cache/size_tracking.rs
💤 Files with no reviewable changes (2)
- src/db/car/mod.rs
- src/interpreter/mod.rs
b869240 to
45a4eff
Compare
45a4eff to
a8404ef
Compare
akaladarshi
left a comment
There was a problem hiding this comment.
@hanabi1224 There are some documents where we are still haven't updated the lru cache metrics such as metrics.md. Please update those as well.
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/state_manager/cache.rs (1)
62-74:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winHit/miss accounting is reversed here.
Line 66 only executes when the insert future is actually polled, so it marks a cache miss, not a hit. As written, computed entries increment
TIPSET_HIT, while cached reads incrementTIPSET_MISS.Suggested fix
- let mut hit = false; + let mut miss = false; let value = self .cache .get_or_insert_async(key, async { - hit = true; + miss = true; compute().await }) .await?; - if hit { - TIPSET_HIT.inc(); - } else { - TIPSET_MISS.inc(); - } + if miss { + TIPSET_MISS.inc(); + } else { + TIPSET_HIT.inc(); + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/state_manager/cache.rs` around lines 62 - 74, The hit/miss flag is inverted because the async closure given to get_or_insert_async runs only on cache misses; change the logic so hit starts true and the closure sets hit = false (so a computed entry marks a miss), then keep the TIPSET_HIT / TIPSET_MISS increments as-is; update the mutable variable usage around get_or_insert_async and the async closure that calls compute() to flip the boolean assignment (use hit = true before calling, and inside the async closure set hit = false).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/utils/cache/size_tracking.rs`:
- Around line 187-195: The compilation fails because get_or_insert_async uses
impl Future but std::future::Future is not imported; add the import "use
std::future::Future;" to the module's imports (top of
src/utils/cache/size_tracking.rs) so the function signature in
get_or_insert_async can resolve the Future trait; ensure the new use is grouped
with other std imports.
---
Outside diff comments:
In `@src/state_manager/cache.rs`:
- Around line 62-74: The hit/miss flag is inverted because the async closure
given to get_or_insert_async runs only on cache misses; change the logic so hit
starts true and the closure sets hit = false (so a computed entry marks a miss),
then keep the TIPSET_HIT / TIPSET_MISS increments as-is; update the mutable
variable usage around get_or_insert_async and the async closure that calls
compute() to flip the boolean assignment (use hit = true before calling, and
inside the async closure set hit = false).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f212dfa7-c1dc-4385-9772-3bcead221089
📒 Files selected for processing (2)
src/state_manager/cache.rssrc/utils/cache/size_tracking.rs
@akaladarshi docs updated |
dcc283b to
8bad44b
Compare
8bad44b to
4c777e8
Compare
…e/forest into hm/prefill-cache-collect-events
Summary of changes
Changes introduced in this pull request:
collect_eventsresolve_to_key_addrin favor ofid_to_deterministic_address. A few RPC methods (Filecoin.GasEstimateGasLimit,Filecoin.MpoolPushMessage,eth_call,trace_call) should benefit from this.SizeTrackingCacheid_to_deterministic_addresscache has a pretty good hit rateReference issue to close (if applicable)
Closes
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit
New Features
Refactor
Chores