Skip to content

feat(sdk): back SPV up with the trusted quorum service in Auto mode - #5882

Merged
shumkov merged 3 commits into
v5.1-devfrom
shumkov/adaptive-auto-fallback
Nov 13, 2026
Merged

shumkov merged 3 commits into
v5.1-devfrom
shumkov/adaptive-auto-fallback

Conversation

@shumkov

@shumkov shumkov commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Bottom of GitHub Stack #5885 (this → #5883 → #5884)

Issue being fixed or feature implemented

In Auto mode the adaptive context provider (#3417) asked the trusted quorum service only while the SPV client was not ready. Once SPV synced, a quorum key it could not serve failed the request:

  • a quorum SPV had not seen yet (mined in the last block or two) banned the honest DAPI node that named it;
  • a quorum SPV held but had not verified yet failed the request.

The trusted service is meant to back SPV up when SPV has problems. This matters now that the Swift and Kotlin SDKs move to Adaptive/Auto by default (#5883, #5884).

What was done?

AdaptiveContextProvider, Auto mode only:

  • SPV not ready: every lookup goes to the trusted provider, as before (Trusted mode).

  • SPV ready, SPV answers: SPV's key is final. A signature that fails with it bans the node, as before, and is never retried with the trusted key: an honest SPV client and an honest trusted service cannot disagree on a quorum's key.

  • SPV ready, SPV cannot serve the key: the lookup goes to the trusted provider. The trusted provider can only turn that failure into a key, never into another verdict:

    • when it fails too, the lookup reports SPV's error;
    • the SDK's fetch goes to the trusted service; when that cannot help either, SPV, asked again, decides: a quorum it does not hold resolves to "unknown" (the node is banned, as before), one it cannot judge (QuorumSourceUnavailable, Config, …) to an error (no ban).

    So an unreachable trusted service cannot spare a node SPV would ban, and every ban today is still a ban.

  • Quorum type other than the network's Platform type: never falls back. SPV refuses those so a lower-threshold LLMQ cannot vouch for Platform state, and the trusted provider looks quorums up by hash alone (types with the same DKG interval share hashes).

  • Strict Spv mode and SpvContextProvider: unchanged, fail closed.

  • Logging: a fallback the trusted provider serves logs at info level, with the quorum and SPV's error; one neither source can serve warns, with both sources' errors.

  • One type check: dash_context_provider::is_platform_quorum_type is now the single check that a quorum type is the network's Platform type, shared by platform-wallet's SPV source and the fallback.

  • Docs: ContextProvider::quorum_source now documents the source asked first. The adaptive provider, ContextProviderMode::Auto and the rs-sdk-ffi entry points say Auto is only as strong as the trusted service.

What this does and does not change:

  • What it no longer resists. Ready Auto used to resist a compromised trusted quorum service. Now someone who controls that service (or its TLS) and a DAPI node can have a proof accepted that names a quorum SPV does not hold. Before, that also took cutting the client off from its SPV peers. Clients that must never depend on the trusted service use Spv mode.
  • Not covered. Heights below SPV's retained history (rust-dashcore#1396) are not rescued: the trusted service lists only the current quorums and those at tip−8.
  • Slower bans. A ban for a quorum SPV says is absent now waits for the trusted fetch to give up, which takes seconds if the trusted host is blackholed.

dash-context-provider was missing from CI's nextest list, so its routing tests (including #3417's) never ran in CI; it is added.

How Has This Been Tested?

Test-first, red → green locally:

  • dash-context-provider, red on the base, green after (5 tests):
    • should_answer_from_trusted_when_a_ready_spv_source_cannot_serve_the_key
    • should_report_spvs_error_when_trusted_cannot_serve_the_key_either
    • should_fetch_missing_quorum_keys_from_trusted_except_in_spv_mode
    • should_let_spv_decide_the_verdict_when_the_trusted_fetch_cannot_help
    • should_keep_the_trusted_verdict_when_spv_stops_being_ready_during_a_fetch
  • should_not_fall_back_for_a_quorum_type_other_than_platforms (LLMQ_50_60) failed against the fallback without the type pin and passes with it. Guard tests check that:
    • a ready SPV key never asks trusted;
    • Spv mode never asks or fetches;
    • not-ready Auto leaves every quorum type to trusted;
    • a trusted provider that cannot fetch leaves SPV's error standing.
  • dash-sdk should_verify_a_proof_whose_quorum_spv_has_not_seen_with_the_trusted_key: a recorded proof, a local trusted quorum service with a cold cache, and a synced SPV client that lacks the quorum. It checks that SPV was asked first. Error::Proof (a ban) with the old provider; verified after.
  • Locally:
    • cargo test -p dash-context-provider --all-features (30 pass);
    • cargo clippy -D warnings on dash-context-provider, dash-sdk and rs-sdk-ffi;
    • the CI-equivalent workspace test run on the top of the stack: 22,166 passed. The one failure, rs-dapi-client socks5_proxy::should_bound_the_tunnel_and_tls_by_one_connect_deadline, is a timing assertion under full parallel load; it passes on its own (14/14), and this stack does not touch that crate.

Breaking Changes

None. Auto mode's behaviour changes as described; no public type, signature or ABI changes.

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

PR Hygiene · 8bbb3d0

  • Bots — thepastaclaw ✓
  • Self-review — posted; again after any push
  • Build green
  • Approvals
    • github (.github/workflows/tests-rs-workspace.yml) — ktechmidas
    • files with no dedicated owner — you own it
    • rs-platform-wallet (packages/rs-platform-wallet/src/manager/spv_quorums.rs, packages/rs-platform-wallet/src/spv_context_provider.rs) — HashEngineering or ZocoLini or llbartekll or romchornyi
    • rust-sdk-ffi — you own it
    • rust-sdk — you own it

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

shumkov and others added 3 commits November 12, 2026 13:56
The crate's routing tests (the SPV slot, the strict SPV provider and the
adaptive provider) were compiled by clippy but never run: the package was
missing from the nextest list. Add it next to dash-sdk.

