Skip to content

Enable strict json check in api compare#6970

Open
sudo-shashank wants to merge 10 commits intomainfrom
shashank/enable-strict-json-api
Open

Enable strict json check in api compare#6970
sudo-shashank wants to merge 10 commits intomainfrom
shashank/enable-strict-json-api

Conversation

@sudo-shashank
Copy link
Copy Markdown
Contributor

@sudo-shashank sudo-shashank commented Apr 28, 2026

Summary of changes

Changes introduced in this pull request:

  • Set FOREST_STRICT_JSON=1 for all api compare check.

  • Fix the unknown field error found in the below methods:

    • Filecoin.ChainGetBlockMessages
    • Filecoin.ChainGetMessagesInTipset
    • Filecoin.ChainGetParentMessages
    • Filecoin.MpoolPending
    • Filecoin.StateCall
    • Filecoin.StateGetNetworkParams
    • Filecoin.StateReplay
    • Filecoin.Version

Reference issue to close (if applicable)

Closes #5635

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

  • New Features

    • ChainGetMessage and GasEstimateMessageGas responses now include message CID.
    • StateGetNetworkParams now returns a genesis timestamp.
    • Version response includes an optional agent field.
    • ExecutionTrace now includes logs and IPLD operations.
    • Fork upgrade info now exposes an UpgradeFireHorseHeight field.
  • Refactor

    • Message-related RPC responses simplified to return the Message schema directly.

@sudo-shashank sudo-shashank added the RPC requires calibnet RPC checks to run on CI label Apr 28, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 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: babad8e2-a5da-475e-9035-fc14cc24d0ac

📥 Commits

Reviewing files that changed from the base of the PR and between dafcc4b and b49052a.

⛔ Files ignored due to path filters (2)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
📒 Files selected for processing (4)
  • docs/openrpc-specs/v0.json
  • docs/openrpc-specs/v1.json
  • src/rpc/methods/state.rs
  • src/tool/subcommands/api_cmd/test_snapshots.txt
✅ Files skipped from review due to trivial changes (1)
  • src/tool/subcommands/api_cmd/test_snapshots.txt

Walkthrough

Replace the FlattenedApiMessage wrapper with Message across OpenRPC and Rust code, add CID to Message, change Message.Params to Base64String defaulting to null, and extend ExecutionTrace (IpldOps, Logs), NetworkParams (GenesisTimestamp), PublicVersion (Agent), and ForkUpgradeParams (UpgradeFireHorseHeight). Enable FOREST_STRICT_JSON for api-compare tests.

Changes

Cohort / File(s) Summary
OpenRPC specs
docs/openrpc-specs/v0.json, docs/openrpc-specs/v1.json
Swap method result schemas from FlattenedApiMessageMessage. Remove FlattenedApiMessage and Nullable_Base64String. Add TraceIpld/TraceIpldOp. Add Message.CID, make Params: Base64String (default: null). Add ExecutionTrace.IpldOps and Logs. Add required NetworkParams.GenesisTimestamp. Add optional nullable PublicVersion.Agent. Add required ForkUpgradeParams.UpgradeFireHorseHeight.
Lotus JSON / message serialization
src/lotus_json/message.rs, src/lotus_json/signed_message.rs
MessageLotusJson.params changed from Option<RawBytes>RawBytes (default). Added optional cid: Option<Cid> serialized as CID. Updated test snapshots to include CID.
RPC method return types
src/rpc/methods/chain.rs, src/rpc/methods/gas.rs
Removed FlattenedApiMessage struct and usages. ChainGetMessage and GasEstimateMessageGas now return Message directly; removed CID computation/wrapping.
RPC types & tracing
src/rpc/methods/state/types.rs, src/rpc/methods/state.rs, src/rpc/methods/common.rs
Add TraceIpldOp enum and TraceIpld struct. Extend ExecutionTrace with logs and ipld_ops (serde defaults/skip). Implement custom PartialEq for ExecutionTrace to ignore logs/ipld differences. Add NetworkParams.genesis_timestamp: u64. Add PublicVersion.agent: Option<String>. Add ForkUpgradeParams.upgrade_fire_horse_height.
Trace initialization
src/rpc/methods/eth.rs, src/state_manager/utils.rs
Initialize ExecutionTrace.logs and ExecutionTrace.ipld_ops to empty Vecs where traces are constructed/created.
Tooling, tests, wallet
src/tool/subcommands/api_cmd/api_compare_tests.rs, src/tool/subcommands/api_cmd/stateful_tests.rs, src/wallet/subcommands/wallet_cmd.rs, src/tool/subcommands/api_cmd/test_snapshots.txt
Update api-compare and stateful tests and wallet flows to handle Message directly (no .message unwrap). Update test snapshot reference. Adjust EIP-1559/unsigned message usage accordingly.
Test runner config
scripts/tests/api_compare/docker-compose.yml
Enabled FOREST_STRICT_JSON=1 for api-compare services to enforce strict JSON validation in tests.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

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

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% 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 'Enable strict json check in api compare' is vague and does not fully capture the scope of the pull request. Consider a more specific title that reflects the actual changes, such as 'Deny unknown fields in RPC response deserialization and update schemas'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed The pull request implements the requirements from #5635 by enabling strict JSON deserialization and fixing all RPC response schema issues identified.
Out of Scope Changes check ✅ Passed All changes directly support the stated objectives: enabling strict JSON checks, fixing RPC schemas, and updating related code and tests.

