Skip to content

fix(platform): ask for quorum keys again when the SDK had not started yet - #1730

Merged
HashEngineering merged 3 commits into
feat/kotlin-sdk-phase-1from
fix/quorum-keys-before-sdk-start
Nov 24, 2026
Merged

HashEngineering merged 3 commits into
feat/kotlin-sdk-phase-1from
fix/quorum-keys-before-sdk-start

Conversation

@HashEngineering

Copy link
Copy Markdown
Collaborator

Problem

A mainnet beta tester (12.0.x) reported the wallet still "syncing" several minutes after reaching 100%. In his logs the L1 chain synced in about 20 s, but Platform was unavailable for about 2.4 minutes after each launch (platform check: 2.478 min, 2.385 min), and the old Platform client banned 12 DAPI nodes in three minutes. Nine of those bans were Proof verification error: quorum key unavailable ... quorum not found, on healthy nodes.

Cause

Post-cutover, the old Platform client gets its quorum keys from SdkQuorumKeyCache, which fetches them from the Kotlin SDK on a quorum lookup. The first lookups of a launch arrive a few seconds before the SDK has started. The cache recorded that empty answer as a fetch attempt and did not ask again for the 30 s retry interval, so every proof in that window failed and the node that served it was banned. Once the client's requests backed off, nothing triggered another fetch for a long time.

From the log, second launch:

time event
00:52:57 SDK quorum fetch skipped: SDK not started yet
00:53:00 Dash Platform SDK started
00:53:07 – 00:53:14 four more lookups return null, four more nodes banned
00:55:07 next lookup; keys fetched in 11 s
00:55:19 platform check: 2.385 min

Fix

The fetcher now reports "the SDK is not running" (QuorumSourceNotReadyException) instead of returning an empty answer, and the cache leaves that lookup unstamped, so the next lookup asks again. A real failed or empty fetch is still rate-limited by the retry interval. The "skipped" line is logged once per not-ready streak rather than once per lookup.

Fetching the keys once at SDK start was the alternative. It needs a start hook from DashSdkServiceImpl into the quorum source (which depends on it the other way round), and alone it would not help, because the first lookups come before the start.

Also

One INFO line when the shielded pool sync status changes (shielded sync status: SYNCING -> READY), transitions only. The tester most likely saw the Shielded screen's "syncing" text, but the pool state was not logged anywhere, so that could not be confirmed.

Not covered

  • Lookups in the ~3 s before the SDK starts still fail and still ban the node that answered (5 of the 9 quorum bans in the second launch). Bans last 60 s and the address list has about 134 entries, so this should not stall the check. Removing them means making the lookup wait for the SDK to start.
  • In the first launch the check ran for another 1 min 46 s after the keys were loaded, on a TCP connect timeout to an unreachable node. This change does not shorten that.
  • A node that proves against a quorum outside the SDK's current validator set still fails the lookup.

Testing

  • ./gradlew :wallet:test_testNet3DebugUnitTest for SdkQuorumKeyCacheTest (8), ParseQuorumThresholdKeysTest (5), ShieldedBalanceServiceTest (155): all pass.
  • New tests: a lookup before the SDK starts followed by one right after returns keys; a thrown fetch still waits the retry interval; the SDK being down at refresh time keeps the cached keys and refetches once it is back.
  • Not run on a device.

🤖 Generated with Claude Code

HashEngineering and others added 2 commits November 21, 2026 20:30
… yet

The first quorum lookups of a launch arrive a few seconds before the
Kotlin SDK has started. The key cache recorded that empty answer as a
fetch attempt and did not ask again for the 30 s retry interval, so
every DAPI proof failed with "quorum not found", the old Platform
client banned healthy nodes, and once its requests backed off nothing
triggered another fetch for minutes.

