Skip to content

feat(rpc): add Forest.NetChainExchange for internal debugging#6824

Merged
hanabi1224 merged 2 commits intomainfrom
hm/NetChainExchange
Mar 31, 2026
Merged

feat(rpc): add Forest.NetChainExchange for internal debugging#6824
hanabi1224 merged 2 commits intomainfrom
hm/NetChainExchange

Conversation

@hanabi1224
Copy link
Copy Markdown
Contributor

@hanabi1224 hanabi1224 commented Mar 31, 2026

Summary of changes

Changes introduced in this pull request:

  • add Forest.NetChainExchange for internal debugging
  • make max concurrent chain exchange requests configurable via FOREST_MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS
  • update the default max concurrent chain exchange requests from 2 to 3 (which makes it faster on my laptop)

Conclusion:

Fetching 64 full tipsets is not much slower than fetching 64 tipset headers when max concurrency is updated to 3, not worth changing how the chain follower downloads tipsets.

Fetching full tipset:

{
    "jsonrpc": "2.0",
    "method": "Forest.NetChainExchange",
		"params": [
			[
				{
				"/": "bafy2bzaceccdj25cza7ofkygmqqaesbsuy75hun2durwwngwqduiqz5fcpney"
				},
				{
					"/": "bafy2bzacecxpe4pfypdx4f6z2hsy5tgvvra3loyprlupw7czrivfxf5adtsia"
				},
				{
					"/": "bafy2bzacea2z5gachypsuldr7bynvmdnqohzdws7oni5y4uwnfqgxcthqkjqw"
				}
			], 64, 3
  	],
    "id": 123
}
{
	"jsonrpc": "2.0",
	"id": 123,
	"result": "fetched 64 tipsets, took 496ms 544us 847ns"
}

Fetching tipset headers:

{
    "jsonrpc": "2.0",
    "method": "Forest.NetChainExchange",
		"params": [
			[
				{
				"/": "bafy2bzaceccdj25cza7ofkygmqqaesbsuy75hun2durwwngwqduiqz5fcpney"
				},
				{
					"/": "bafy2bzacecxpe4pfypdx4f6z2hsy5tgvvra3loyprlupw7czrivfxf5adtsia"
				},
				{
					"/": "bafy2bzacea2z5gachypsuldr7bynvmdnqohzdws7oni5y4uwnfqgxcthqkjqw"
				}
			], 64, 1
  	],
    "id": 123
}
{
	"jsonrpc": "2.0",
	"id": 123,
	"result": "fetched 64 tipsets, took 295ms 427us 572ns"
}

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.

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

    • Configurable limit for concurrent chain-exchange requests via env var (FOREST_MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS, default 3)
    • New admin-only RPC method Forest.NetChainExchange for performing chain exchange operations
  • Documentation

    • Added reference entry documenting the new environment variable
  • Tests

    • Updated ignored API test snapshots to include the new RPC endpoint

@hanabi1224 hanabi1224 added the RPC requires calibnet RPC checks to run on CI label Mar 31, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 31, 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: 3dbe16f6-cfcd-466a-88d8-51e71bd17663

📥 Commits

Reviewing files that changed from the base of the PR and between c388f49 and df802e9.

⛔ Files ignored due to path filters (3)
  • 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
  • src/rpc/snapshots/forest__rpc__tests__rpc__v2.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • src/tool/subcommands/api_cmd/test_snapshots_ignored.txt
✅ Files skipped from review due to trivial changes (1)
  • src/tool/subcommands/api_cmd/test_snapshots_ignored.txt

Walkthrough

Adds a new internal RPC method for chain exchange, exposes the chain-exchange handler, and makes the chain-exchange concurrency limit configurable via an environment variable; includes documentation and test-snapshot adjustments.

Changes

Cohort / File(s) Summary
Documentation
docs/docs/users/reference/env_variables.md
Add FOREST_MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS env var entry (positive integer, default 3) documenting the max concurrent chain-exchange requests.
Network Context
src/chain_sync/network_context.rs
Make concurrency configurable via LazyLock<NonZeroUsize> reading the env var (default 3); change RaceBatch::new to accept NonZeroUsize; expose handle_chain_exchange_request as pub async fn; update call sites/tests to use .get().
RPC Method Implementation
src/rpc/methods/net.rs
Add NetChainExchange RPC method (Forest.NetChainExchange) with params (ApiTipsetKey, u64, u64) and admin permission; validate len > 0, determine start tipset, time the operation, call handle_chain_exchange_request, and return a formatted string result.
RPC Registration
src/rpc/mod.rs
Register NetChainExchange in the for_each_rpc_method! macro alongside existing net methods.
Test/Tooling
src/tool/subcommands/api_cmd/test_snapshots_ignored.txt
Add Forest.NetChainExchange to ignored API snapshot list.

Sequence Diagram

sequenceDiagram
    participant Client
    participant RPC as Forest.NetChainExchange
    participant ChainStore
    participant SyncCtx as SyncNetworkContext

    Client->>RPC: Forest.NetChainExchange(startTipsetKey?, len, options)
    RPC->>RPC: Validate len > 0
    alt startTipsetKey provided
        RPC->>RPC: use provided key
    else
        RPC->>ChainStore: heaviest_tipset().key()
        ChainStore-->>RPC: tipset key
    end
    RPC->>RPC: start timer
    RPC->>SyncCtx: handle_chain_exchange_request(tipset_key, len)
    SyncCtx->>SyncCtx: fetch tipsets (respecting concurrency limit)
    SyncCtx-->>RPC: fetched tipsets count
    RPC->>RPC: compute elapsed time
    RPC-->>Client: "fetched N tipsets, took Xms"
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • LesnyRumcajs
  • sudo-shashank
  • akaladarshi
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

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.
✅ 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: adding a new RPC method Forest.NetChainExchange for internal debugging, which is the primary purpose across most of the modified files.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch hm/NetChainExchange
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hm/NetChainExchange

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

@hanabi1224 hanabi1224 marked this pull request as ready for review March 31, 2026 09:00
@hanabi1224 hanabi1224 requested a review from a team as a code owner March 31, 2026 09:00
@hanabi1224 hanabi1224 requested review from LesnyRumcajs and sudo-shashank and removed request for a team March 31, 2026 09:00
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.

🧹 Nitpick comments (1)
docs/docs/users/reference/env_variables.md (1)

66-66: Minor: Capitalize the description for consistency.

Other entries in this table start with a capital letter (e.g., "The passphrase...", "Load CAR files...", "Maximum number of..."). Consider capitalizing for consistency:

-| `FOREST_MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS`           | positive integer                | 3                                              | 3                                                             | number of max concurrent requests to send over chain exchange protocol                                                |
+| `FOREST_MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS`           | positive integer                | 3                                              | 3                                                             | Maximum number of concurrent requests to send over the chain exchange protocol                                        |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/docs/users/reference/env_variables.md` at line 66, Update the table
entry for the environment variable FOREST_MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS
by capitalizing the description text; replace "number of max concurrent requests
to send over chain exchange protocol" with a capitalized phrase such as "Number
of max concurrent requests to send over chain exchange protocol" (or improve to
"Maximum number of concurrent requests to send over chain exchange protocol") to
match the capitalization style of other entries.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/docs/users/reference/env_variables.md`:
- Line 66: Update the table entry for the environment variable
FOREST_MAX_CONCURRENT_CHAIN_EXCHANGE_REQUESTS by capitalizing the description
text; replace "number of max concurrent requests to send over chain exchange
protocol" with a capitalized phrase such as "Number of max concurrent requests
to send over chain exchange protocol" (or improve to "Maximum number of
concurrent requests to send over chain exchange protocol") to match the
capitalization style of other entries.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 38a8d526-1ffc-4dda-9199-d456adb1e8bf

📥 Commits

Reviewing files that changed from the base of the PR and between d52a294 and c388f49.

📒 Files selected for processing (4)
  • docs/docs/users/reference/env_variables.md
  • src/chain_sync/network_context.rs
  • src/rpc/methods/net.rs
  • src/rpc/mod.rs

@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 17.50000% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.85%. Comparing base (d52a294) to head (df802e9).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/rpc/methods/net.rs 0.00% 21 Missing ⚠️
src/chain_sync/network_context.rs 36.84% 11 Missing and 1 partial ⚠️
Additional details and impacted files
Files with missing lines Coverage Δ
src/rpc/mod.rs 89.20% <ø> (ø)
src/chain_sync/network_context.rs 30.43% <36.84%> (-0.77%) ⬇️
src/rpc/methods/net.rs 0.00% <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 d52a294...df802e9. 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.

@hanabi1224 hanabi1224 added this pull request to the merge queue Mar 31, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 31, 2026
@hanabi1224 hanabi1224 added this pull request to the merge queue Mar 31, 2026
Merged via the queue into main with commit 0b7f2b4 Mar 31, 2026
46 checks passed
@hanabi1224 hanabi1224 deleted the hm/NetChainExchange branch March 31, 2026 12:18
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.

2 participants