Skip to content

fix: Inaccurate GetSize impl for a few types#7129

Draft
hanabi1224 wants to merge 3 commits into
mainfrom
hm/fix-get-size-impl
Draft

fix: Inaccurate GetSize impl for a few types#7129
hanabi1224 wants to merge 3 commits into
mainfrom
hm/fix-get-size-impl

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented Jun 2, 2026

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

Outside contributions

  • I have read and agree to the CONTRIBUTING document.
  • I have read and agree to the AI Policy document. I understand that failure to comply with the guidelines will lead to rejection of the pull request.

Summary by CodeRabbit

  • Refactor
    • Migrated heap-size accounting to a tracker-aware API across many types and collection helpers to enable incremental, threaded memory measurement.
    • Replaced numerous manual size implementations with derived or standardized behavior to simplify and unify sizing logic.
    • Updated collection helpers and tests to use the new tracker semantics for per-element and capacity-aware sizing and validation.

Review Change Stack

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Jun 2, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 767fb6b8-e544-4b6a-8799-95a4ade80463

📥 Commits

Reviewing files that changed from the base of the PR and between 16dbcda and aa31274.

📒 Files selected for processing (1)
  • src/state_manager/mod.rs

Walkthrough

Heap-size tracking is migrated from get_heap_size() -> usize to a tracker-threaded get_heap_size_with_tracker<T: GetSizeTracker>(...) -> (usize, T) API. Vector helpers and trait impls across blocks, proofs, collections, RPC types, shims, and the state manager were updated to thread and return a tracker.

Changes

GetSize trait migration to tracker-based API

Layer / File(s) Summary
Heap-size helper infrastructure redesign
src/utils/get_size/mod.rs
Vector/collection heap-size helpers now thread get_size2::GetSizeTracker through per-element sizing and return (heap_size, tracker). Tests updated to construct StandardTracker and validate derive attribute behavior.
Block & proof GetSize updates
src/blocks/header.rs, src/blocks/tipset.rs, src/blocks/vrf_proof.rs, src/shim/sector.rs
RawBlockHeader, Tipset, VRFProof, and PoStProof migrate to get_heap_size_with_tracker, summing tracked sizes of subfields; Tipset replaces derive with manual impl to handle lazily-initialized key.
Data collection GetSize updates
src/cid_collections/small_cid_vec.rs
SmallCidNonEmptyVec delegates sizing to nunny_vec_heap_size_helper(..., tracker) and returns (size, tracker).
RPC Ethereum type GetSize updates
src/rpc/methods/eth.rs, src/rpc/methods/eth/types.rs
EthBigInt implements get_heap_size_with_tracker. EthAddress, EthHash, Nonce, and Bloom derive GetSize with #[get_size(ignore)] on inner ethereum types, removing previous manual impls.
Shim and state type GetSize updates
src/shim/address.rs, src/shim/econ.rs, src/shim/state_tree.rs, src/shim/executor.rs
Address uses empty impl GetSize; TokenAmount and ActorState implement get_heap_size_with_tracker; Receipt and StampedEvent thread tracker through return_data and event.entries sizing via vector helper.
State manager integration
src/state_manager/mod.rs
ExecutedMessage implements get_heap_size_with_tracker, accumulating tracked heap sizes for message, receipt, and events. Import reference updated for GetSize.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant VecHelper as vec_heap_size_with_fn_helper
  participant Element as Element (GetSize)
  participant Tracker as GetSizeTracker
  Caller->>VecHelper: (vec, tracker, callback)
  loop for each vec[i]
    VecHelper->>Element: callback(&element, tracker)
    Element-->>VecHelper: (elem_heap_size, tracker)
  end
  VecHelper->>VecHelper: sum: heap + (capacity - len) * size_of
  VecHelper-->>Caller: (total_heap_size, tracker)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

rust

Suggested reviewers

  • akaladarshi
  • LesnyRumcajs
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix: Inaccurate GetSize impl for a few types' is partially related to the changeset but lacks specificity about the primary change. The title mentions fixing inaccurate GetSize implementations but is vague about the core improvement. Consider specifying that the fix involves transitioning to tracker-based heap-size accounting APIs across multiple types.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/fix-get-size-impl
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/fix-get-size-impl

Warning

Review ran into problems

🔥 Problems

Linked repositories: Couldn't analyze filecoin-project/lotus - clone failed: Clone operation failed: Stream initialization permanently failed: Received unknown message on Sandbox stream


Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Comment @coderabbitai help to get the list of available commands and usage tips.

