Skip to content

Conversation

LesnyRumcajs
Copy link
Member

@LesnyRumcajs LesnyRumcajs commented Aug 6, 2025

Summary of changes

Changes introduced in this pull request:

Reference issue to close (if applicable)

Closes #5880

Other information and links

Sample usage:

curl --silent -X POST -H "Content-Type: application/json" \
                   --data '{"jsonrpc":"2.0","id":2,"method":"Forest.StateMarketDealsDump","params": [ null, "bla.json" ] }' \
                   "http://localhost:2345/rpc/experimental"
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'json'
require 'http'

rpc_url = 'http://localhost:2345/rpc/experimental'
method = 'Forest.StateMarketDealsFiltered'
wallets = ['f...', 'f...'] # put your addresses here


HTTP.post(
  rpc_url,
  headers: { 'Content-Type' => 'application/json' },
  json: {
    jsonrpc: '2.0',
    method: method,
    params: [nil,'AllowedClients': wallets, 'AllowedProviders': wallets],
    id: 1
  }
).then do |response|
  if response.status.success?
    result = response.body.to_s
    if result['error']
      puts "Error for #{wallets}: #{result['error']['message']}"
    else
      puts result
    end
  else
    puts "HTTP Error for #{wallets}: #{response.status}"
  end
end

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 support for an experimental API path, allowing access to experimental RPC methods.
    • Introduced two new RPC methods for Storage Market deals:
      • Ability to export all deals to an NDJSON file.
      • Ability to filter deals by client and/or provider addresses.
  • Enhancements

    • Improved deal iteration performance in Storage Market RPC methods.
    • Added new filtering options for retrieving Storage Market deals.
  • Chores

    • Updated dependencies to use specific Git revisions for certain libraries.

Copy link
Contributor

coderabbitai bot commented Aug 6, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes introduce new RPC methods for filtering and dumping Storage Market deals, extend the API to support an "experimental" endpoint, and update dependencies to use specific Git revisions for certain crates. Additional utility methods for iterating deal proposals are added, and the API versioning and client logic are updated to handle the new "experimental" path.

Changes

Cohort / File(s) Change Summary
Dependency Patch Update
Cargo.toml
Adds a [patch.crates-io] section to override fvm_ipld_* crates with a specific Git revision from ref-fvm. Removes commented local path overrides.
RPC Client Experimental Support
src/rpc/client.rs
Adds an experimental field and logic to the Client struct to support the new experimental API path, updating initialization and client retrieval.
Storage Market Deals RPC Methods
src/rpc/methods/state.rs
Introduces StateMarketDealsDump and StateMarketDealsFiltered RPC methods, a filter struct, and uses a new cacheless iteration method for deals.
RPC Method Registration
src/rpc/mod.rs
Registers new StateMarketDealsFiltered and StateMarketDealsDump methods in the macro for RPC method enumeration.
API Path Versioning
src/rpc/reflect/mod.rs, src/rpc/segregation_layer.rs
Adds Experimental variant to ApiPaths enum and updates version-methods mapping and corresponding tests.
Deal Proposal Iteration Utilities
src/shim/actors/builtin/market/mod.rs
Adds for_each_cacheless and count methods to DealProposals for alternative iteration and counting.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant UrlClient
    participant API

    Client->>Client: get_or_init_client(ApiPaths::Experimental)
    alt Not initialized
        Client->>UrlClient: Initialize with base_url + "/rpc/experimental"
        UrlClient-->>Client: Return new UrlClient
    else Already initialized
        Client-->>Client: Return existing UrlClient
    end
    Client->>API: Make request via experimental UrlClient
Loading
sequenceDiagram
    participant User
    participant RPC
    participant MarketState

    User->>RPC: Call StateMarketDealsFiltered(filter)
    RPC->>MarketState: Load market actor state
    MarketState->>MarketState: Iterate deals with for_each_cacheless
    MarketState->>RPC: Return filtered deals
    RPC-->>User: Return map of deal_id → deal

    User->>RPC: Call StateMarketDealsDump(tipset, file)
    RPC->>MarketState: Load market actor state
    MarketState->>MarketState: Iterate deals with for_each_cacheless
    MarketState->>RPC: Serialize and write each deal to NDJSON file
    RPC-->>User: Return success
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

RPC

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch amt-wibbles

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

@LesnyRumcajs
Copy link
Member Author

@CodeRabbit full review

Copy link
Contributor

coderabbitai bot commented Aug 6, 2025

✅ Actions performed

Full review triggered.

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

🧹 Nitpick comments (1)
src/rpc/methods/state.rs (1)

555-567: Consider adding progress reporting for large datasets.

For very large market deal datasets, users might benefit from progress reporting to track the dump operation.

You could add periodic progress logging:

+        let mut count = 0u64;
         da.for_each_cacheless(|deal_id, d| {
             let s = sa.get(deal_id)?.unwrap_or_else(DealState::empty);
             let market_deal = ApiMarketDeal {
                 proposal: d?.into(),
                 state: s.into(),
             };
             write!(
                 writer,
                 "{}\n",
                 crate::lotus_json::HasLotusJson::into_lotus_json_string(market_deal)?
             )?;
+            count += 1;
+            if count % 10000 == 0 {
+                tracing::info!("Dumped {} deals to {}", count, output_file);
+            }
             Ok(())
         })?;
+        tracing::info!("Successfully dumped {} deals to {}", count, output_file);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0874cee and 619631a.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • Cargo.toml (1 hunks)
  • src/rpc/client.rs (4 hunks)
  • src/rpc/methods/state.rs (4 hunks)
  • src/rpc/mod.rs (1 hunks)
  • src/rpc/reflect/mod.rs (2 hunks)
  • src/rpc/segregation_layer.rs (1 hunks)
  • src/shim/actors/builtin/market/mod.rs (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in the forest codebase, `vec` can be used as an `asyncwrite` implementation in test contexts. th...
Learnt from: hanabi1224
PR: ChainSafe/forest#5835
File: src/chain/tests.rs:58-76
Timestamp: 2025-08-04T13:36:22.993Z
Learning: In the Forest codebase, `Vec<u8>` can be used as an `AsyncWrite` implementation in test contexts. The user confirmed that tests using `&mut Vec<u8>` with `export` and `export_v2` functions compile and pass both locally and on CI.

Applied to files:

  • src/rpc/reflect/mod.rs
  • src/rpc/methods/state.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). (6)
  • GitHub Check: All lint checks
  • GitHub Check: cargo-publish-dry-run
  • GitHub Check: Build MacOS
  • GitHub Check: Build Ubuntu
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (rust)
🔇 Additional comments (13)
src/rpc/mod.rs (1)

210-211: LGTM! New RPC methods properly registered.

The addition of StateMarketDealsFiltered and StateMarketDealsDump follows the established pattern for registering RPC methods in the for_each_rpc_method macro. These methods are correctly placed in the state vertical section.

src/rpc/segregation_layer.rs (1)

19-24: LGTM! Experimental API path properly registered.

The addition of ApiPaths::Experimental to the version methods mapping correctly extends the segregation layer to support experimental RPC methods. This follows the same pattern as existing API versions and ensures experimental methods will be properly routed and validated.

src/rpc/reflect/mod.rs (2)

127-129: LGTM! Experimental API path properly implemented.

The new Experimental variant is well-implemented:

  • Uses a unique bitflag value (0b10000000) that doesn't conflict with existing variants
  • Includes proper case-insensitive string parsing annotation
  • Follows the established pattern for API path variants

Note that the all() method intentionally excludes the experimental path, which is appropriate for experimental features.


442-444: LGTM! Test coverage for experimental API path.

The test case properly verifies that the URI path /rpc/experimental correctly maps to the Experimental variant, ensuring the string parsing works as expected.

src/shim/actors/builtin/market/mod.rs (2)

389-435: LGTM! Well-implemented cacheless iteration method.

The for_each_cacheless method is correctly implemented:

  • Follows the same pattern as the existing for_each method
  • Properly delegates to the underlying array's for_each_cacheless method for all variants (V9-V16)
  • Maintains consistent error handling and function signature
  • Provides a memory-efficient alternative for iteration without caching

451-462: LGTM! Simple and correct count method.

The count method is properly implemented:

  • Correctly delegates to the underlying array's count method for all variants
  • Follows the established pattern for enum method delegation
  • Provides a useful utility for getting the total number of deal proposals
src/rpc/client.rs (4)

40-40: LGTM! Consistent field addition following established patterns.

The experimental field follows the same pattern as the existing version fields, using OnceCell for proper lazy initialization.


88-88: LGTM! Proper field initialization.

The experimental field is correctly initialized using the same pattern as other version fields.


167-167: LGTM! Consistent pattern matching extension.

The match arm correctly handles the ApiPaths::Experimental variant and returns the appropriate field reference.


176-176: LGTM! Appropriate URL path mapping.

The experimental API path mapping to "rpc/experimental" follows the established convention and will correctly construct the experimental endpoint URL.

src/rpc/methods/state.rs (3)

13-13: LGTM!

The import additions are appropriate for the new functionality - LotusJson for serialization and std::io::Write for file operations.

Also applies to: 71-71


501-501: Good optimization for memory efficiency.

Using for_each_cacheless instead of for_each is appropriate here as it avoids unnecessary caching when iterating over potentially large deal datasets.


572-584: LGTM!

The filter struct is well-designed with appropriate serialization attributes and optional fields for flexible filtering.

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.

Improve market state retrieval
1 participant