Skip to content

chore(perf): avoid redundant GenesisInfo reconstructions - #7458

Merged
LesnyRumcajs merged 1 commit into
mainfrom
cache-genesis-info
Aug 6, 2026
Merged

chore(perf): avoid redundant GenesisInfo reconstructions#7458
LesnyRumcajs merged 1 commit into
mainfrom
cache-genesis-info

Conversation

@LesnyRumcajs

@LesnyRumcajs LesnyRumcajs commented Aug 6, 2026

Copy link
Copy Markdown
Member

Summary of changes

Changes introduced in this pull request:

  • we do quite a bit of useless genesis info reconstructions in several places. They are relatively cheap, but still a lot of allocs and some minor conversions. This doesn't make sense because genesis info is constant - we can pretty much construct it once and then just have a shared pointer.

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

  • This pull request is based on an issue that a maintainer has accepted (see Before Opening a Pull Request).
  • 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

  • Bug Fixes
    • Improved consistency of genesis, circulating-supply, pledge, and market-fund information across RPC and message simulation workflows.
    • Ensured pledge and market-fund balances are initialized correctly when genesis data is created.
    • Preserved genesis information across state manager clones and cached supply calculations.

@LesnyRumcajs
LesnyRumcajs requested a review from a team as a code owner August 6, 2026 10:48
@LesnyRumcajs
LesnyRumcajs requested review from EclesioMeloJunior and akaladarshi and removed request for a team August 6, 2026 10:48
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

Genesis information reuse

Layer / File(s) Summary
Genesis information construction and caching
src/state_manager/circulating_supply.rs
GenesisInfo and GenesisInfoVesting no longer derive Default. Chain configuration initialization sets pledge and market-fund balances to zero. Cached calculation accepts Arc<Self>.
StateManager genesis information storage
src/state_manager/mod.rs
StateManager stores, initializes, clones, and exposes shared Arc<GenesisInfo> data.
RPC and simulation integration
src/rpc/mod.rs, src/rpc/methods/state.rs, src/state_manager/message_simulation.rs
RPC methods and message simulation use shared genesis information instead of constructing local instances.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant RPCMethod
  participant RPCState
  participant StateManager
  participant GenesisInfo
  RPCMethod->>RPCState: request genesis_info()
  RPCState->>StateManager: access shared genesis_info
  StateManager->>GenesisInfo: calculate circulating supply
  GenesisInfo-->>RPCMethod: return circulating supply
Loading

Suggested reviewers: hanabi1224, sudo-shashank

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 52.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: reusing shared GenesisInfo instances to avoid redundant reconstructions.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cache-genesis-info
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch cache-genesis-info

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/state_manager/mod.rs (1)

414-417: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document both new public accessors.

Both new public accessors lack rustdoc comments. Add documentation at each site.

  • src/state_manager/mod.rs#L414-L417: Document StateManager::genesis_info.
  • src/rpc/mod.rs#L535-L538: Document RPCState::genesis_info.

As per coding guidelines, “Document public functions and structs with doc comments.”

🤖 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/mod.rs` around lines 414 - 417, Document both public
genesis_info accessors with concise rustdoc comments: add documentation for
StateManager::genesis_info in src/state_manager/mod.rs lines 414-417 and
RPCState::genesis_info in src/rpc/mod.rs lines 535-538, describing that each
returns the corresponding GenesisInfo value.

Source: Coding guidelines

🤖 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.

Nitpick comments:
In `@src/state_manager/mod.rs`:
- Around line 414-417: Document both public genesis_info accessors with concise
rustdoc comments: add documentation for StateManager::genesis_info in
src/state_manager/mod.rs lines 414-417 and RPCState::genesis_info in
src/rpc/mod.rs lines 535-538, describing that each returns the corresponding
GenesisInfo value.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b75757fe-2fd9-4e37-8f94-bbbf23aa5303

📥 Commits

Reviewing files that changed from the base of the PR and between 3853f58 and 36eb846.

📒 Files selected for processing (5)
  • src/rpc/methods/state.rs
  • src/rpc/mod.rs
  • src/state_manager/circulating_supply.rs
  • src/state_manager/message_simulation.rs
  • src/state_manager/mod.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

@codecov

codecov Bot commented Aug 6, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.87879% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.11%. Comparing base (3853f58) to head (36eb846).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/state.rs 77.77% 0 Missing and 4 partials ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/mod.rs 94.65% <100.00%> (+0.03%) ⬆️
src/state_manager/circulating_supply.rs 78.29% <100.00%> (+0.08%) ⬆️
src/state_manager/message_simulation.rs 79.02% <100.00%> (-0.21%) ⬇️
src/state_manager/mod.rs 64.34% <100.00%> (+0.99%) ⬆️
src/rpc/methods/state.rs 44.04% <77.77%> (-0.12%) ⬇️

... and 9 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 3853f58...36eb846. 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.

@LesnyRumcajs
LesnyRumcajs enabled auto-merge August 6, 2026 12:05
@LesnyRumcajs
LesnyRumcajs added this pull request to the merge queue Aug 6, 2026
Merged via the queue into main with commit 9c30523 Aug 6, 2026
34 checks passed
@LesnyRumcajs
LesnyRumcajs deleted the cache-genesis-info branch August 6, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants