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
|
|
|
||
| const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); | ||
| const DEFAULT_ID_TO_DETERMINISTIC_ADDRESS_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); | ||
| const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(8192usize); |
There was a problem hiding this comment.
~27MiB maximum
cache_tipset_state_executed_tipset_5_size_bytes 10313496
# HELP tipset_state_executed_tipset_5_len Length of cache tipset_state_executed_tipset_5
# TYPE tipset_state_executed_tipset_5_len gauge
tipset_state_executed_tipset_5_len 3423
# HELP tipset_state_executed_tipset_5_cap Capacity of cache tipset_state_executed_tipset_5
# TYPE tipset_state_executed_tipset_5_cap gauge
tipset_state_executed_tipset_5_cap 8192
| const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); | ||
| const DEFAULT_ID_TO_DETERMINISTIC_ADDRESS_CACHE_SIZE: NonZeroUsize = nonzero!(1024usize); | ||
| const DEFAULT_TIPSET_CACHE_SIZE: NonZeroUsize = nonzero!(8192usize); | ||
| const DEFAULT_ID_TO_DETERMINISTIC_ADDRESS_CACHE_SIZE: NonZeroUsize = nonzero!(8192usize); |
There was a problem hiding this comment.
~0.6MiB maximum
cache_id_to_deterministic_address_6_size_bytes 61072
# HELP id_to_deterministic_address_6_len Length of cache id_to_deterministic_address_6
# TYPE id_to_deterministic_address_6_len gauge
id_to_deterministic_address_6_len 694
# HELP id_to_deterministic_address_6_cap Capacity of cache id_to_deterministic_address_6
# TYPE id_to_deterministic_address_6_cap gauge
id_to_deterministic_address_6_cap 8192
| fn read_cache_size() -> NonZeroUsize { | ||
| // Arbitrary number, can be adjusted | ||
| const DEFAULT: NonZeroUsize = nonzero!(1024usize); | ||
| const DEFAULT: NonZeroUsize = nonzero!(8192usize); |
There was a problem hiding this comment.
~45MiB maximum
cache_msg_in_tipset_1_size_bytes 23020119
# HELP msg_in_tipset_1_len Length of cache msg_in_tipset_1
# TYPE msg_in_tipset_1_len gauge
msg_in_tipset_1_len 4018
# HELP msg_in_tipset_1_cap Capacity of cache msg_in_tipset_1
# TYPE msg_in_tipset_1_cap gauge
msg_in_tipset_1_cap 8192
|
|
||
| /// Similar to `resolve_to_key_addr` in the `forest_vm` [`crate::state_manager`] but does not | ||
| /// allow `Actor` type of addresses. Uses `ts` to generate the VM state. | ||
| pub async fn resolve_to_key_addr( |
There was a problem hiding this comment.
@coderabbitai double check if this removed fn resolve_to_key_addr is logically identical to resolve_to_deterministic_address
There was a problem hiding this comment.
🧩 Analysis chain
Let me fetch the full body of the removed resolve_to_key_addr function to do a proper comparison.
🏁 Script executed:
#!/bin/bash
# Get the full diff for address_resolution.rs to see the complete removed function
git diff HEAD~1 -- src/state_manager/address_resolution.rs
Repository: ChainSafe/forest
Length of output: 29
🏁 Script executed:
#!/bin/bash
# Try fetching the full PR diff via GitHub CLI
gh pr diff 7077 --repo ChainSafe/forest | grep -A 80 "resolve_to_key_addr"
Repository: ChainSafe/forest
Length of output: 76
🏁 Script executed:
#!/bin/bash
# Fetch the PR diff via GitHub REST API (public repo, no auth needed)
curl -s -H "Accept: application/vnd.github.v3.diff" \
"https://api.github.com/repos/ChainSafe/forest/pulls/7077" \
| grep -A 80 "resolve_to_key_addr"
Length of output: 0
🏁 Script executed:
#!/bin/bash
# Check if there are any remaining references to resolve_to_key_addr in the codebase
rg "resolve_to_key_addr" -n -C 3
echo "---"
# Also check git log to find available commits
git log --oneline | head -5
Repository: ChainSafe/forest
Length of output: 61
🏁 Script executed:
#!/bin/bash
# Try to get the base branch SHA for the PR
curl -s "https://api.github.com/repos/ChainSafe/forest/pulls/7077" | \
python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('base',{}).get('sha',''))"
Length of output: 41
🏁 Script executed:
#!/bin/bash
# Fetch the base version of address_resolution.rs
curl -s "https://raw.githubusercontent.com/ChainSafe/forest/e0bca2ae61a44fd70a79abd6693a1378a2ec40dd/src/state_manager/address_resolution.rs"
Length of output: 4751
Now let me fetch the old resolve_to_key_addr helper from src/interpreter/mod.rs to complete the comparison.
🏁 Script executed:
#!/bin/bash
# Fetch the base version of interpreter/mod.rs to see the removed resolve_to_key_addr helper
curl -s "https://raw.githubusercontent.com/ChainSafe/forest/e0bca2ae61a44fd70a79abd6693a1378a2ec40dd/src/interpreter/mod.rs"
Length of output: 1212
@hanabi1224 I've retrieved and compared both implementations. Here's the detailed analysis:
Old StateManager::resolve_to_key_addr (removed)
match addr.protocol() {
BLS | Secp256k1 | Delegated => return Ok(*addr), // return as-is
Actor => return Err(...), // bail
_ => {} // falls through for ID
};
// For ID: calls standalone `resolve_to_key_addr` helper:
// 1. get_actor(addr) from StateTree
// 2. if delegated_address present → return it
// 3. else → load account state, return pubkey_address()New StateManager::resolve_to_deterministic_address
match address.protocol() {
BLS | Secp256k1 | Delegated => Ok(address), // return as-is
Actor => bail!(...), // bail
ID => {
// Cached; calls StateTree::resolve_to_deterministic_address:
// 1. if delegated_address present → return it
// 2. else → load account state, return pubkey_address()
}
}Verdict: Logically identical for all practical inputs, with two enhancements in the new version
| Aspect | Old resolve_to_key_addr |
New resolve_to_deterministic_address |
|---|---|---|
| BLS/Secp256k1/Delegated | return as-is ✅ | return as-is ✅ |
| Actor | error ✅ | error ✅ |
| ID → delegated_address present | return it ✅ | return it ✅ |
| ID → no delegated_address | pubkey_address() ✅ |
pubkey_address() ✅ |
| Caching | ❌ none | ✅ id_to_deterministic_address_cache |
_ => {} catch-all |
✅ (any unknown future protocol tries resolution) | ✅ exhaustive match (ID explicit) |
The underlying resolution for ID addresses — the standalone resolve_to_key_addr helper vs StateTree::resolve_to_deterministic_address — are also logically identical: both prefer delegated_address if present, otherwise fall back to the account actor's pubkey_address(). The AI summary for src/shim/state_tree.rs does note that the old had a "version/protocol-gated workaround" for delegated_address while the new is unconditional, but this is a minor edge-case difference in the StateTree layer, not a semantic divergence for normal usage.
In summary: yes, the removed resolve_to_key_addr is logically identical to resolve_to_deterministic_address, with the new version adding caching as an optimization on top.
🧠 Learnings used
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6381
File: src/lotus_json/actors/states/cron_state.rs:8-8
Timestamp: 2026-01-05T12:54:40.850Z
Learning: In Rust code reviews, do not derive Eq for a struct if any field does not implement Eq (e.g., types from external dependencies). If a type like CronStateLotusJson includes fields wrapping external dependencies that lack Eq, derive PartialEq (or implement PartialEq manually) but avoid deriving Eq. This ensures comparisons compile and reflect actual equivalence semantics. When needed, consider implementing custom PartialEq (and possibly Eq) only after ensuring all fields (or wrappers) implement Eq, or keep PartialEq-only if full equality semantics cannot be expressed.
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6381
File: src/lotus_json/actors/states/evm_state.rs:41-44
Timestamp: 2026-01-05T12:56:13.802Z
Learning: In Rust codebases (e.g., Forest), do not add #[cfg(test)] to functions already annotated with #[test]. The #[test] attribute ensures the function is compiled only for tests, so a separate #[cfg(test)] is redundant and can be removed if present. Apply this check to all Rust files that contain #[test] functions.
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6666
File: src/tool/subcommands/archive_cmd.rs:628-631
Timestamp: 2026-03-02T09:43:34.946Z
Learning: In Rust sources related to Forest snapshot handling, implement the rule: enable message_receipts and events (message_receipts: true, events: true) only for GC snapshots as defined in src/db/gc/snapshot.rs, since these are internal snapshots created during garbage collection. For user-facing export commands such as src/tool/subcommands/archive_cmd.rs, disable receipts and events by default (message_receipts: false, events: false) to keep user-facing snapshots smaller, unless explicitly requested. This guidance targets Rust files; apply consistently across similar snapshot-related modules, using the narrowest applicable scope when extending beyond the two specified files.
Learnt from: LesnyRumcajs
Repo: ChainSafe/forest PR: 6903
File: src/shim/executor.rs:243-251
Timestamp: 2026-04-14T17:24:13.631Z
Learning: In the ChainSafe/forest (LesnyRumcajs) codebase, do not require rustdoc comments on public methods when the method’s purpose is clearly self-explanatory from its name (e.g., `entries(&self)`, `into_entries(self)`). When reviewing Rust (`.rs`) files, avoid flagging missing documentation for these obviously named public APIs, reserving doc requirements for less clear or non-obvious public methods.
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.
| let block_cid = tipset.key().cid()?; | ||
| ETH_BLOCK_HASH_TX_CACHE | ||
| .get_or_else(&block_cid.into(), async move || { | ||
| .get_or_insert_async(&CidWrapper::from(block_cid), async move { |
There was a problem hiding this comment.
Do we not need to track the metrics for the ETH_BLOCK_HASH_TX_CACHE cache hits and miss here?
There was a problem hiding this comment.
I think we could add hit/miss metrics at SizeTrackingCache level instead of doing it one by one on caller side. I'd do this in a subsequent PR.
@coderabbitai please create a tracking issue for this.
There was a problem hiding this comment.
🧩 Analysis chain
@hanabi1224, I've created a tracking issue for adding hit/miss metrics at the SizeTrackingCache level. Here's the link once the script runs — it will be assigned to you.
The issue captures:
- The motivation (avoiding per-caller instrumentation in favor of a centralized approach)
- A link back to this PR and the specific comment
- The proposed work (adding prometheus-style counters keyed by cache name inside
SizeTrackingCache, coveringget_or_insert_with,get_or_insert_async, and other retrieval methods)
🏁 Script executed:
#!/bin/bash
gh issue create \
--repo ChainSafe/forest \
--title "feat: add hit/miss metrics to SizeTrackingCache" \
--body "## Summary
Currently, \`SizeTrackingCache\` does not track cache hit/miss metrics. Instead of adding per-caller instrumentation (e.g., on \`ETH_BLOCK_HASH_TX_CACHE\`, \`ETH_BLOCK_FULL_TX_CACHE\`, etc.), it would be cleaner and more scalable to implement hit/miss tracking centrally at the \`SizeTrackingCache\` level so all caches benefit automatically.
## Motivation
In PR `#7077`, \`ETH_BLOCK_HASH_TX_CACHE\` and \`ETH_BLOCK_FULL_TX_CACHE\` were migrated from \`ForestCache\` to \`SizeTrackingCache\`. During review, it was noted ([comment](https://github.com/ChainSafe/forest/pull/7077#discussion_r3264120152)) that hit/miss metrics are not currently tracked for these caches. Rather than doing this one by one on the caller side, the preferred approach is to add hit/miss metrics at the \`SizeTrackingCache\` level.
## Proposed Work
- Add hit and miss counters/metrics inside \`SizeTrackingCache\` (e.g., via \`prometheus\` counters keyed by cache name).
- Ensure \`get_or_insert_with\` and \`get_or_insert_async\` (and any other retrieval methods) increment the appropriate counter.
- Verify metrics are visible/exported via the existing metrics infrastructure.
## References
- PR `#7077` (context for this issue)
- Requested by `@hanabi1224`
" \
--assignee hanabi1224
Length of output: 76
🏁 Script executed:
#!/bin/bash
curl -s -X POST \
-H "Authorization: token ${GH_TOKEN}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/ChainSafe/forest/issues \
-d '{
"title": "feat: add hit/miss metrics to SizeTrackingCache",
"body": "## Summary\n\nCurrently, `SizeTrackingCache` does not track cache hit/miss metrics. Instead of adding per-caller instrumentation (e.g., on `ETH_BLOCK_HASH_TX_CACHE`, `ETH_BLOCK_FULL_TX_CACHE`, etc.), it would be cleaner and more scalable to implement hit/miss tracking centrally at the `SizeTrackingCache` level so all caches benefit automatically.\n\n## Motivation\n\nIn PR `#7077`, `ETH_BLOCK_HASH_TX_CACHE` and `ETH_BLOCK_FULL_TX_CACHE` were migrated from `ForestCache` to `SizeTrackingCache`. During review, it was noted ([comment](https://github.com/ChainSafe/forest/pull/7077#discussion_r3264120152)) that hit/miss metrics are not currently tracked for these caches. Rather than doing this one by one on the caller side, the preferred approach is to add hit/miss metrics at the `SizeTrackingCache` level.\n\n## Proposed Work\n\n- Add hit and miss counters/metrics inside `SizeTrackingCache` (e.g., via `prometheus` counters keyed by cache name).\n- Ensure `get_or_insert_with` and `get_or_insert_async` (and any other retrieval methods) increment the appropriate counter.\n- Verify metrics are visible/exported via the existing metrics infrastructure.\n\n## References\n\n- PR `#7077` (context for this issue)\n- Requested by `@hanabi1224`\n",
"assignees": ["hanabi1224"]
}' | jq '{number: .number, url: .html_url, title: .title}'
Length of output: 53
@hanabi1224, I'm unable to create the issue automatically in this environment due to authentication constraints. Here are the details you can use to open it manually:
Title: feat: add hit/miss metrics to SizeTrackingCache
Body:
## Summary
Currently, `SizeTrackingCache` does not track cache hit/miss metrics. Instead of adding per-caller instrumentation (e.g., on `ETH_BLOCK_HASH_TX_CACHE`, `ETH_BLOCK_FULL_TX_CACHE`, etc.), it would be cleaner and more scalable to implement hit/miss tracking centrally at the `SizeTrackingCache` level so all caches benefit automatically.
## Motivation
In PR `#7077`, `ETH_BLOCK_HASH_TX_CACHE` and `ETH_BLOCK_FULL_TX_CACHE` were migrated from `ForestCache` to `SizeTrackingCache`. During review, it was noted ([comment](https://github.com/ChainSafe/forest/pull/7077#discussion_r3264120152)) that hit/miss metrics are not currently tracked for these caches. Rather than doing this one by one on the caller side, the preferred approach is to add hit/miss metrics at the `SizeTrackingCache` level.
## Proposed Work
- Add hit and miss counters/metrics inside `SizeTrackingCache` (e.g., via `prometheus` counters keyed by cache name).
- Ensure `get_or_insert_with` and `get_or_insert_async` (and any other retrieval methods) increment the appropriate counter.
- Verify metrics are visible/exported via the existing metrics infrastructure.
## References
- PR `#7077` (context for this issue)
- Requested by `@hanabi1224`
Assignee: hanabi1224
You can create it directly at: https://github.com/ChainSafe/forest/issues/new
🧠 Learnings used
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6381
File: src/lotus_json/actors/states/cron_state.rs:8-8
Timestamp: 2026-01-05T12:54:40.850Z
Learning: In Rust code reviews, do not derive Eq for a struct if any field does not implement Eq (e.g., types from external dependencies). If a type like CronStateLotusJson includes fields wrapping external dependencies that lack Eq, derive PartialEq (or implement PartialEq manually) but avoid deriving Eq. This ensures comparisons compile and reflect actual equivalence semantics. When needed, consider implementing custom PartialEq (and possibly Eq) only after ensuring all fields (or wrappers) implement Eq, or keep PartialEq-only if full equality semantics cannot be expressed.
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6381
File: src/lotus_json/actors/states/evm_state.rs:41-44
Timestamp: 2026-01-05T12:56:13.802Z
Learning: In Rust codebases (e.g., Forest), do not add #[cfg(test)] to functions already annotated with #[test]. The #[test] attribute ensures the function is compiled only for tests, so a separate #[cfg(test)] is redundant and can be removed if present. Apply this check to all Rust files that contain #[test] functions.
Learnt from: sudo-shashank
Repo: ChainSafe/forest PR: 6498
File: src/rpc/methods/eth.rs:1778-1780
Timestamp: 2026-01-28T21:30:16.490Z
Learning: When reviewing Ethereum RPC method implementations (e.g., in src/rpc/methods/*.rs), treat the limit/lookback parameter as a sentinel flag: -1 indicates no lookback limit (equivalent to LOOKBACK_NO_LIMIT). Ensure code paths properly translate -1 to the defined constant, document the behavior in comments, and validate that any downstream logic respects an unlimited lookback rather than applying a default cap.
Learnt from: hanabi1224
Repo: ChainSafe/forest PR: 6666
File: src/tool/subcommands/archive_cmd.rs:628-631
Timestamp: 2026-03-02T09:43:34.946Z
Learning: In Rust sources related to Forest snapshot handling, implement the rule: enable message_receipts and events (message_receipts: true, events: true) only for GC snapshots as defined in src/db/gc/snapshot.rs, since these are internal snapshots created during garbage collection. For user-facing export commands such as src/tool/subcommands/archive_cmd.rs, disable receipts and events by default (message_receipts: false, events: false) to keep user-facing snapshots smaller, unless explicitly requested. This guidance targets Rust files; apply consistently across similar snapshot-related modules, using the narrowest applicable scope when extending beyond the two specified files.
Learnt from: LesnyRumcajs
Repo: ChainSafe/forest PR: 6903
File: src/shim/executor.rs:243-251
Timestamp: 2026-04-14T17:24:13.631Z
Learning: In the ChainSafe/forest (LesnyRumcajs) codebase, do not require rustdoc comments on public methods when the method’s purpose is clearly self-explanatory from its name (e.g., `entries(&self)`, `into_entries(self)`). When reviewing Rust (`.rs`) files, avoid flagging missing documentation for these obviously named public APIs, reserving doc requirements for less clear or non-obvious public methods.
There was a problem hiding this comment.
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
There was a problem hiding this comment.
@akaladarshi now we have automatic hit/miss stats for every SizeTrackingCache
There was a problem hiding this comment.
@hanabi1224 So I saw that the peek method doesn't record the cache hit or miss in quick cache.
Is it not worth tracking ? I mean we were not adding it to begin with but just want to confirm here once for the record.
There was a problem hiding this comment.
So I am asking specifically for the BadBlockCache since it use the peek only.
There was a problem hiding this comment.
@akaladarshi that makes sense. I don't think we need peek as the cache policy is now CLOCK-pro instead of LRU
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 |
| Self { | ||
| cache: self.cache.shallow_clone(), | ||
| } | ||
| Self(self.0.shallow_clone()) |
There was a problem hiding this comment.
It'd be nice to improve ergonomics here. Consider implementing Deref/DerefMut to avoid always specifying .0.
| /// | ||
| /// Gets or inserts an item in the cache with key. | ||
| /// Concurrent callers for the same key are coalesced — only one runs | ||
| /// `compute`, the rest wait on the result. |
There was a problem hiding this comment.
It was dropped by mistake. Fixed.
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