Skip to content

Conversation

@hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Jan 26, 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.

Summary by CodeRabbit

  • Refactor

    • Unified cross-version state handling and policy wrapping to simplify version branching and conversions.
    • Consolidated imports and delegated conversion patterns across actors.
  • New Features

    • New uniform Policy wrapper and delegation-based state enums for multi-version compatibility.
    • CLI subcommand dispatch simplified to direct async execution.
  • Breaking Changes

    • Several actor helper accessors and conversion helpers removed or reshaped; some public actor methods were added or removed and may require client updates.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 26, 2026

Walkthrough

Centralizes policy handling into a new Policy wrapper with cross-version conversions, applies delegated_enum-based wrappers to many actor State types to replace per-version match dispatch, removes several extension methods/traits, and updates imports and call sites to use the unified conversion/delegation patterns.

Changes

Cohort / File(s) Change Summary
Core Policy Infrastructure
src/shim/runtime.rs, src/networks/mod.rs
Introduce Policy(pub PolicyV13) with From<&Policy> -> PolicyV9..V17 conversions; ChainConfig constructors now use .into() for policy initialization; imports updated to crate::shim::runtime::Policy.
Delegated Enum — Actor States
src/shim/actors/builtin/datacap/mod.rs, src/shim/actors/builtin/evm/mod.rs, src/shim/actors/builtin/init/mod.rs, src/shim/actors/builtin/multisig/mod.rs, src/shim/actors/builtin/reward/mod.rs, src/shim/actors/builtin/system/mod.rs, src/shim/actors/builtin/verifreg/mod.rs
Apply #[delegated_enum(impl_conversions)] to State enums, add delegate_state! usage to replace V8..V17 match arms, and add delegated-based helpers/constructors where present (e.g., tombstone/default_latest_version, get_vesting_schedule, root_key).
Delegated Enum — Utilities & Trees
src/shim/gas.rs, src/shim/state_tree.rs
Add delegated_enum to PriceList and StateTree<S>; replace explicit per-version From/dispatch with delegate_price_list!/delegate_state_tree! macros.
Miner API surface rework
src/shim/actors/builtin/miner/ext/mod.rs, src/shim/actors/builtin/miner/ext/partition.rs, src/shim/actors/builtin/miner/ext/state.rs, src/shim/actors/builtin/miner/mod.rs
Remove PartitionExt trait and several MinerStateExt helpers from ext/*; reintroduce helpers (allocated_sectors, load_allocated_sector_numbers, load_precommit_on_chain_info, recorded_deadline_info, terminated, expirations_epochs) as methods on State/Partition in miner/mod.rs; unify policy handling via policy.into().
Multisig & Verifreg extension changes
src/shim/actors/builtin/multisig/ext/mod.rs, src/shim/actors/builtin/multisig/ext/state.rs, src/shim/actors/builtin/multisig/mod.rs, src/shim/actors/builtin/verifreg/ext/mod.rs, src/shim/actors/builtin/verifreg/ext/state.rs, src/shim/actors/builtin/verifreg/mod.rs
Remove MultisigExt trait and its vesting accessor; remove VerifiedRegistryStateExt::root_key from ext; convert multisig and verifreg State to delegated enums and add delegated get_vesting_schedule/root_key on the public State types.
RPC and policy usage updates
src/rpc/methods/f3.rs, src/shim/actors/builtin/power/mod.rs
Replace per-version policy conversion helpers (from_policy_v13_to_*) with let policy = &ctx.chain_config().policy and use policy.into() at call sites; consolidate per-version branches via delegation.
Transaction parsing & multisig RPC simplifications
src/shim/actors/macros.rs, src/shim/actors/builtin/multisig/mod.rs, src/rpc/methods/msig.rs
Update parse macros and multisig parsing to use .into() or direct fields for txn mappings; re-export parse_pending_transactions macros crate-locally; simplify msig RPC handling to avoid redundant conversions.
Conversion removals
src/shim/actors/convert.rs
Remove four padded-piece-size conversion helpers (v2↔v3/v4 variants).
Imports, shim surface, and CLI changes
src/shim/actors/mod.rs, src/shim/mod.rs, src/rpc/methods/state.rs, src/cli/*
Remove old Policy re-export from shim::actors; add pub mod runtime and pub type MethodNum in shim::mod.rs; consolidate imports; adjust some call sites to pass Address/ID directly; make CLI Subcommand delegated and add async run paths.
Minor type/usage simplifications
src/shim/actors/builtin/account/mod.rs, src/state_manager/circulating_supply.rs, src/state_manager/mod.rs, src/cli/subcommands/config_cmd.rs, src/state_migration/nv17/miner.rs
Remove unused imports; use ms.locked_balance(height)? directly (no .into()); add Debug derive to StateEvents; make Dump command async with an internal run helper; minor test call-site adjustments.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • LesnyRumcajs
  • akaladarshi
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 38.03% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: introducing delegated_enum patterns throughout the codebase to reduce repetitive code. Multiple files show this pattern being applied to State enums and related types.

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

✨ Finishing touches
  • 📝 Generate docstrings

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

@hanabi1224 hanabi1224 marked this pull request as ready for review January 26, 2026 17:31
@hanabi1224 hanabi1224 requested a review from a team as a code owner January 26, 2026 17:31
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and akaladarshi and removed request for a team January 26, 2026 17:31
Copy link
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

🤖 Fix all issues with AI agents
In `@src/shim/actors/builtin/multisig/ext/state.rs`:
- Around line 6-8: The empty impl block "impl MultisigExt for State {}" must
either be removed or completed: implement the trait's required method
get_vesting_schedule on State (or forward to the existing concrete
implementation in mod.rs) so the trait contract is satisfied; update the impl
block to include fn get_vesting_schedule(&self, ...) -> ... calling the existing
implementation in mod.rs (or delete the empty impl entirely if the trait is
already implemented elsewhere) and ensure the signature exactly matches
MultisigExt's declaration.
🧹 Nitpick comments (1)
src/shim/actors/builtin/multisig/mod.rs (1)

110-116: Consider propagating errors instead of using .expect().

The PendingTxnMap::load calls use .expect("Could not load pending transactions") which will panic on failure. Per coding guidelines, production code should avoid unwrap() and expect() where possible, preferring ? for error propagation.

♻️ Suggested fix
             State::V12(st) => {
                 let txns = fil_actor_multisig_state::v12::PendingTxnMap::load(
                     store,
                     &st.pending_txs,
                     fil_actor_multisig_state::v12::PENDING_TXN_CONFIG,
                     "pending txns",
-                )
-                .expect("Could not load pending transactions");
+                )?;
                 parse_pending_transactions_v4!(res, txns);
                 Ok(res)
             }

Apply similar changes to V13-V17 branches.

Also applies to: 121-127, 132-138, 143-149, 154-160, 165-171

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 34.03141% with 126 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.03%. Comparing base (327f9e5) to head (d99f3cf).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/shim/actors/builtin/miner/mod.rs 44.23% 24 Missing and 5 partials ⚠️
src/shim/runtime.rs 22.22% 21 Missing ⚠️
src/shim/actors/builtin/multisig/mod.rs 16.66% 13 Missing and 2 partials ⚠️
src/rpc/methods/f3.rs 0.00% 13 Missing ⚠️
src/shim/actors/builtin/power/mod.rs 7.14% 10 Missing and 3 partials ⚠️
src/shim/actors/builtin/reward/mod.rs 22.22% 6 Missing and 1 partial ⚠️
src/shim/actors/builtin/verifreg/mod.rs 30.00% 5 Missing and 2 partials ⚠️
src/shim/actors/macros.rs 33.33% 6 Missing ⚠️
src/rpc/methods/msig.rs 62.50% 0 Missing and 3 partials ⚠️
src/shim/actors/builtin/evm/mod.rs 0.00% 2 Missing ⚠️
... and 10 more
Additional details and impacted files
Files with missing lines Coverage Δ
src/cli/main.rs 53.33% <100.00%> (+21.19%) ⬆️
src/cli/subcommands/config_cmd.rs 94.73% <100.00%> (+0.98%) ⬆️
src/networks/mod.rs 88.73% <100.00%> (ø)
src/shim/actors/builtin/account/mod.rs 100.00% <ø> (ø)
src/shim/actors/builtin/miner/ext/state.rs 12.24% <ø> (-5.56%) ⬇️
src/shim/actors/builtin/verifreg/ext/state.rs 26.21% <ø> (-0.28%) ⬇️
src/shim/actors/convert.rs 24.88% <ø> (-0.63%) ⬇️
src/state_migration/nv17/miner.rs 81.61% <100.00%> (ø)
src/cli/subcommands/mod.rs 8.33% <66.66%> (+8.33%) ⬆️
src/rpc/methods/state.rs 44.40% <0.00%> (ø)
... and 18 more

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hanabi1224 hanabi1224 force-pushed the hm/more-delegate-enum-2 branch from 9b8e5ff to 6822c55 Compare January 26, 2026 17:51
@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Jan 26, 2026
Copy link
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: 3

🤖 Fix all issues with AI agents
In `@src/shim/actors/builtin/multisig/mod.rs`:
- Around line 178-183: Add a rustdoc comment for the public function
get_vesting_schedule describing what the function returns and under what
conditions it may error: document that get_vesting_schedule returns the multisig
vesting schedule as an MsigVesting (fields: initial_balance, start_epoch,
unlock_duration), that it reads from the actor state via delegate_state! and
that it returns an anyhow::Result which may contain an error if state access
fails; include examples or panics only if relevant and tag return value with #
Returns and # Errors headings.

In `@src/shim/actors/builtin/verifreg/mod.rs`:
- Around line 275-277: The public method root_key() lacks rustdoc; add a /// doc
comment above pub fn root_key(&self) -> Address describing its purpose (returns
the verifier registry's root key address), what it returns (Address) and any
important behavior/ownership/format expectations, and include examples or notes
if needed for callers; place the doc immediately above the root_key function
declaration so the new public API is documented.

In `@src/shim/runtime.rs`:
- Around line 14-28: Add a rustdoc comment for the public Policy wrapper
explaining that Policy is a transparent newtype wrapper around PolicyV13,
describing its purpose and typical usage (e.g., that it delegates to PolicyV13
behavior and preserves serialization via #[serde(transparent)]), mention any
important invariants or versioning note (PolicyV13) and include a short example
or pointer to PolicyV13 docs; place the doc comment immediately above the pub
struct Policy declaration referencing Policy and PolicyV13.
🧹 Nitpick comments (7)
src/shim/actors/macros.rs (1)

10-29: Consider consolidating identical macros.

parse_pending_transactions and parse_pending_transactions_v3 have identical implementations. If they're meant to behave the same, consider removing one and aliasing. If divergence is expected, a brief comment clarifying the intent would help future maintainers.

Also applies to: 36-55

src/shim/actors/builtin/miner/ext/state.rs (2)

14-185: Opportunity to apply delegated_enum pattern here as well.

The load_sectors_ext method has 10 nearly identical match arms (V8-V17), each following the same pattern. Given this PR's goal of reducing repetitive code with delegated_enum, this method could potentially benefit from the same treatment in a follow-up.


5-6: Remove unused imports from lines 5-6.

ChainEpoch, Policy, and anyhow::Context are not used in this file. These can be safely removed from the imports.

♻️ Cleanup
-use crate::shim::{actors::convert::*, clock::ChainEpoch, runtime::Policy};
-use anyhow::Context as _;
+use crate::shim::actors::convert::*;
src/shim/actors/builtin/evm/mod.rs (1)

57-75: Add rustdoc for the new TombstoneState API.
Public enum and constructor lack rustdoc (Line 60, Line 72).

Suggested doc additions
+/// EVM tombstone state across actor versions.
 pub enum TombstoneState {
@@
 impl TombstoneState {
+    /// Constructs the latest-version tombstone state.
     pub fn default_latest_version(origin: fvm_shared4::ActorID, nonce: u64) -> Self {
         TombstoneState::V17(fil_actor_evm_state::v17::Tombstone { origin, nonce })
     }
 }
As per coding guidelines, public items should have rustdoc comments.
src/shim/actors/builtin/miner/mod.rs (1)

413-447: Add rustdoc for allocated_sectors.
Line 413 introduces a new public method without rustdoc.

Suggested doc addition
+    /// Returns the CID of the allocated sectors bitfield.
     pub fn allocated_sectors(&self) -> Cid {
         delegate_state!(self.allocated_sectors)
     }
As per coding guidelines, public items should have rustdoc comments.
src/cli/subcommands/config_cmd.rs (1)

18-22: Add rustdoc and confirm clippy won’t flag unused_async.
New public run lacks rustdoc, and it currently doesn’t await. With --deny=warnings, please verify clippy::unused_async isn’t triggered; if it is, add a targeted allow or adjust the structure. As per coding guidelines, public functions should be documented.

✍️ Suggested rustdoc
-    pub async fn run(self, _: rpc::Client) -> anyhow::Result<()> {
+    /// Execute the config subcommand.
+    pub async fn run(self, _: rpc::Client) -> anyhow::Result<()> {
         self.run_internal(&mut std::io::stdout())
     }
src/cli/subcommands/mod.rs (1)

106-109: Add rustdoc for the new public run method.
As per coding guidelines, public functions should be documented.

✍️ Suggested rustdoc
 impl Subcommand {
+    /// Execute the selected CLI subcommand.
     pub async fn run(self, client: crate::rpc::Client) -> anyhow::Result<()> {
         delegate_subcommand!(self.run(client).await)
     }
 }

Copy link
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.

LGTM

@hanabi1224 hanabi1224 enabled auto-merge January 27, 2026 16:32
@hanabi1224 hanabi1224 added this pull request to the merge queue Jan 27, 2026
Merged via the queue into main with commit 59fef10 Jan 27, 2026
34 checks passed
@hanabi1224 hanabi1224 deleted the hm/more-delegate-enum-2 branch January 27, 2026 17:15
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.

3 participants