Skip to content

Enable strict json check in api compare#6949

Draft
sudo-shashank wants to merge 19 commits intomainfrom
shashank/enable-strict-json-check-ci
Draft

Enable strict json check in api compare#6949
sudo-shashank wants to merge 19 commits intomainfrom
shashank/enable-strict-json-check-ci

Conversation

@sudo-shashank
Copy link
Copy Markdown
Contributor

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

Summary of changes

Changes introduced in this pull request:

  • Set FOREST_STRICT_JSON=1 for all api compare check and fix the unknown field error found in some RPC response.

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

    • RPC message responses now include CID information
    • Version endpoint returns optional agent field
    • Network parameters endpoint includes genesis timestamp
    • Execution traces now include logs and IPLD operations
    • Fork upgrade parameters now include upgrade height information
  • Chores

    • Enhanced API validation to strictly enforce JSON schema compliance

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

coderabbitai Bot commented Apr 21, 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: 121055d8-47b3-4dc3-b8a2-f5317fcbe8aa

📥 Commits

Reviewing files that changed from the base of the PR and between b204c8b and 5f0e8ed.

⛔ 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 (2)
  • src/rpc/methods/eth.rs
  • src/rpc/methods/state/types.rs

Walkthrough

This PR implements strict JSON deserialization for RPC responses to detect unknown fields, adds CID serialization to message types, simplifies RPC response structures by removing wrapper types, extends execution traces and network parameters with new fields, and updates test infrastructure to validate against unknown fields during API parity testing.

Changes

Cohort / File(s) Summary
Docker & Environment Configuration
scripts/tests/api_compare/docker-compose.yml
Added FOREST_STRICT_JSON=1 environment variable to api-compare, api-compare-gateway, and api-compare-offline services to enable strict JSON validation in containers.
Message Lotus JSON Serialization
src/lotus_json/message.rs, src/lotus_json/signed_message.rs
Added optional cid field to MessageLotusJson serialization, updated test snapshots for Message and SignedMessage to include computed CID values in nested message representations.
RPC Response Type Simplifications
src/rpc/methods/chain.rs, src/rpc/methods/gas.rs
Removed FlattenedApiMessage wrapper struct; Filecoin.ChainGetMessage and Filecoin.GasEstimateMessageGas now return Message directly instead of flattening message and CID into separate fields.
RPC Response Type Extensions
src/rpc/methods/common.rs, src/rpc/methods/state.rs
Added optional agent field to PublicVersion; added genesis_timestamp to NetworkParams (from genesis block header) and activated upgrade_xx_height: ChainEpoch field in ForkUpgradeParams (defaulting to 999_999_999_999_999).
Execution Trace Type Modeling
src/rpc/methods/state/types.rs
Added new TraceIpldOp enum and TraceIpld struct for IPLD operation tracing; extended ExecutionTrace with logs: Vec<String> and ipld_ops: Vec<TraceIpld> fields (both default to empty), and replaced derived PartialEq with manual implementation that excludes these fields from equality checks.
Test Utilities & Helpers
src/rpc/methods/eth.rs, src/state_manager/utils.rs
Updated create_execution_trace test helper and ExecutionTrace construction in state manager to initialize logs and ipld_ops as empty vectors.
API Comparison Test Infrastructure
src/tool/subcommands/api_cmd/api_compare_tests.rs
Switched JSON deserialization in RpcTest::basic_raw and validate_raw from serde_json::from_value to from_value_rejecting_unknown_fields for strict field validation; simplified gas test closure to operate directly on message objects instead of extracting nested fields.
Stateful Test & Wallet Updates
src/tool/subcommands/api_cmd/stateful_tests.rs, src/wallet/subcommands/wallet_cmd.rs
Updated EIP-1559 transaction building to pass unsigned_msg directly instead of unsigned_msg.message field; simplified wallet send command to use GasEstimateMessageGas response directly without field extraction.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Suggested reviewers

  • hanabi1224
  • LesnyRumcajs
  • akaladarshi
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title "Enable strict json check in api compare" accurately captures the main change: enabling FOREST_STRICT_JSON=1 in Docker Compose for API comparison services.
Linked Issues check ✅ Passed All code changes directly address issue #5635's objective to deny unknown fields on RPC response deserialization. Changes include implementing strict JSON validation via FOREST_STRICT_JSON=1, adding cid/agent fields to RPC responses, updating message types to include CID, and fixing downstream code that depends on these responses.
Out of Scope Changes check ✅ Passed All changes are within scope of issue #5635. Updates to Docker Compose, RPC response types, test utilities for strict validation, and cascading code fixes are all necessary to implement and verify strict JSON deserialization for RPC responses.
Docstring Coverage ✅ Passed Docstring coverage is 87.10% which is sufficient. The required threshold is 80.00%.

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

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

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 (1)
src/rpc/methods/state.rs (1)

