Skip to content

feat(swift-sdk): default SDK to the adaptive context provider in Auto mode - #5883

Merged
shumkov merged 5 commits into
v5.1-devfrom
shumkov/adaptive-swift-default
Nov 13, 2026
Merged

shumkov merged 5 commits into
v5.1-devfrom
shumkov/adaptive-swift-default

Conversation

@shumkov

@shumkov shumkov commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Middle of GitHub Stack #5885 (#5882 → this → #5884)

Issue being fixed or feature implemented

SDK(network:) built the trusted context provider. So every SwiftDashSDK consumer that did not choose a provider verified Platform proofs with the trusted quorum service's keys. That includes dashwallet-ios, which builds SDK(network:platformVersion:) and configures one PlatformWalletManager on it, and it held even while the manager ran a synced SPV client. With #5882, Auto mode is a safe default: SPV keys once SPV has synced, the trusted service before that and for any key SPV cannot serve.

What was done?

  • SDK.init's contextProvider defaults to .adaptive. Rust builds it in Auto mode, so Swift sets no mode.
  • Consumers without a manager: an SDK that no PlatformWalletManager serves (none configured with configure(sdk:)) verifies exactly as before, with the same trusted provider, quorum prefetch and contract cache. The observable differences are:
    • setQuorumMode now succeeds;
    • dash_sdk_get_status reports a mode.
  • Consumers with a manager: a manager configured with the SDK serves it its SPV quorum keys. Only one manager serves an SDK, so configuring a second with the same default SDK while the first holds it throws. await shutdown() the old manager first, or pass .trusted. dashwallet-ios builds a fresh SDK per manager, so it is not affected by the one-manager rule. Its proofs move to SPV keys on its next Platform pin bump.
  • Docs:
    • ContextProviderKind, QuorumMode.auto (only as strong as the trusted service; use .spv to fail closed) and quorumSource (the source asked first);
    • the SwiftExampleApp's picker/indicator help and AppState docs, plus a CHANGELOG [Unreleased] migration entry.
  • SwiftDashSDKIntegrationTests' env builds its SDK .trusted explicitly. It replaces its manager, and tests build throwaway managers, on that one SDK while another manager is alive.

How Has This Been Tested?

  • SDKQuorumSourceTests.testShouldBuildAnAdaptiveSdkInAutoByDefault: the default SDK reports trusted, then SPV and trusted as the mode changes. It fails on the old default, whose trusted SDK refuses setQuorumMode.
  • testShouldRefuseAModeChangeOnAnExplicitTrustedSdk pins the opt-out.
  • AppStateQuorumModeTests.testShouldRestoreTheSavedQuorumModeOnLaunch checks that a relaunch restores the saved mode. The parity manifest in feat(kotlin-sdk): bridge the adaptive context provider and build it by default #5884 cites it for restart coverage.
  • Written on a machine without Xcode, so these run only in CI (swift-sdk-build).

Breaking Changes

Source-compatible: only a default argument value changes. Behaviour changes for callers that relied on the default:

  • the proof trust root moves to SPV once a manager's SPV syncs;
  • one wallet manager per SDK.

The CHANGELOG entry describes both and the way back (contextProvider: .trusted). There is no !: the repository reserves ! for consensus-breaking changes (coding conventions).

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • The Swift SDK now defaults to adaptive quorum routing. It uses trusted quorum keys when no wallet manager provides SPV, and can switch to SPV after the manager syncs; trusted keys remain available when SPV cannot provide them.
    • You can still explicitly select trusted or SPV mode.
  • Documentation
    • Updated guidance in the Swift example app to explain adaptive routing and quorum-source status.

@shumkov
shumkov added this pull request to stack #5885 November 12, 2026 07:56
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

No actionable comments were generated in the recent review.

Walkthrough

The Swift SDK initializer now defaults to adaptive quorum mode. Documentation describes how the SDK reports and selects quorum sources. Tests cover mode switching, explicit trusted mode, and restoration of the saved app mode.

Changes: Swift SDK quorum mode

Layer / File(s) Summary
SDK default and quorum-source contract
packages/swift-sdk/Sources/SwiftDashSDK/SDK.swift, packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift, packages/swift-sdk/SwiftTests/SwiftDashSDKTests/SDKQuorumSourceTests.swift, packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Support/IntegrationTestEnv.swift, packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swift, CHANGELOG.md
The SDK initializer now defaults to .adaptive. Documentation describes trusted and SPV source selection, fallback behavior, and the meaning of quorumSource. Tests check adaptive mode changes and explicit trusted mode. The integration test environment now selects .trusted explicitly.
Example app mode and restoration
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/AppState.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/OptionsView.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleAppTests/AppStateQuorumModeTests.swift
App comments and help text describe adaptive routing and source reporting. A test checks that a saved .spv mode is restored in a new AppState and its SDK.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Possibly related PRs

  • dashpay/platform#3417: It adds a different Swift SDK construction path for SPV context, but overlaps with this PR’s Swift quorum-source design.
  • dashpay/platform#5884: It makes adaptive mode the Kotlin SDK default and uses the same quorum modes and single-manager rule.

Suggested reviewers: quantumexplorer, zocolini

Merge Risk: Minimal · up to e5efb

This change makes the Swift SDK default to adaptive quorum routing. It comes with documentation, a changelog entry, and tests. No concrete merge-blocking risk was identified in the reviewed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: SDK(network:) now defaults to the adaptive context provider, which runs in Auto mode. The raw summary confirms the default changed from .trusted to .adaptive in SDK.in…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: SDK(network:) now defaults to the adaptive context provider, which runs in Auto mode. The raw summary confirms the default changed from .trusted to .adaptive in SDK.init, and the other files are documentation, tests, and example-app wording that support that change. The title follows the conventional commit format and stays concise.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8bbb3d0 and e5efba7.

Files selected for processing: 9

  • CHANGELOG.md
  • packages/swift-sdk/Sources/SwiftDashSDK/FFI/PlatformQueryExtensions.swift
  • packages/swift-sdk/Sources/SwiftDashSDK/SDK.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/AppState.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/OptionsView.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleAppTests/AppStateQuorumModeTests.swift
  • packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swift
  • packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Support/IntegrationTestEnv.swift
  • packages/swift-sdk/SwiftTests/SwiftDashSDKTests/SDKQuorumSourceTests.swift

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@shumkov shumkov changed the title shumkov/adaptive swift default feat(swift-sdk): default SDK to the adaptive context provider in Auto mode Nov 12, 2026
@thepastaclaw

thepastaclaw commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit e5efba7) · triage: critical

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Final validation — Phase 1 + Phase 2

Verified the findings against head 0e19667 and the surrounding Rust provider and manager-lifecycle code. No blocking defects were confirmed; one stale test-documentation comment remains. Validation was static only: current code checks pass, but no Swift build/test result is available, and the automated review check remains pending.