@hanabi1224 hanabi1224 force-pushed the hm/fix-get-size-impl branch from 7742077 to 9e80f48 Compare June 2, 2026 11:17
@hanabi1224 hanabi1224 marked this pull request as ready for review June 2, 2026 11:19
@hanabi1224 hanabi1224 requested a review from a team as a code owner June 2, 2026 11:19
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and akaladarshi and removed request for a team June 2, 2026 11:19
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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/blocks/tipset.rs`:
- Around line 192-193: The code measures Tipset.headers by calling
nunny_vec_heap_size_helper(&self.headers, &mut tracker) which deref-coerces the
Arc<NonEmpty<CachingBlockHeader>> and bypasses Arc's tracker-aware measurement,
causing shared Arc allocations to be double-counted; change the measurement to
call self.headers.get_heap_size_with_tracker(&mut tracker).0 so
Arc<T>::get_heap_size_with_tracker runs and deduplicates shared ownership;
update the expression that computes heap_size (currently adding
nunny_vec_heap_size_helper(&self.headers, ...).0 +
self.key.get_heap_size_with_tracker(...).0) to use
self.headers.get_heap_size_with_tracker(...) instead of the nunny helper.
🪄 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: 264f9a18-f7dc-48c7-b86a-eeaa2b244b62

📥 Commits

Reviewing files that changed from the base of the PR and between a79a337 and 9e80f48.

📒 Files selected for processing (13)
  • src/blocks/header.rs
  • src/blocks/tipset.rs
  • src/blocks/vrf_proof.rs
  • src/cid_collections/small_cid_vec.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/eth/types.rs
  • src/shim/address.rs
  • src/shim/econ.rs
  • src/shim/executor.rs
  • src/shim/sector.rs
  • src/shim/state_tree.rs
  • src/state_manager/mod.rs
  • src/utils/get_size/mod.rs

Comment thread src/blocks/tipset.rs
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

❌ Patch coverage is 26.50602% with 61 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.30%. Comparing base (128a84e) to head (20e9746).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/blocks/header.rs 0.00% 19 Missing ⚠️
src/state_manager/mod.rs 0.00% 10 Missing ⚠️
src/blocks/tipset.rs 0.00% 8 Missing ⚠️
src/utils/get_size/mod.rs 75.86% 7 Missing ⚠️
src/shim/executor.rs 0.00% 5 Missing ⚠️
src/blocks/vrf_proof.rs 0.00% 2 Missing ⚠️
src/cid_collections/small_cid_vec.rs 0.00% 2 Missing ⚠️
src/rpc/methods/eth.rs 0.00% 2 Missing ⚠️
src/shim/econ.rs 0.00% 2 Missing ⚠️
src/shim/sector.rs 0.00% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/methods/eth/types.rs 65.71% <ø> (+1.57%) ⬆️
src/shim/address.rs 86.76% <ø> (+1.25%) ⬆️
src/blocks/vrf_proof.rs 33.33% <0.00%> (ø)
src/cid_collections/small_cid_vec.rs 74.46% <0.00%> (ø)
src/rpc/methods/eth.rs 65.40% <0.00%> (+0.14%) ⬆️
src/shim/econ.rs 94.07% <0.00%> (ø)
src/shim/sector.rs 75.79% <0.00%> (ø)
src/shim/state_tree.rs 58.50% <0.00%> (ø)
src/shim/executor.rs 85.94% <0.00%> (ø)
src/utils/get_size/mod.rs 72.54% <75.86%> (+12.54%) ⬆️
... and 3 more

... and 16 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 128a84e...20e9746. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@hanabi1224 hanabi1224 force-pushed the hm/fix-get-size-impl branch from 9e80f48 to 16dbcda Compare June 2, 2026 11:40
Comment thread src/blocks/header.rs
+ signature.get_heap_size()
+ parent_base_fee.get_heap_size()
(
miner_address.get_heap_size_with_tracker(&mut tracker).0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are you confident this is the correct use of this API? Seems in examples the tracker gets passed around by move. Not sure if there's a practical difference.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think they're equivalent. https://github.com/bircni/get-size2/blob/6d0ae91743cfba0efa29c3e11507ed0583a670aa/crates/get-size2/src/tracker.rs#L13

impl<T: GetSizeTracker> GetSizeTracker for &mut T {
    fn track<A>(&mut self, addr: *const A) -> bool {
        GetSizeTracker::track(*self, addr)
    }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't say for sure, but I trust you checked it.

Copy link
Copy Markdown
Member

@LesnyRumcajs LesnyRumcajs left a comment

Choose a reason for hiding this comment

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

Worth a changelog entry, given metrics were incorrect.

@LesnyRumcajs
Copy link
Copy Markdown
Member

Also, please provide numbers from before and after the change. It'd be good to have them for reference.

@hanabi1224 hanabi1224 marked this pull request as draft June 6, 2026 02:59
@hanabi1224 hanabi1224 marked this pull request as draft June 6, 2026 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RPC requires calibnet RPC checks to run on CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants