Skip to content

Add support for datacap actor in state decode params API#5871

Merged
sudo-shashank merged 24 commits intomainfrom
shashank/datacap-decode-params
Aug 13, 2025
Merged

Add support for datacap actor in state decode params API#5871
sudo-shashank merged 24 commits intomainfrom
shashank/datacap-decode-params

Conversation

@sudo-shashank
Copy link
Copy Markdown
Contributor

@sudo-shashank sudo-shashank commented Jul 28, 2025

Summary of changes

Changes introduced in this pull request:

  • Added datacap actor support in state decode params with tests.

Reference issue to close (if applicable)

Closes #5717

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

  • New Features
    • Added DataCap actor support to RPC method registry for versions 9–16.
    • state-decode API now decodes DataCap parameters (constructor, mint, destroy, balance, transfer/transferFrom, allowance ops, burn/burnFrom).
    • Added lotus-json parameter representations for DataCap to ensure consistent cross-version serialization.
  • Tests
    • Added comprehensive tests covering DataCap v16 parameter decoding.
    • Added snapshot files for DataCap state-decode cases.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 28, 2025

Walkthrough

Adds Datacap actor LotusJson parameter wrappers (v9–v16), registers Datacap actor methods in the RPC MethodRegistry for versions 9–16, and extends state_decode_params API tests and snapshots to cover Datacap (notably v16). A new datacap registry module and its module declaration were added. No public API signatures changed.

Changes

Cohort / File(s) Summary of changes
Lotus JSON Datacap Params
src/lotus_json/actor_states/methods/datacap_actor_params.rs, src/lotus_json/actor_states/methods/mod.rs
Added LotusJson wrapper structs and HasLotusJson impls for Datacap parameter types across actor versions v9–v16; added mod datacap_actor_params to methods mod.
RPC Registry — Datacap actor
src/rpc/registry/actors/datacap.rs, src/rpc/registry/actors/mod.rs, src/rpc/registry/methods_reg.rs
New datacap registry module implementing registration macros and register_datacap_actor_methods; integrated datacap into actors mod and MethodRegistry dispatch for BuiltinActor::DataCap (v9–v16); tests updated to include DataCap.
Tooling tests and snapshots
src/tool/subcommands/api_cmd/api_compare_tests.rs, src/tool/subcommands/api_cmd/test_snapshots.txt
Added state_decode_params API test cases for Datacap (v16) and 16 corresponding snapshot entries for datacap method decodings.

Sequence Diagram(s)

sequenceDiagram
  participant Registry as MethodRegistry
  participant Datacap as registry::actors::datacap
  participant Macro as register_actor_methods!
  Registry->>Datacap: register_datacap_actor_methods(cid, version)
  Datacap->>Macro: register method deserializers for version
  Macro-->>Registry: Methods registered
Loading
sequenceDiagram
  participant Client
  participant API as Filecoin.StateDecodeParams
  participant Registry as MethodRegistry
  participant Decoder as Datacap LotusJson
  Client->>API: stateDecodeParams(address, method, params, tipset)
  API->>Registry: lookup actor/version + method decoder
  Registry->>Decoder: deserialize params (versioned)
  Decoder-->>API: decoded JSON params
  API-->>Client: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Support Datacap in Filecoin.StateDecodeParams API (overall) [#5717]
Version support V9–V16 [#5717]
Version support V8 [#5717] No registration or LotusJson bridging added for v8; v8 remains unimplemented.

Possibly related PRs

Suggested reviewers

  • akaladarshi
  • LesnyRumcajs
  • hanabi1224

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3ff7c4 and 9616cce.

📒 Files selected for processing (1)
  • src/tool/subcommands/api_cmd/api_compare_tests.rs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: Build Ubuntu
  • GitHub Check: Build MacOS
  • GitHub Check: All lint checks
  • GitHub Check: tests-release
  • GitHub Check: tests
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (rust)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch shashank/datacap-decode-params

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sudo-shashank sudo-shashank added the RPC requires calibnet RPC checks to run on CI label Jul 29, 2025
@sudo-shashank sudo-shashank marked this pull request as ready for review August 1, 2025 10:12
@sudo-shashank sudo-shashank requested a review from a team as a code owner August 1, 2025 10:12
@sudo-shashank sudo-shashank requested review from LesnyRumcajs and hanabi1224 and removed request for a team August 1, 2025 10:12
Comment thread src/lotus_json/actor_states/methods/datacap_balance_params.rs Outdated
hanabi1224
hanabi1224 previously approved these changes Aug 1, 2025
@sudo-shashank sudo-shashank marked this pull request as draft August 4, 2025 11:58
@sudo-shashank sudo-shashank force-pushed the shashank/datacap-decode-params branch from e33651b to 4679180 Compare August 5, 2025 09:57
@sudo-shashank sudo-shashank marked this pull request as ready for review August 5, 2025 10:28
hanabi1224
hanabi1224 previously approved these changes Aug 5, 2025
@LesnyRumcajs LesnyRumcajs requested review from akaladarshi and removed request for LesnyRumcajs August 5, 2025 16:21
@LesnyRumcajs
Copy link
Copy Markdown
Member

I'll let the state decode params expert, @akaladarshi, review this one.

Copy link
Copy Markdown
Collaborator

@akaladarshi akaladarshi left a comment

Choose a reason for hiding this comment

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

@sudo-shashank I think this implementation is incomplete. Right now, it only supports ConstructorParams, MintParams, DestroyParams, and BalanceParams, but there are many more methods that are still missing. You can check this in the builtin-actor.

Look at the methods being called and the parameters they accept builtin-actor.

Sometimes, the method parameters are not defined in builtin-actor actors types.rs (so they won’t be in the fil-actor-state crate either). Instead, they’re imported from other crates. Even in that case, we still need to support them in Forest.

For example, in the verified_reg actor, see this code where UniversalReceiverParams is imported from the fvm_actor_utils crate. We also need to implement the HasLotusJson trait for it, as shown here.

Also, if a method doesn’t take any parameters, we still need to handle that. In such cases, use the empty type. You can see an example of this in the power actor here, no need to include this in test as it should not return any result.

Edit: You can cross check if all the methods are implemented or not by checking all the versions of go-state-types, this is what lotus uses.

@sudo-shashank
Copy link
Copy Markdown
Contributor Author

@sudo-shashank I think this implementation is incomplete. Right now, it only supports ConstructorParams, MintParams, DestroyParams, and BalanceParams, but there are many more methods that are still missing. You can check this in the builtin-actor.

Look at the methods being called and the parameters they accept builtin-actor.

Sometimes, the method parameters are not defined in builtin-actor actors types.rs (so they won’t be in the fil-actor-state crate either). Instead, they’re imported from other crates. Even in that case, we still need to support them in Forest.

For example, in the verified_reg actor, see this code where UniversalReceiverParams is imported from the fvm_actor_utils crate. We also need to implement the HasLotusJson trait for it, as shown here.

Also, if a method doesn’t take any parameters, we still need to handle that. In such cases, use the empty type. You can see an example of this in the power actor here, no need to include this in test as it should not return any result.

Edit: You can cross check if all the methods are implemented or not by checking all the versions of go-state-types, this is what lotus uses.

all methods are now supported

@sudo-shashank sudo-shashank marked this pull request as ready for review August 11, 2025 13:31
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: 2

🧹 Nitpick comments (3)
src/tool/subcommands/api_cmd/api_compare_tests.rs (2)

2303-2315: Duplicate test: Multisig LockBalance added twice

The second LockBalance test is a duplicate of the first and can be dropped to keep the suite lean.

Proposed diff:

-        RpcTest::identity(StateDecodeParams::request((
-            Address::new_id(18101), // https://calibration.filscan.io/en/address/t018101/,
-            fil_actor_multisig_state::v16::Method::LockBalance as u64,
-            to_vec(&multisig_lock_bal_params)?,
-            tipset.key().into(),
-        ))?),

1810-1916: Optional: Factor Datacap test setup for maintainability

The function is very large. Consider extracting a “make_datacap_v16_decode_tests(tipset)” helper that builds datacap params and the 16 test cases. This keeps state_decode_params_api_tests readable and reduces future merge conflicts.

Also applies to: 2056-2151

src/lotus_json/actor_states/methods/datacap_methods.rs (1)

1-14: NIT: small documentation hint for version coverage

Consider a short module-level comment documenting which datacap versions are supported per param group (e.g., Balance/Constructor start at v11). Helps future maintainers cross-check against builtin-actors.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4679180 and 09a6dd1.

📒 Files selected for processing (7)
  • src/lotus_json/actor_states/methods/datacap_methods.rs (1 hunks)
  • src/lotus_json/actor_states/methods/mod.rs (1 hunks)
  • src/rpc/registry/actors/datacap.rs (1 hunks)
  • src/rpc/registry/actors/mod.rs (1 hunks)
  • src/rpc/registry/methods_reg.rs (2 hunks)
  • src/tool/subcommands/api_cmd/api_compare_tests.rs (2 hunks)
  • src/tool/subcommands/api_cmd/test_snapshots.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/rpc/registry/actors/datacap.rs
🧰 Additional context used
🧬 Code Graph Analysis (3)
src/rpc/registry/methods_reg.rs (1)
src/rpc/registry/actors/datacap.rs (1)
  • register_datacap_actor_methods (121-137)
src/tool/subcommands/api_cmd/api_compare_tests.rs (1)
src/shim/address.rs (2)
  • new_id (141-143)
  • default (121-123)
src/lotus_json/actor_states/methods/datacap_methods.rs (3)
src/shim/address.rs (1)
  • new_id (141-143)
src/tool/subcommands/api_cmd/api_compare_tests.rs (4)
  • serde_json (262-262)
  • serde_json (292-292)
  • serde_json (301-301)
  • serde_json (302-302)
src/shim/econ.rs (1)
  • from_atto (98-100)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: tests
  • GitHub Check: tests-release
  • GitHub Check: Build forest binaries on Linux AMD64
🔇 Additional comments (19)
src/rpc/registry/actors/mod.rs (1)

5-5: Module wiring LGTM

datacap module is correctly exposed alongside existing actor modules; ordering remains consistent.

src/lotus_json/actor_states/methods/mod.rs (1)

6-6: LotusJson datacap module inclusion looks good

The datacap_methods module is properly declared; this aligns with registry wiring and tests.

src/rpc/registry/methods_reg.rs (3)

76-78: Importing datacap actor module into registry is correct

Consistent with other actor imports; no concerns.


65-73: Error message remains clear for unregistered methods

The bail! path still surfaces detailed context (actor type, version, method). Good for debugging.


75-98: Version coverage for DataCap: verify V8 handling per issue #5717

register_known_methods handles DataCap versions via datacap::register_datacap_actor_methods (v9–v16 per datacap.rs). Issue #5717 requests V8–V16 support or justification. If V8 DataCap didn’t exist or params were unavailable, please document explicitly in code comments or CHANGELOG.

Would you confirm whether there is any DataCap actor at V8 in the code registry? If not, please add a brief comment near the match to state “DataCap actor exists from v9+” to close the loop with the issue’s acceptance criteria.

src/tool/subcommands/api_cmd/api_compare_tests.rs (2)

1853-1916: Datacap v16 test vectors: types/fields look correct

Constructor/Mint/Destroy/Balance and FRC-46 types (Transfer*, Allowance*, Burn*, GetAllowance) are instantiated with appropriate Address/TokenAmount/RawBytes. Using TokenAmount::default() is fine for identity tests.


2056-2151: Comprehensive Datacap StateDecodeParams coverage (v16) — one thing to confirm

The “no-params” methods (Name/Symbol/TotalSupply/Granularity) pass empty bytes. Ensure the datacap registry registers these with the empty handler, so the deserializer returns {} (or base64 when non-empty), matching Lotus behavior.

Can you confirm datacap.rs registers these as empty via register_actor_methods!(..., [(Method::X, empty), ...])?

src/lotus_json/actor_states/methods/datacap_methods.rs (12)

16-52: BalanceParams: solid LotusJson wrapper; v11–v16 only — verify earlier versions

The implementation and snapshot are correct. Coverage starts at v11. If BalanceParams also exists in v9 or v10, consider adding them; otherwise, add a note in datacap.rs explaining earliest supported version for this param.

Would you confirm whether datacap::v9/v10 define BalanceParams? If yes, extend the macro; if not, add a brief comment in datacap.rs to document why v9/v10 aren’t included for BalanceParams.


53-89: ConstructorParams wrapper: v11–v16 covered — confirm need for earlier versions

Same note as BalanceParams. If ConstructorParams exist in earlier versions, extend macro; else, document earliest version.


90-139: DestroyParams: v9–v16 coverage with correct Address/TokenAmount mapping

Serde/schemars and tests are correct; using from_atto(1e18) fits i64 range. LGTM.


140-199: MintParams: v9–v16 coverage OK; operators mapped as Vec

Good use of iterator map for address conversion. LGTM.


200-249: TransferParams: RawBytes lotus_json mapping is correct

operator_data passed through transparently; snapshot encodes as base64 as expected. LGTM.


250-305: TransferFromParams: Address/TokenAmount/RawBytes mappings correct

Round-trip snapshots cover base64 semantics. LGTM.


307-349: IncreaseAllowanceParams: correct JSON shape and conversions

No issues spotted.


350-391: DecreaseAllowanceParams: correct JSON shape and conversions

No issues spotted.


393-428: RevokeAllowanceParams: correct mapping of operator address

No issues.


429-464: BurnParams: TokenAmount mapping correct

No issues.


465-506: BurnFromParams: owner + amount mapping correct

No issues.


508-550: GetAllowanceParams: owner/operator mapping correct

No issues.

Comment thread src/rpc/registry/methods_reg.rs
Comment thread src/tool/subcommands/api_cmd/test_snapshots.txt Outdated
Copy link
Copy Markdown
Collaborator

@akaladarshi akaladarshi left a comment

Choose a reason for hiding this comment

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

Rename the filename datacap_methods -> datacap_actor_params

Comment thread src/rpc/registry/actors/datacap.rs
Comment thread src/rpc/registry/actors/datacap.rs
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

🧹 Nitpick comments (1)
src/lotus_json/actor_states/methods/datacap_actor_params.rs (1)

114-118: Nit: Prefer wider integer type for TokenAmount literals.

The atto values use i64 (1e18 fits but is close to the limit for typical monetary literals growth). Consider i128 to avoid accidental overflow if test values change.

Example:

-amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i64).into(),
+amount: TokenAmount::from_atto(1_000_000_000_000_000_000_i128).into(),

Also applies to: 168-176, 225-231, 279-285, 327-333, 371-376, 445-450, 486-491

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e5c0fce and a3ff7c4.

📒 Files selected for processing (3)
  • src/lotus_json/actor_states/methods/datacap_actor_params.rs (1 hunks)
  • src/lotus_json/actor_states/methods/mod.rs (1 hunks)
  • src/rpc/registry/actors/datacap.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/rpc/registry/actors/datacap.rs
  • src/lotus_json/actor_states/methods/mod.rs
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/lotus_json/actor_states/methods/datacap_actor_params.rs (2)
src/shim/address.rs (1)
  • new_id (142-144)
src/shim/econ.rs (1)
  • from_atto (106-108)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: Build MacOS
  • GitHub Check: Build Ubuntu
  • GitHub Check: tests-release
  • GitHub Check: tests
  • GitHub Check: Build forest binaries on Linux AMD64
  • GitHub Check: All lint checks
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (rust)
🔇 Additional comments (2)
src/lotus_json/actor_states/methods/datacap_actor_params.rs (2)

214-248: FRC46 param wrappers and RawBytes handling look solid.

  • Using fil_actors_shared FRC46 types directly is correct.
  • RawBytes is serialized via the LotusJson codec (base64), matching the snapshots.
  • Address and TokenAmount conversions via shim are consistent.

No changes requested here.

Also applies to: 267-305, 318-349, 361-392, 401-428, 437-464, 476-507, 519-549


90-99: Confirm JSON key casing consistency for Datacap params

The #[serde(rename_all = "PascalCase")] on these LotusJson wrapper structs will serialize fields as "Owner", "Amount", etc., but your stored snapshots and FRC-46 spec appear to use snake-/lower-case keys (e.g. "owner", "amount"). Please:

  • Verify the expected JSON field casing via the Lotus/go-state-types definitions for FRC-46 Datacap methods.
  • If snapshots and spec use snake-case, remove the #[serde(rename_all = "PascalCase")] lines.
  • Otherwise update your snapshots (and any downstream tests) to expect PascalCase.

Affected structs (file src/lotus_json/actor_states/methods/datacap_actor_params.rs):

  • DatacapDestroyParamsLotusJson (lines 90–99)
  • TransferParamsLotusJson (201–202)
  • TransferFromParamsLotusJson (251–252)
  • IncreaseAllowanceParamsLotusJson (308–309)
  • DecreaseAllowanceParamsLotusJson (351–352)
  • RevokeAllowanceParamsLotusJson (394–395)
  • BurnParamsLotusJson (466–467)
  • BurnFromParamsLotusJson (509–510)

Comment thread src/lotus_json/actor_states/methods/datacap_actor_params.rs
Comment thread src/tool/subcommands/api_cmd/api_compare_tests.rs
@sudo-shashank sudo-shashank added this pull request to the merge queue Aug 13, 2025
Merged via the queue into main with commit fe7278c Aug 13, 2025
43 checks passed
@sudo-shashank sudo-shashank deleted the shashank/datacap-decode-params branch August 13, 2025 14:53
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.

Add support for the Datacap actor state in Filecoin.StateDecodeParams API

4 participants