💬 1 nitpick(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

1 finding(s) not shown inline (the lines are not part of this PR's diff)

💬 Nitpick: Update the test's description of the default provider
packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swift:4-5

This test constructs SDK(network: .testnet) without selecting a provider, so the new default makes it adaptive in Auto rather than a fixed trusted provider. It still obtains trusted quorum keys because no wallet manager serves it, but the parenthetical now names the wrong provider. Update the comment to distinguish the provider configuration from the source supplying its keys.

/// Live read of a known testnet identity through the default testnet SDK
/// (adaptive context provider in Auto, using trusted quorum keys without a
/// wallet manager, and seed DAPI nodes). It depends on testnet being

source: muse-spark-1.3-contributor (phase1-reviewer: general)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — The default-provider change affects proof trust selection and wallet-manager lifecycle compatibility, but the diff is neither large nor intricate enough to qualify as critical.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swift`:
- [NITPICK] packages/swift-sdk/SwiftTests/SwiftDashSDKIntegrationTests/Platform/TestnetIdentityFetchTests.swift:4-5: Update the test's description of the default provider
  This test constructs `SDK(network: .testnet)` without selecting a provider, so the new default makes it adaptive in Auto rather than a fixed trusted provider. It still obtains trusted quorum keys because no wallet manager serves it, but the parenthetical now names the wrong provider. Update the comment to distinguish the provider configuration from the source supplying its keys.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-review — Final validation — Phase 1 + Phase 2

The Swift SDK default now selects the existing Rust adaptive provider in Auto mode, with routing and manager ownership remaining Rust-owned. The documentation and targeted tests match the constructor behavior, trusted fallback, and explicit trusted opt-out; no actionable in-scope issues were found. This was a static review of e5efba7: current CI reports no failed checks, while the Swift SDK build-and-test check remains pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is an intricate cross-language change that changes the default proof-verification trust root and runtime quorum-key source between the trusted service and an SPV wallet manager in SDK.swift.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — security-auditor (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@shumkov

shumkov commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Non-inline nitpick (TestnetIdentityFetchTests.swift:4-5): Fixed in e5efba7: the description now says the default testnet SDK is the
adaptive provider in Auto, taking trusted quorum keys while no wallet manager
serves it SPV.

@shumkov

shumkov commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@shumkov
shumkov removed this pull request from stack #5885 November 13, 2026 03:51
Base automatically changed from shumkov/adaptive-auto-fallback to v5.1-dev November 13, 2026 03:51
@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 13, 2026
shumkov and others added 5 commits November 13, 2026 10:51
… mode

`SDK(network:)` built the trusted context provider, so every consumer that
did not choose a provider verified proofs with the trusted quorum
service's keys, even while a wallet manager on the same SDK ran a synced
SPV client. `contextProvider` now defaults to `.adaptive`, which Rust
builds in Auto mode: the trusted service's keys until a wallet manager
configured with the SDK serves a synced SPV client, then SPV's, and the
trusted service's for any key SPV cannot serve. An SDK no manager serves
verifies exactly as before.

Only one wallet manager serves an SDK, so configuring a second on the same
default SDK while the first holds it now throws. The init doc and the
CHANGELOG entry say so, with `.trusted` as the way back.

The SwiftDashSDKIntegrationTests env replaces its manager, and tests build
throwaway managers, on one SDK while another manager is alive; it now
builds that SDK `.trusted` explicitly, so those opt-in tests run as before.

Docs: `QuorumMode.auto` states that Auto is only as strong as the trusted
service, and `quorumSource` reports the source asked first.

Tests (SwiftDashSDKTests): testShouldBuildAnAdaptiveSdkInAutoByDefault
fails on the old default, whose trusted SDK refuses `setQuorumMode`, and
testShouldRefuseAModeChangeOnAnExplicitTrustedSdk pins the opt-out. No
Xcode on the machine this was written on, so neither red nor green was
run locally; CI's swift-sdk-build runs them.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…om the trusted service

The quorum mode picker's help, the indicator's help and AppState's mode
docs described Auto as switching wholesale from trusted to SPV once SPV
synced. Auto now asks the trusted service for any key SPV cannot serve,
and the indicator shows the source asked first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…m mode

A fresh AppState reads the mode saved in UserDefaults and builds its SDKs
in it, so a user who chose SPV is not dropped back to Auto on restart.
The parity manifest's restart coverage for the quorum mode cites this
test. It passes on the base (no behaviour change); run by CI's
SwiftExampleApp scheme.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review follow-ups. In Auto, a key SPV cannot serve comes from the trusted
service while the source reads SPV, so:
- `SDKStatus.quorumSource`, the example app's AppState docs and the
  Options help say "the source asked first" rather than the live choice
  or "what is actually active";
- the indicator reads "SPV", not "SPV (trustless)";
- the help points at the Sync tab, where SPV starts;
- `addContractToContext` adds to the SDK's context provider, which is no
  longer the trusted one by default.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…daptive

`SDK(network: .testnet)` now builds the adaptive provider in Auto, which
takes trusted quorum keys while no wallet manager serves it SPV; the test's
description still named a fixed trusted provider.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@shumkov
shumkov force-pushed the shumkov/adaptive-swift-default branch from e5efba7 to 946f651 Compare November 13, 2026 03:51
@shumkov
shumkov merged commit f5e4da9 into v5.1-dev Nov 13, 2026
6 of 7 checks passed
@shumkov
shumkov deleted the shumkov/adaptive-swift-default branch November 13, 2026 03:52
shumkov added a commit that referenced this pull request Nov 13, 2026
Merge v5.1-dev at d9d5689, which carries the squashed lifecycle PR (#4657) and the adaptive context provider work (#5882, #5883, #5884) plus #5830. Merge attributes were disabled; the merge is clean.

Audit: the merge delta onto 1073d2e is byte-identical to the v5.1-dev delta onto the merged lifecycle head 84ac1e7 (47 files), so the squash reproduces the lifecycle content exactly and nothing of the mobile delta changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants