Skip to content

fix(sdk): eagerly bootstrap protocol version before first proof parse#3493

Open
QuantumExplorer wants to merge 3 commits intov3.1-devfrom
fix/sdk-protocol-version-bootstrap
Open

fix(sdk): eagerly bootstrap protocol version before first proof parse#3493
QuantumExplorer wants to merge 3 commits intov3.1-devfrom
fix/sdk-protocol-version-bootstrap

Conversation

@QuantumExplorer
Copy link
Copy Markdown
Member

@QuantumExplorer QuantumExplorer commented Apr 15, 2026

Summary

Close the bootstrap hole in the auto-detect protocol version feature from #3483.

Before: On a fresh auto-detect SDK the first `parse_proof_with_metadata_and_proof` call uses `PlatformVersion::latest()` as a fallback because no response metadata has been seen yet. On an older network whose proof interpretation differs from `latest()`, the very first proof-backed request fails before the SDK ever learns the correct version. The old doc comment on `parse_proof_with_metadata_and_proof` called this out as a known limitation and told users to pin the version explicitly via `SdkBuilder::with_version()` if they cared.

After: The first time `parse_proof_with_metadata_and_proof` runs on an auto-detect SDK, it transparently kicks off a one-shot `CurrentQuorumsInfo` unproved RPC, reads `metadata.protocol_version` from the response, and updates the SDK's cached version before the proof parse executes. A `tokio::sync::OnceCell` guarantees the bootstrap RPC runs at most once per SDK (and its clones) even under concurrent first calls — subsequent callers wait for the in-flight bootstrap to finish.

Design notes

  • Skipped for SDKs pinned via `SdkBuilder::with_version()`, mock SDKs, and any SDK that has already seen a response (`protocol_version != 0`).
  • Best-effort: if the bootstrap RPC itself fails the SDK logs a warning and falls back to the previous `latest()` behaviour, so partially-reachable networks still function.
  • Unproved path chosen intentionally: `CurrentQuorumsInfo::fetch_unproved_with_settings` does not itself call `parse_proof_with_metadata_and_proof`, so there's no re-entry into the bootstrap helper.
  • Protocol-version update reuses the existing `maybe_update_protocol_version` path, which already handles unknown-version validation.

Test plan

  • `cargo check --workspace --all-targets` — clean
  • CI: existing rs-sdk unit tests (`test_version_update_from_metadata`, `test_unknown_version_ignored`, etc.) still pass — they use mock SDKs so the bootstrap path is skipped.
  • Manual: `cargo test -p dash-sdk` locally
  • Follow-up: add an integration test hitting a real testnet node to verify the bootstrap RPC flows end-to-end

🤖 Generated with Claude Code

Summary by CodeRabbit

Release Notes

  • New Features

    • Protocol version now automatically detects and initializes on first SDK use, with fallback to the latest version if detection fails.
  • Chores

    • Updated .gitignore configuration.

QuantumExplorer and others added 2 commits April 15, 2026 14:45
The auto-detect protocol version feature introduced in #3483 updated the
cached version only *after* a proof-backed response was successfully
parsed. On a fresh auto-detect SDK the first parse therefore used
PlatformVersion::latest() as a fallback, so on an older network whose
proof interpretation differs from latest() the very first request could
fail before the SDK ever got a chance to learn the correct version.

Close that bootstrap hole by running a one-shot unproved RPC
(CurrentQuorumsInfo) the first time parse_proof_with_metadata_and_proof
is invoked, reading metadata.protocol_version from the response, and
updating the SDK's cached version before the proof parse runs. A
tokio::sync::OnceCell guarantees the bootstrap RPC runs at most once
per SDK (and its clones) even under concurrent first calls.

Skipped for pinned SDKs (with_version), mock SDKs, and any SDK that has
already seen a response. If the bootstrap RPC itself fails the SDK logs
a warning and falls back to the previous latest() behaviour so
partially-reachable networks still function.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added this to the v3.1.0 milestone Apr 15, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 15, 2026

📝 Walkthrough

Walkthrough

Updated .gitignore to exclude the entire .claude/ directory. Added protocol version bootstrapping to the SDK using Arc<tokio::sync::OnceCell<()>> to coordinate a single unproved RPC call that discovers and caches the protocol version before parsing proofs.

Changes

Cohort / File(s) Summary
Gitignore Update
.gitignore
Broadened exclusion from .claude/worktrees/ subdirectory to entire .claude/ directory.
Protocol Version Bootstrapping
packages/rs-sdk/src/sdk.rs
Added protocol_version_bootstrapped OnceCell field for coordinating one-shot bootstrap. Introduced ensure_protocol_version_bootstrapped() async method that fetches CurrentQuorumsInfo via unproved RPC when auto-detect is enabled and cached version is 0, updates metadata, and falls back to PlatformVersion::latest() on failure. Wired bootstrap into proof parsing flow and updated builder initialization.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant SDK
    participant OnceCell as OnceCell<br/>(Bootstrap)
    participant DAPI
    participant MetadataCache

    Client->>SDK: parse_proof_with_metadata_and_proof()
    SDK->>OnceCell: Check if bootstrap completed
    alt First call (OnceCell empty)
        OnceCell->>SDK: Bootstrap needed
        SDK->>SDK: Check if auto-detect enabled<br/>& cached version == 0
        alt Conditions met
            SDK->>DAPI: fetch_unproved<br/>CurrentQuorumsInfo
            DAPI-->>SDK: metadata with protocol_version
            SDK->>MetadataCache: Update cached<br/>protocol_version
            SDK->>OnceCell: Mark bootstrap complete
        else Conditions not met
            SDK->>OnceCell: Mark bootstrap complete<br/>(no-op)
        end
    else Already bootstrapped
        OnceCell-->>SDK: Bootstrap skipped<br/>(cached result)
    end
    SDK->>Client: Resume proof parsing
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

🐰 With whiskers twitched and paws alight,
The .claude now hides from git's keen sight,
Protocol versions bootstrap true,
One call to fetch, the cache renewed,
No more guessing—discovery's in flight! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: eagerly bootstrapping the protocol version before the first proof parse, which directly addresses the bootstrap gap described in the PR objectives.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% 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 fix/sdk-protocol-version-bootstrap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@thepastaclaw
Copy link
Copy Markdown
Collaborator

thepastaclaw commented Apr 15, 2026

⏳ Review in progress (commit 923c4af)

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/rs-sdk/src/sdk.rs`:
- Around line 357-360: The bootstrap RPC call uses RequestSettings::default()
which ignores the SDK-wide settings and caller overrides; replace that hardcoded
default with the SDK instance's configured RequestSettings (the field on the
client, e.g., self.request_settings or self.settings) and pass that into
CurrentQuorumsInfo::fetch_unproved_with_settings so the call honors
SdkBuilder::with_settings() and the SDK's retry/timeout policy.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: c7a31a89-fb63-46a6-af36-cebcad6b41dd

📥 Commits

Reviewing files that changed from the base of the PR and between 127ad5e and fd1e4a2.

📒 Files selected for processing (2)
  • .gitignore
  • packages/rs-sdk/src/sdk.rs

Comment on lines +357 to +360
match CurrentQuorumsInfo::fetch_unproved_with_settings(
self,
NoParamQuery {},
RequestSettings::default(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Use the SDK’s configured request settings for the bootstrap RPC.

Line 360 hardcodes RequestSettings::default(), so this new pre-parse RPC ignores both the SDK default retry policy and any caller overrides from SdkBuilder::with_settings(). That makes the first proof-backed request run under a different timeout/retry policy than every other SDK call.

Suggested fix
                 match CurrentQuorumsInfo::fetch_unproved_with_settings(
                     self,
                     NoParamQuery {},
-                    RequestSettings::default(),
+                    self.dapi_client_settings,
                 )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
match CurrentQuorumsInfo::fetch_unproved_with_settings(
self,
NoParamQuery {},
RequestSettings::default(),
match CurrentQuorumsInfo::fetch_unproved_with_settings(
self,
NoParamQuery {},
self.dapi_client_settings,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rs-sdk/src/sdk.rs` around lines 357 - 360, The bootstrap RPC call
uses RequestSettings::default() which ignores the SDK-wide settings and caller
overrides; replace that hardcoded default with the SDK instance's configured
RequestSettings (the field on the client, e.g., self.request_settings or
self.settings) and pass that into
CurrentQuorumsInfo::fetch_unproved_with_settings so the call honors
SdkBuilder::with_settings() and the SDK's retry/timeout policy.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 15, 2026

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "c4e7ddc282704f0a475ba2a8f9f187d52feede046a90605ef3479195aac1590b"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

{
// Learn the network protocol version before the first proof parse.
// No-op after the first successful call (and for pinned / mock SDKs).
self.ensure_protocol_version_bootstrapped().await;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think calling this function in SdkBuilder::build() will be simpler and (marginally) cheaper.

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.

3 participants