A fetcher that cannot ask at all now reports that, and the cache leaves
the lookup unstamped so the next one asks again. A real failed or empty
fetch is still rate-limited by the retry interval.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
One INFO line when the status changes (NOT_READY, SYNCING, READY), so a
report of a balance stuck on "syncing" shows which state the pool was in.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 22, 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 45 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 83a56f7 and a71a7e0.

Files selected for processing: 3

  • wallet/src/de/schildbach/wallet/service/platform/sdk/SdkSourcedQuorums.kt
  • wallet/src/de/schildbach/wallet/service/platform/sdk/ShieldedBalanceServiceImpl.kt
  • wallet/test/de/schildbach/wallet/service/platform/sdk/SdkSourcedQuorumsTest.kt
  • 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

@thepastaclaw

thepastaclaw commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ Final review complete — no blockers (commit a71a7e0) · triage: low

@thepastaclaw thepastaclaw left a comment

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.

Final validation — Phase 1 + Phase 2

The quorum cache now retries on the next lookup when no SDK handle was available, while preserving cached keys and the existing refresh and retry intervals for actual fetches. Shielded sync logging preserves the existing publication order and lifecycle guards; the only in-scope finding is a detached KDoc block. CI build and check passed, PastaClaw review is pending, and no local tests were run during this static review.

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

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The diff makes a contained change to quorum-cache retry timing and adds transition logging without changing key parsing or proof verification.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 76% left, weekly 27% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort medium); 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 `wallet/src/de/schildbach/wallet/service/platform/sdk/SdkSourcedQuorums.kt`:
- [NITPICK] wallet/src/de/schildbach/wallet/service/platform/sdk/SdkSourcedQuorums.kt:139-163: Keep the retry and locking contract attached to the quorum cache
  The new exception and its own KDoc sit between the cache's KDoc and `SdkQuorumKeyCache`. Kotlin associates only the nearest KDoc with a declaration, so the exception retains its short description but the cache loses its merge, retry, and single-flight contract, including the new rule for a lookup that could not make a fetch. Move the exception and its KDoc above the cache's KDoc.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • Verify the provenance of legacy Platform quorum keys — The existing wallet bridge supplies quorum hash and threshold key pairs from currentQuorumsInfo() to the legacy proof verifier. The available Platform source uses FetchUnproved for that query and does not verify those pairs against validator-set commitments on that path. This PR changes when the call is retried, not which keys the verifier trusts.
    • Follow-up: Open a separate issue to confirm the trust guarantees of the pinned SDK artifact and, if it does not independently authenticate the pairs, update the bridge to use quorum keys from authenticated validator-set data.

Comment on lines +146 to +163
* [retryIntervalMs]; a populated one refreshes after
* [refreshIntervalMs]. Failures keep the previous keys and stamp the
* attempt so the DAPI callback can never hammer the fetcher.
* - A fetcher that throws [QuorumSourceNotReadyException] asked nobody (the
* SDK is not running yet), so that lookup is NOT stamped as an attempt:
* the next lookup asks again. Stamping it made the first lookups of a
* launch, which arrive seconds before the SDK starts, lock the cache
* empty for a full [retryIntervalMs] while every DAPI proof failed and
* healthy nodes were banned.
* - [snapshot] may block (single-flight) on the SDK query; callers are
* rust DAPI worker threads that are blocking on the quorum callback
* anyway.
*/
/**
* Thrown by a quorum fetcher that could not ask at all because its source
* (the Kotlin SDK) is not running. See [SdkQuorumKeyCache].
*/
internal class QuorumSourceNotReadyException : Exception("quorum source not ready")

@thepastaclaw thepastaclaw Nov 22, 2026 •

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.

✅ Resolved at a71a7e0e; see the replies below.

💬 Nitpick: Keep the retry and locking contract attached to the quorum cache

The new exception and its own KDoc sit between the cache's KDoc and SdkQuorumKeyCache. Kotlin associates only the nearest KDoc with a declaration, so the exception retains its short description but the cache loses its merge, retry, and single-flight contract, including the new rule for a lookup that could not make a fetch. Move the exception and its KDoc above the cache's KDoc.

Suggested change
* [retryIntervalMs]; a populated one refreshes after
* [refreshIntervalMs]. Failures keep the previous keys and stamp the
* attempt so the DAPI callback can never hammer the fetcher.
* - A fetcher that throws [QuorumSourceNotReadyException] asked nobody (the
* SDK is not running yet), so that lookup is NOT stamped as an attempt:
* the next lookup asks again. Stamping it made the first lookups of a
* launch, which arrive seconds before the SDK starts, lock the cache
* empty for a full [retryIntervalMs] while every DAPI proof failed and
* healthy nodes were banned.
* - [snapshot] may block (single-flight) on the SDK query; callers are
* rust DAPI worker threads that are blocking on the quorum callback
* anyway.
*/
/**
* Thrown by a quorum fetcher that could not ask at all because its source
* (the Kotlin SDK) is not running. See [SdkQuorumKeyCache].
*/
internal class QuorumSourceNotReadyException : Exception("quorum source not ready")
/**
* Thrown by a quorum fetcher that could not ask at all because its source
* (the Kotlin SDK) is not running. See [SdkQuorumKeyCache].
*/
internal class QuorumSourceNotReadyException : Exception("quorum source not ready")
/**
* Merge-on-fetch cache for SDK-sourced quorum threshold keys.
*
* - A quorum's public key is immutable for its hash, so every successful
* fetch MERGES into the previous snapshot — quorums that rotate out
* stay resolvable for proofs signed shortly before rotation.
* - Refresh policy at access time: an empty snapshot retries after
* [retryIntervalMs]; a populated one refreshes after
* [refreshIntervalMs]. Failures keep the previous keys and stamp the
* attempt so the DAPI callback can never hammer the fetcher.
* - A fetcher that throws [QuorumSourceNotReadyException] asked nobody (the
* SDK is not running yet), so that lookup is NOT stamped as an attempt:
* the next lookup asks again. Stamping it made the first lookups of a
* launch, which arrive seconds before the SDK starts, lock the cache
* empty for a full [retryIntervalMs] while every DAPI proof failed and
* healthy nodes were banned.
* - [snapshot] may block (single-flight) on the SDK query; callers are
* rust DAPI worker threads that are blocking on the quorum callback
* anyway.
*/

source: glm-5.3-flash (phase1-reviewer: general); gpt-6.2-sol (phase2-reviewer: general, security-auditor)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in a71a7e0: moved QuorumSourceNotReadyException and its KDoc above the cache's KDoc, so the merge, retry and single-flight contract is attached to SdkQuorumKeyCache again.

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.

Resolved (re-reviewed at a71a7e0e): Thanks—the move puts the exception and its KDoc before the cache’s KDoc, so the merge, retry, and single-flight contract now directly documents SdkQuorumKeyCache.

The not-ready exception sat between SdkQuorumKeyCache and its KDoc, so
the cache lost its merge, retry and single-flight contract.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@thepastaclaw thepastaclaw left a comment

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.

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

New on this head: This revision moves QuorumSourceNotReadyException and its KDoc above the KDoc for SdkQuorumKeyCache, without changing runtime behavior. The build and check jobs passed at the reviewed head; PastaClaw was still pending.

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

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.2-sol (effort low) — The diff makes a contained change to quorum-cache retry timing, adds transition logging, and tests the affected cases without changing proof verification or which keys are accepted.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort high); 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 (zai below 15% reserve: 5h 100% left, weekly 0% left)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.2-sol — security-auditor (completed, effort medium); 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.

Comment on lines +146 to +163
* [retryIntervalMs]; a populated one refreshes after
* [refreshIntervalMs]. Failures keep the previous keys and stamp the
* attempt so the DAPI callback can never hammer the fetcher.
* - A fetcher that throws [QuorumSourceNotReadyException] asked nobody (the
* SDK is not running yet), so that lookup is NOT stamped as an attempt:
* the next lookup asks again. Stamping it made the first lookups of a
* launch, which arrive seconds before the SDK starts, lock the cache
* empty for a full [retryIntervalMs] while every DAPI proof failed and
* healthy nodes were banned.
* - [snapshot] may block (single-flight) on the SDK query; callers are
* rust DAPI worker threads that are blocking on the quorum callback
* anyway.
*/
/**
* Thrown by a quorum fetcher that could not ask at all because its source
* (the Kotlin SDK) is not running. See [SdkQuorumKeyCache].
*/
internal class QuorumSourceNotReadyException : Exception("quorum source not ready")

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.

Resolved (re-reviewed at a71a7e0e): Thanks—the move puts the exception and its KDoc before the cache’s KDoc, so the merge, retry, and single-flight contract now directly documents SdkQuorumKeyCache.

@HashEngineering

Copy link
Copy Markdown
Collaborator Author

QA run 52 — PASS, and run 50's unattributed failure is now attributed to this PR

Run 50 (build 12000301, without this PR) ended with a failure it recorded but refused to blame: accepting an incoming contact request failed twice, each time sitting on "Accepting" for 2–4 minutes before showing "Contact request not accepted", with Dapi … Deadline expired and Attempted to unwrap a Failure in the log. It could have been the build or a bad day on testnet.

Build 12000303 adds this PR. The same operation, on the same kind of fixture:

run 50 — 12000301 run 52 — 12000303
accepts attempted 2 4, across two wallets
result both failed 4 × Worker result SUCCESS
time to outcome 2–4 min, then an error 4–30 s
errors Deadline expired, unwrap-a-Failure none
DAPI nodes banned 12 in 3 minutes 0

The ban count is the evidence, not the pass. Your PR describes the old client banning nodes on quorum key unavailable. Across 29 DAPI addresses in the logs of both devices, ban_count: 0 is the only value that appears anywhere — not one node was banned at any point in the run.

Each accept broadcast cleanly and was reconciled from Platform:

PlatformDocumentBroadcastService: contact request sent via Kotlin SDK; reconciling from platform
WM-WorkerWrapper: Worker result SUCCESS for SendContactRequestWorker

Scope. Four accepts on two wallets on testnet, over about half an hour. Contact payments were not re-run here (they already passed in run 50), and mainnet was not touched.

How this was tested

Builds. 12000303 = feat/kotlin-sdk-phase-1 @ 83a56f723 (the v12.0.2 tag) + Kotlin SDK int42 + dashj-platform 5.1.0-dev.3-20261123.212721-1, with #1686, #1712, #1719, #1548, #1694, #1697, #1713, #1721, #1717, #1718 and #1730 merged at their then-current heads.
12000304 = the same, plus #1736, and with #1725/#1721/#1718/#1714 taken from qa/spv-restart-with-1721-1718 @ 9244f3324 instead of merged separately. APK sha256 96422c3acd8dab7939ab12402d407a5500326f454564aae5b877e6c9e7e2c253.

Devices. Android 16 (API 36) emulators, testnet, release-signed builds. Platform protocol 14.

Unit tests on 12000304: 4,779 tests across 330 classes, 0 failures, 0 errors, 1 skipped.

Both SDK native libraries are byte-identical in size across the two builds, so differences between them come from the PRs and not from the SDK underneath.

Full report: https://github.com/HashEngineering/dash-wallet-qa-report — run 52.

@HashEngineering
HashEngineering merged commit b9deeb5 into feat/kotlin-sdk-phase-1 Nov 24, 2026
4 checks passed
HashEngineering added a commit that referenced this pull request Nov 24, 2026
…x/send-after-first-sync

Brings in the squash of #1714 (1a30905), with its last fix to the
invoice screen's observers, and the base's #1719 and #1730.

Co-Authored-By: Claude Fable 5.2 <[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