✏️ 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 shashank/enable-strict-json-api
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch shashank/enable-strict-json-api

Review rate limit: 2/5 reviews remaining, refill in 25 minutes and 52 seconds.

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

@sudo-shashank sudo-shashank changed the title Enable strict json check Enable strict json check in api compare Apr 28, 2026
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/rpc/methods/state.rs (1)

3234-3284: ⚠️ Potential issue | 🟠 Major

upgrade_xx_height should be config-driven, not hardcoded.

Line 3284 hardcodes a sentinel epoch, so StateGetNetworkParams can diverge from the actual network config once that upgrade is scheduled (or on custom networks). Please source this value from ChainConfig (with an explicit fallback policy if needed) rather than embedding a literal.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/rpc/methods/state.rs` around lines 3234 - 3284, The code currently
hardcodes upgrade_xx_height to 999_999_999_999_999 in TryFrom<&ChainConfig> for
ForkUpgradeParams; instead, read the value from ChainConfig (use the existing
height lookup helper get_height or an explicit ChainConfig field for the XX
upgrade) and assign that to upgrade_xx_height, with a clear fallback policy
(e.g., use get_height(XX)? or fallback to
config.some_optional_xx_height.unwrap_or(default_epoch)) so
StateGetNetworkParams stays in sync with the network config. Locate this change
in the try_from implementation that constructs ForkUpgradeParams and replace the
literal with the config-driven lookup and fallback.
🧹 Nitpick comments (2)
src/lotus_json/message.rs (1)

120-120: Optional readability tweak for intentionally ignored CID.

Consider using an explicit ignored binding name and short comment for parity with signed_message.rs.

Suggested tiny cleanup
-            cid: _,
+            cid: _ignored_cid, // CID is derived from message fields; input CID is not used
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lotus_json/message.rs` at line 120, The ignored CID field in message.rs
is currently written as cid: _, which is less explicit; update the pattern to
use an explicit ignored binding like cid: _cid and add a short comment (e.g., //
intentionally ignored) to match the style used in signed_message.rs so the
intent is clear when reading the Message destructuring.
src/rpc/methods/state/types.rs (1)

204-213: Consider adding a short struct-level note explaining why logs/ipld_ops are excluded from equality.

The code is fine as-is; this would just make intent easier to retain for future changes around API-compare behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/rpc/methods/state/types.rs` around lines 204 - 213, Add a short doc
comment on the ExecutionTrace struct explaining why logs and ipld_ops are
intentionally excluded from the PartialEq implementation: they are
implementation-dependent and not part of API-level equality comparison. Update
the struct-level comment for ExecutionTrace (referencing fields logs and
ipld_ops and the PartialEq impl) to state this intent so future maintainers
understand why eq ignores those fields.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/rpc/methods/state.rs`:
- Around line 3234-3284: The code currently hardcodes upgrade_xx_height to
999_999_999_999_999 in TryFrom<&ChainConfig> for ForkUpgradeParams; instead,
read the value from ChainConfig (use the existing height lookup helper
get_height or an explicit ChainConfig field for the XX upgrade) and assign that
to upgrade_xx_height, with a clear fallback policy (e.g., use get_height(XX)? or
fallback to config.some_optional_xx_height.unwrap_or(default_epoch)) so
StateGetNetworkParams stays in sync with the network config. Locate this change
in the try_from implementation that constructs ForkUpgradeParams and replace the
literal with the config-driven lookup and fallback.

---

Nitpick comments:
In `@src/lotus_json/message.rs`:
- Line 120: The ignored CID field in message.rs is currently written as cid: _,
which is less explicit; update the pattern to use an explicit ignored binding
like cid: _cid and add a short comment (e.g., // intentionally ignored) to match
the style used in signed_message.rs so the intent is clear when reading the
Message destructuring.

In `@src/rpc/methods/state/types.rs`:
- Around line 204-213: Add a short doc comment on the ExecutionTrace struct
explaining why logs and ipld_ops are intentionally excluded from the PartialEq
implementation: they are implementation-dependent and not part of API-level
equality comparison. Update the struct-level comment for ExecutionTrace
(referencing fields logs and ipld_ops and the PartialEq impl) to state this
intent so future maintainers understand why eq ignores those fields.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1d5006cd-50f9-4bf8-9882-73c9293697ea

📥 Commits

Reviewing files that changed from the base of the PR and between 65c39a0 and e15b409.

⛔ Files ignored due to path filters (2)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • docs/openrpc-specs/v0.json
  • docs/openrpc-specs/v1.json
  • scripts/tests/api_compare/docker-compose.yml
  • src/lotus_json/message.rs
  • src/lotus_json/signed_message.rs
  • src/rpc/methods/common.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/state.rs
  • src/rpc/methods/state/types.rs
  • src/state_manager/utils.rs
  • src/tool/subcommands/api_cmd/test_snapshots.txt

@sudo-shashank sudo-shashank marked this pull request as ready for review April 28, 2026 02:15
@sudo-shashank sudo-shashank requested a review from a team as a code owner April 28, 2026 02:15
@sudo-shashank sudo-shashank requested review from LesnyRumcajs and akaladarshi and removed request for a team April 28, 2026 02:15
Comment thread docs/openrpc-specs/v1.json Outdated
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docs/openrpc-specs/v0.json (1)

10151-10189: ⚠️ Potential issue | 🟠 Major

Remove or make UpgradeXxHeight optional in the OpenRPC schema.

Lotus's StateGetNetworkParams returns UpgradeFireHorseHeight in ForkUpgradeParams, not UpgradeXxHeight. Forest's implementation hardcodes upgrade_xx_height to 999_999_999_999_999, but marking it as required in the OpenRPC schema will cause strict validation failures against Lotus responses, which omit this field entirely. Either remove UpgradeXxHeight from the schema or mark it as non-required to maintain compatibility.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/openrpc-specs/v0.json` around lines 10151 - 10189, The OpenRPC schema
currently lists UpgradeXxHeight as a required property in the ForkUpgradeParams
object which conflicts with Lotus's StateGetNetworkParams (which returns
UpgradeFireHorseHeight and omits UpgradeXxHeight) and forces strict validation
failures; update the schema by either removing UpgradeXxHeight from the
ForkUpgradeParams required array or moving UpgradeXxHeight out of the "required"
list (making it optional) so responses that omit upgrade_xx_height (Forest
hardcodes it but Lotus omits it) validate correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@docs/openrpc-specs/v0.json`:
- Around line 10151-10189: The OpenRPC schema currently lists UpgradeXxHeight as
a required property in the ForkUpgradeParams object which conflicts with Lotus's
StateGetNetworkParams (which returns UpgradeFireHorseHeight and omits
UpgradeXxHeight) and forces strict validation failures; update the schema by
either removing UpgradeXxHeight from the ForkUpgradeParams required array or
moving UpgradeXxHeight out of the "required" list (making it optional) so
responses that omit upgrade_xx_height (Forest hardcodes it but Lotus omits it)
validate correctly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 17b75584-731e-4e12-b601-7db4e794ecda

📥 Commits

Reviewing files that changed from the base of the PR and between e15b409 and 0869652.

⛔ Files ignored due to path filters (2)
  • src/rpc/snapshots/forest__rpc__tests__rpc__v0.snap is excluded by !**/*.snap
  • src/rpc/snapshots/forest__rpc__tests__rpc__v1.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • docs/openrpc-specs/v0.json
  • docs/openrpc-specs/v1.json
  • src/lotus_json/message.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/gas.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
  • src/tool/subcommands/api_cmd/stateful_tests.rs
  • src/wallet/subcommands/wallet_cmd.rs
✅ Files skipped from review due to trivial changes (1)
  • src/tool/subcommands/api_cmd/api_compare_tests.rs

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.12%. Comparing base (ad9abdd) to head (b49052a).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/state.rs 50.00% 0 Missing and 1 partial ⚠️
src/wallet/subcommands/wallet_cmd.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/lotus_json/message.rs 100.00% <100.00%> (ø)
src/lotus_json/signed_message.rs 92.45% <100.00%> (+0.45%) ⬆️
src/rpc/methods/chain.rs 56.58% <100.00%> (-0.05%) ⬇️
src/rpc/methods/common.rs 61.53% <100.00%> (+1.01%) ⬆️
src/rpc/methods/eth.rs 65.27% <100.00%> (+0.02%) ⬆️
src/rpc/methods/gas.rs 86.55% <100.00%> (-0.04%) ⬇️
src/rpc/methods/state/types.rs 100.00% <100.00%> (ø)
src/state_manager/utils.rs 79.90% <100.00%> (+0.09%) ⬆️
src/rpc/methods/state.rs 44.75% <50.00%> (+<0.01%) ⬆️
src/wallet/subcommands/wallet_cmd.rs 25.45% <0.00%> (ø)

... and 10 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 ad9abdd...b49052a. 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.

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.

Why the do the snap files change?

Comment thread src/rpc/methods/state.rs Outdated
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.

Deny unknown fields on RPC response deserialization

2 participants