3283-3285: Clarify the placeholder value and naming.

The hardcoded value 999_999_999_999_999 serves as a far-future placeholder, which is reasonable for an unscheduled upgrade. However:

  1. The field name upgrade_xx_height is non-descriptive - consider using the actual upgrade name (e.g., upgrade_firehorse_height as suggested by the comment) for clarity.
  2. Consider adding a brief comment explaining why this placeholder exists, such as // Placeholder for FireHorse upgrade - not yet scheduled.

This helps maintainability when the actual upgrade height becomes known.

🤖 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 3283 - 3285, Rename the
non-descriptive field upgrade_xx_height to upgrade_firehorse_height (matching
the commented get_height(FireHorse)? hint) and replace the magic literal
999_999_999_999_999 with a named constant or at least retain the literal but add
a clear inline comment like "// Placeholder for FireHorse upgrade - not yet
scheduled" next to upgrade_firehorse_height; update any references to
upgrade_xx_height elsewhere (structs, serializers, tests) to the new name so the
code remains consistent and maintainable.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 34: Update the CHANGELOG.md entry that currently references PR `#6926` to
instead reference issue `#5635`: replace the PR link and label
"[`#6926`](https://github.com/ChainSafe/forest/pull/6926)" with the issue-style
link "[`#5635`](https://github.com/ChainSafe/forest/issues/5635)" in the line
describing strict JSON validation so the entry follows the repo convention of
referencing the issue rather than the PR.

In `@src/rpc/methods/state/types.rs`:
- Around line 152-156: Add a new TraceIpld struct and use it for the ipld_ops
field: define a pub struct TraceIpld with serde-backed fields matching Lotus
(pub op: String for "Get"/"Put"/"Unknown", pub cid: Option<String>, pub size:
Option<u64>) and derive Serialize/Deserialize/Debug/Clone; then change the
existing ipld_ops field from Vec<serde_json::Value> to Vec<TraceIpld> while
keeping #[serde(default, skip_serializing_if = "Vec::is_empty")] on the ipld_ops
declaration in the same type (the ExecutionTrace/struct containing ipld_ops) so
deserialization is type-safe and compatible when FVM trace IpldOps are present.

---

Nitpick comments:
In `@src/rpc/methods/state.rs`:
- Around line 3283-3285: Rename the non-descriptive field upgrade_xx_height to
upgrade_firehorse_height (matching the commented get_height(FireHorse)? hint)
and replace the magic literal 999_999_999_999_999 with a named constant or at
least retain the literal but add a clear inline comment like "// Placeholder for
FireHorse upgrade - not yet scheduled" next to upgrade_firehorse_height; update
any references to upgrade_xx_height elsewhere (structs, serializers, tests) to
the new name so the code remains consistent and maintainable.
🪄 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: 1dda2f00-e919-46da-b950-f2a7cd41b259

📥 Commits

Reviewing files that changed from the base of the PR and between 799007a and b204c8b.

⛔ Files ignored due to path filters (3)
  • Cargo.lock is excluded by !**/*.lock
  • 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 (19)
  • CHANGELOG.md
  • Cargo.toml
  • docs/docs/users/reference/env_variables.md
  • scripts/tests/api_compare/docker-compose.yml
  • src/lotus_json/message.rs
  • src/lotus_json/signed_message.rs
  • src/rpc/json_validator.rs
  • src/rpc/methods/chain.rs
  • src/rpc/methods/common.rs
  • src/rpc/methods/eth.rs
  • src/rpc/methods/gas.rs
  • src/rpc/methods/state.rs
  • src/rpc/methods/state/types.rs
  • src/rpc/reflect/mod.rs
  • src/rpc/reflect/parser.rs
  • src/state_manager/utils.rs
  • src/tool/subcommands/api_cmd/api_compare_tests.rs
  • src/tool/subcommands/api_cmd/stateful_tests.rs
  • src/wallet/subcommands/wallet_cmd.rs

Comment thread CHANGELOG.md
Comment thread src/rpc/methods/state/types.rs
@sudo-shashank sudo-shashank force-pushed the shashank/enable-strict-json-check-ci branch from f76d689 to f6ceac2 Compare April 23, 2026 00:40
@sudo-shashank sudo-shashank marked this pull request as ready for review April 23, 2026 00:49
@sudo-shashank sudo-shashank requested a review from a team as a code owner April 23, 2026 00:49
@sudo-shashank sudo-shashank removed the request for review from a team April 23, 2026 00:49
@sudo-shashank sudo-shashank marked this pull request as draft April 23, 2026 01:38
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

1 participant