Locally `cargo test -p dash-context-provider --all-features --locked`
passes on the base (22 tests).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
In Auto mode the adaptive context provider asked the trusted provider only
while the SPV client was not ready. Once SPV synced, a key it could not
serve failed the request: a quorum SPV had not seen yet banned the honest
node that named it, and one it held unverified failed the request.

Now, while SPV is ready, a lookup SPV cannot serve goes to the trusted
provider, and the trusted provider can only turn that failure into a key:
- When it fails too, the lookup reports SPV's error. The SDK's fetch is the
  trusted provider's, and when that cannot help either, SPV, asked again,
  decides the verdict: a quorum it does not hold resolves to "unknown",
  which bans the node as before, and one it cannot judge to its error,
  which does not. A trusted service that is down therefore cannot spare a
  node SPV would ban.
- A key SPV serves stays final: a signature that fails with it is the
  node's fault and is never retried with the trusted key.
- A quorum type other than the network's Platform type never falls back.
  SPV refuses those so a lower-threshold quorum cannot vouch for Platform
  state, and the trusted provider looks quorums up by hash alone.
- Strict SPV mode is unchanged and fails closed. While SPV is not ready,
  Auto is the trusted provider alone, as before.
- Each fallback is logged at warn level with the quorum and both sources'
  errors.

Auto is therefore only as strong as the trusted quorum service: someone who
controls that service and a node can have a proof accepted that names a
quorum SPV does not hold. The docs say so and point strict clients to SPV
mode. ContextProvider::quorum_source now documents the source asked first.

Tests, red before the change (dash-context-provider):
- should_answer_from_trusted_when_a_ready_spv_source_cannot_serve_the_key
- should_report_spvs_error_when_trusted_cannot_serve_the_key_either
- should_fetch_missing_quorum_keys_from_trusted_except_in_spv_mode
- should_let_spv_decide_the_verdict_when_the_trusted_fetch_cannot_help
- should_keep_the_trusted_verdict_when_spv_stops_being_ready_during_a_fetch
  ✖ 5 failed on the base, ✔ pass after.
- should_not_fall_back_for_a_quorum_type_other_than_platforms passes on
  the base; ✖ it failed against the fallback without the type pin,
  ✔ passes with it.
- dash-sdk should_verify_a_proof_whose_quorum_spv_has_not_seen_with_the_trusted_key
  verifies a recorded proof through a local trusted quorum service with a
  synced SPV client that lacks the quorum: ✖ Error::Proof (a ban) with the
  old provider, ✔ verified after.
should_not_retry_a_ready_spv_miss_against_trusted pinned the old behaviour
and is replaced.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…fallback logs and tests

Review follow-ups to the Auto fallback:
- `dash_context_provider::is_platform_quorum_type` is now the one check
  that a quorum type is the network's Platform type; platform-wallet's SPV
  source and the adaptive provider's fallback both call it, so the two
  pins cannot drift.
- A fallback the trusted provider serves is logged at info level: it is
  the designed path while SPV lags a new quorum and would otherwise warn
  on every verification. A lookup or fetch neither source can serve still
  warns, with both sources' errors under the same field names.
- The SDK's "unknown quorum" log and docs, the status JSON's
  `quorumSource`, `QuorumKeySource` and the FFI docs say "the provider's
  source" and "the source asked first", which hold in Auto too, and
  platform-wallet's `serve_spv_quorums` doc covers the adaptive provider.
- Tests: a lookup of LLMQ_50_60 (the type the pin exists for) still goes to
  the trusted provider while SPV is not ready; an `InvalidQuorum` SPV
  answer to the fetch's re-ask resolves to unknown; the "trusted cannot
  fetch" case is its own test; and the dash-sdk end-to-end test checks
  that SPV was asked first (twice, failing with the error platform-wallet
  reports for a missing quorum) before the trusted key verified.

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

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

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

Files ignored due to path filters: 1

  • Cargo.lock is excluded by !**/*.lock
Files selected for processing: 12

  • .github/workflows/tests-rs-workspace.yml
  • packages/rs-context-provider/Cargo.toml
  • packages/rs-context-provider/src/adaptive.rs
  • packages/rs-context-provider/src/lib.rs
  • packages/rs-context-provider/src/provider.rs
  • packages/rs-context-provider/src/quorum_source.rs
  • packages/rs-context-provider/src/test_support.rs
  • packages/rs-platform-wallet/src/manager/spv_quorums.rs
  • packages/rs-platform-wallet/src/spv_context_provider.rs
  • packages/rs-sdk-ffi/src/sdk.rs
  • packages/rs-sdk-ffi/src/system/status.rs
  • packages/rs-sdk/src/sdk/quorum_key.rs
  • 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

@github-actions github-actions Bot added this to the v5.1.0 milestone Nov 12, 2026
@shumkov shumkov changed the title shumkov/adaptive auto fallback feat(sdk): back SPV up with the trusted quorum service in Auto mode Nov 12, 2026
@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 12, 2026
@thepastaclaw

thepastaclaw commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 8bbb3d0)

@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

The Auto fallback preserves SPV-first lookup, strict SPV behavior, and the Platform quorum-type guard. One nonblocking regression remains: existing Swift diagnostics still describe the reported source as trustless proof provenance, although it now identifies only the first source asked. This was a static review of 8bbb3d0; current code checks pass, including Rust workspace, wasm32, Swift, and Kotlin checks, while review and hygiene gates remain pending.

🟡 1 suggestion(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.

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: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate change to quorum-key sourcing that alters the trust boundary for proof verification and can affect signature acceptance and node-banning decisions in the SDK.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer, muse-spark-1.3-contributor — rust-quality (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 — rust-quality (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 (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/rs-sdk-ffi/src/sdk.rs`:
- [SUGGESTION] packages/rs-sdk-ffi/src/sdk.rs:763-766: Update the existing Swift trust indicator with Auto's new semantics
  This diagnostic now reports SPV even when Auto verifies a proof with a trusted-service key. However, SDK.swift:393-419 still documents it as the source verification currently uses, and OptionsView.swift:424-441 displays `.spv` as a green `SPV (trustless)` indicator. This already affects the example app because AppState.makeSdk explicitly constructs an adaptive SDK; it does not depend on the default-provider change in #5883. The linked https://github.com/dashpay/platform/pull/5883 contains the appropriate documentation and indicator changes, but this head independently introduces the misleading trust claim. Include those consumer wording changes here, or deliver them atomically with this behavior change. Describing the value as the first source asked, with possible trusted fallback, is sufficient; Swift should not reconstruct proof provenance from readiness or callback timing.

Comment thread packages/rs-sdk-ffi/src/sdk.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 12, 2026
@shumkov

shumkov commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

/self-reviewed

@github-actions

Copy link
Copy Markdown
Contributor

Ready for review — github: ktechmidas · rs-platform-wallet: HashEngineering or ZocoLini or llbartekll or romchornyi.
Full checklist in the description.

@github-actions github-actions Bot added ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 13, 2026
@shumkov
shumkov removed this pull request from stack #5885 November 13, 2026 03:51
@shumkov
shumkov merged commit 7266c08 into v5.1-dev Nov 13, 2026
32 of 34 checks passed
@shumkov
shumkov deleted the shumkov/adaptive-auto-fallback branch November 13, 2026 03:51
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

ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants