Registry Mirror
Skip to content

Conversation

@QuantumExplorer

@QuantumExplorer QuantumExplorer commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Basic explanation

A wallet can now see the tokens it holds inside a token's shielded pool. Until now the wallet scanned only the credit shielded pool. A token bought from the shielded pool (type 28, #6090) landed on chain, but the app could not show it.

The wallet now keeps a list of the token pools it watches. Each shielded sync scans those pools for the wallet's notes and reports one balance per watched pool and account. A type 28 purchase watches the bought token's pool before it buys, and the app can watch any other token that has a shielded pool.

Before: after a shielded purchase, the screen said the tokens were on chain but not shown.

After: a new Shielded Tokens screen (Wallet → Shielded Tokens) lists each watched token with:

  • its balance per account;
  • its unspent note count;
  • how far the scan has got ("Scanned X of Y notes", or "Not scanned yet");
  • the last scan error, if any.

Refresh runs a shielded sync. "Watch a token pool" picks one of the app's known tokens. Swipe to stop watching.

This is the first of three PRs. It is the foundation for the shielded token transfer (type 26) and the token unshield to an identity (type 27). Both spend these notes, and both follow in stacked PRs.

Issue being fixed or feature implemented

Test plan rows SH-25 to SH-27 were blocked: rs-platform-wallet tracked no token pool notes, and types 26 and 27 cannot be built until the wallet has them. No open PR or issue covered this.

What was done?

rs-platform-wallet

New module wallet::shielded::token_pool.

Tables

  • Five new tables in the shielded store's SQLite file: watches, per-pool scan state, per-account watermarks, pool leaves, and owned notes.
  • They are created on open. They are not handed to the host persister, so SwiftData's schema does not change.

Scan

  • sync_token_pools scans every watched pool for the registered accounts of the wallets that watch it.
  • It reads one chunk at a time, chunk-aligned, starting from the lowest watermark. Each chunk is applied in one transaction:
    1. keep the leaves;
    2. save the notes each account decrypts at a position it had not checked;
    3. mark spent the owned notes whose nullifiers the chunk's actions reveal;
    4. raise the watermarks to the chunk's end.
  • A chunk that comes back short ends the pass, so a watermark only covers positions that were read. platform-wallet: a shielded note scan advances its watermark past a gap between fetched ranges #6109 describes that gap for the credit pool; this scan does not repeat it.
  • A note counts as spent only on positive evidence: a nullifier the pool revealed. Nothing is inferred from what a scan did not see.
  • A pool whose read fails keeps its error for the balance to show, and the other pools are still scanned.
  • Leaves are kept for the Merkle paths that the type 26 and 27 spends will need.

NetworkShieldedCoordinator

  • New methods watch_token_pool, record_token_pool_watch (no network read), unwatch_token_pool and token_pool_balances.
  • sync runs the token pool scan after the credit pool. A stopped pass reads no token pool, and a token pool failure fails nothing else.
  • Watch and unwatch take the lifecycle lock, so a watch cannot land after a wallet's removal purged it. Each chunk rechecks the watch, and the account's watermark row, inside its own transaction. An unwatch, a wallet's removal, a Clear or a dropped account that lands mid-scan is therefore never undone.
  • Token notes found or spent, or a token pool failure, count as activity for the caught-up cooldown.

FileBackedShieldedStore

  • Wallet removal drops the wallet's token pool rows.
  • Dropping or re-keying an account drops that account's rows.
  • Clear drops the scan state (scans, watermarks, leaves, notes) but keeps the watch list, so the next sync rescans the watched pools. Nothing else would bring the watches back.

Purchases

  • ShieldedTokenPurchaser::purchase records the bought token's pool watch before it reserves or sends anything. A watch that cannot be recorded refuses the purchase.
  • Doc comments that said the bought note is not tracked are updated.

rs-platform-wallet-ffi

  • New module shielded_token_pools with the four exports below. They only marshal.
  • They resolve the coordinator the way the other shielded exports do, and run outside the manager registry guard, so a network read or a wait on the store lock never holds the registry.
  • Every export catches panics, and errors go through the existing shielded error mapping. No new error codes.

Swift SDK and SwiftExampleApp

  • Swift wrappers in PlatformWalletManagerShieldedSync.swift.
  • New ShieldedTokenPoolsView.swift, linked from WalletDetailView.
  • Token names and decimals are looked up locally for display only. Rows are shown as Rust returns them.
  • The stale "not shown" texts in ShieldedActivityView and TokenPurchaseActionView are updated.
  • No SwiftData @Model change.

Docs

  • TEST_PLAN.md SH-25 is implemented and notes it has not yet run on a simulator. SH-24's "not shown" wording is removed.
  • sdk-parity-manifest.json gains shielded.token_pool_balances, and PARITY_SUMMARY.md is regenerated.

New public interfaces

C FFI (shielded feature)

PlatformWalletFFIResult platform_wallet_manager_shielded_token_pool_watch(
    Handle handle, const uint8_t *wallet_id_bytes, const uint8_t *data_contract_id,
    uint16_t token_contract_position, uint8_t *out_token_id /* 32 bytes */);
PlatformWalletFFIResult platform_wallet_manager_shielded_token_pool_unwatch(
    Handle handle, const uint8_t *wallet_id_bytes, const uint8_t *token_id);
PlatformWalletFFIResult platform_wallet_manager_shielded_token_pool_balances(
    Handle handle, const uint8_t *wallet_id_bytes,
    struct ShieldedTokenPoolBalanceFFI **out_rows, uintptr_t *out_count);
void platform_wallet_manager_shielded_token_pool_balances_free(
    struct ShieldedTokenPoolBalanceFFI *rows, uintptr_t count);

watch

  • Verifies the token's configuration has a shielded pool, with a network read, then records the watch.
  • Watching a watched pool again changes nothing.
  • It is refused with Rust's message when the wallet is not bound to shielded, when the token has no shielded pool, or when the token's configuration cannot be read.

unwatch

  • Forgets the wallet's notes and scan state in that pool, and the pool's leaves once no wallet watches it.

balances

  • Reads local state only, one row per watched pool and registered account.
  • ShieldedTokenPoolBalanceFFI fields:
    • token_id[32], data_contract_id[32], token_contract_position, account_index;
    • balance: the unspent value, in the token's smallest unit;
    • unspent_note_count;
    • three optional values, each with a flag: has_scanned_note_count/scanned_note_count, has_pool_note_count/pool_note_count and has_scanned_height/scanned_height;
    • last_error: an owned C string, or null.
  • The free function releases the rows and their strings. Releasing twice is a no-op.

Swift (PlatformWalletManager)

  • shieldedTokenPoolWatch(walletId:dataContractId:tokenContractPosition:) async throws -> Data returns the token id.
  • shieldedTokenPoolUnwatch(walletId:tokenId:) async throws
  • shieldedTokenPoolBalances(walletId:) async throws -> [ShieldedTokenPoolBalance]
  • public struct ShieldedTokenPoolBalance: Sendable, Hashable mirrors the row, with optionals for the flagged values and lastError.

Unwatch and balances are async because they wait for the shielded store, which a sync pass can hold. A synchronous call would block the main actor.

Rust (platform-wallet)

  • ShieldedTokenPoolWatch { token_id, data_contract_id, token_contract_position }
  • ShieldedTokenPoolBalance { watch, account_index, balance, unspent_note_count, scanned_note_count, pool_note_count, scanned_height, last_error }
  • NetworkShieldedCoordinator::{watch_token_pool, unwatch_token_pool, token_pool_balances}

Persisted state (Rust-owned SQLite in the shielded store file, not SwiftData)

Table Key Holds
shielded_token_pool_watches wallet, token contract id, position
shielded_token_pool_scans token pool note count, scan height, last error
shielded_token_pool_watermarks wallet, account, token notes checked from 0 without a gap
shielded_token_pool_leaves token, position note commitment
shielded_token_pool_notes wallet, account, token, nullifier position, cmx, value (8 bytes LE), note bytes, height, spent

App accessibility identifiers

  • Link: walletDetail.shieldedTokensLink
  • List and controls: shieldedTokens.list, shieldedTokens.refreshButton, shieldedTokens.watchButton
  • Rows: shieldedTokens.row.<tokenIdBase58>.<account>, containing shieldedTokens.balance, .noteCount, .scanState, .lastError and .unwatchButton
  • Watch sheet: shieldedTokens.watchSheet, shieldedTokens.watchSheet.token.<contractIdBase58>.<position>

How Has This Been Tested?

  • cargo test -p platform-wallet --features shielded --lib -- token_pool should_request_a_sync_only: 13 passed (plus the watch refusal test). They cover:
    • notes and their spends across passes, and a note received and spent within one chunk;
    • the short-chunk gap: the next chunk is never read, and the next pass recovers it;
    • an account added later, and a wallet that does not watch the pool;
    • a scan error kept until a read succeeds, and cancellation;
    • unwatch;
    • reopen, account purge and Clear on the file store;
    • the coordinator's watch, list and wallet removal;
    • an unwatch landing mid-scan (should_not_undo_an_unwatch_that_lands_mid_scan);
    • the network-checked watch refusals: no shielded pool, and a contract not on Platform.
  • cargo test -p platform-wallet --features shielded --lib -- should_refuse_to_watch_a_token shielded::coordinator shielded::file_store shielded::sync: 88 passed after the review fixes (101 before them, with shielded::operations::token_purchase included).
  • cargo test -p platform-wallet-ffi --features shielded --lib shielded_token_pools: 13 passed. They cover:
    • the free function on null and empty arrays, and on rows with and without errors;
    • a second release;
    • null pointers and unknown handles on all exports.
  • cargo clippy -p platform-wallet -p platform-wallet-ffi --all-targets --all-features --locked -- --no-deps -D warnings: clean. cargo fmt --all: clean.
  • packages/swift-sdk/build_ios.sh --target sim (release): BUILD SUCCEEDED. The xcframework built from this branch, and SwiftExampleApp built with -warnings-as-errors.
  • python3 scripts/check_sdk_parity_manifest.py --write-summary: OK.

Not yet verified

  • No simulator run, and no scan against a live network: a type 28 purchase showing up on the Shielded Tokens screen after a sync has not been seen. SH-25 records this.
  • Rows for a wallet with more than one bound account have not been seen in the app.

Breaking Changes

None. There is no protocol or consensus change and no SwiftData schema change. The new SQLite tables are additive and created on open. The C ABI only gains functions.

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 · 3a766bf

  • Bots — thepastaclaw not yet — /skip-bots proceeds without the ones not yet reported
  • Self-review — post /self-reviewed
  • Reviewer requests paused — your 5 review slots are occupied; this PR is excluded from reviewers' queues. Required approvals still count without a slot.
  • Build running
  • Approvals
    • sdk-parity — you own it
    • kotlin-sdk (packages/kotlin-sdk/PARITY_SUMMARY.md) — HashEngineering
    • rs-platform-wallet-ffi (packages/rs-platform-wallet-ffi/src/identity_withdrawals.rs, packages/rs-platform-wallet-ffi/src/lib.rs, packages/rs-platform-wallet-ffi/src/shielded_sync.rs and 1 more) — HashEngineering or ZocoLini or llbartekll or romchornyi
    • rs-platform-wallet (packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs, packages/rs-platform-wallet/src/wallet/platform_wallet.rs, packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs and 6 more) — HashEngineering or ZocoLini or llbartekll or romchornyi
    • swift-sdk (packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedActivityView.swift, packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedTokenPoolsView.swift and 4 more) — llbartekll or romchornyi

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.

@coderabbitai

coderabbitai Bot commented Nov 23, 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 17 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 891152e and 3a766bf.

Files selected for processing: 22

  • docs/sdk/sdk-parity-manifest.json
  • packages/kotlin-sdk/PARITY_SUMMARY.md
  • packages/rs-platform-wallet-ffi/src/identity_withdrawals.rs
  • packages/rs-platform-wallet-ffi/src/lib.rs
  • packages/rs-platform-wallet-ffi/src/shielded_sync.rs
  • packages/rs-platform-wallet-ffi/src/shielded_token_pools.rs
  • packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs
  • packages/rs-platform-wallet/src/wallet/platform_wallet.rs
  • packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs
  • packages/rs-platform-wallet/src/wallet/shielded/file_store.rs
  • packages/rs-platform-wallet/src/wallet/shielded/mod.rs
  • packages/rs-platform-wallet/src/wallet/shielded/operations.rs
  • packages/rs-platform-wallet/src/wallet/shielded/sync.rs
  • packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs
  • packages/rs-platform-wallet/src/wallet/shielded/token_pool_tests.rs
  • packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedSync.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedActivityView.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/ShieldedTokenPoolsView.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/WalletDetailView.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Core/Views/WalletsContentView.swift
  • packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/TokenActions/TokenPurchaseActionView.swift
  • packages/swift-sdk/SwiftExampleApp/TEST_PLAN.md
  • 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 23, 2026
@thepastaclaw

thepastaclaw commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

🔍 Review in progress (commit 3a766bf) · live progress

@QuantumExplorer
QuantumExplorer marked this pull request as ready for review November 23, 2026 09:00
@github-actions

github-actions Bot commented Nov 23, 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.

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

⚠️ DEGRADED — Final validation — Phase 1 + Phase 2

⚠️ DEGRADED review. The primary review models were unavailable (gpt-6.2-sol unavailable: Request rejected (429) · All credentials for model gpt-6.2-sol are cooling down (last error: usage_limit_reached: The us), so this review ran on stand-in models: gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor, gpt-6.1-sol → muse-spark-1.3-contributor, gpt-6.2-astra → muse-spark-1.3-contributor, gpt-6.2-sol → muse-spark-1.3-contributor. Both review phases and the independent verifiers still ran, but on weaker models, with Phase 1 capped at high effort. Treat the verdict as provisional; a full-strength re-review will run on the next push once the primary models are back.

Changes requested: 2 blockers

  • Unwatch or wallet removal mid-scan resurrects token rows and a later re-watch skips notes — packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:800-884 (new)
    Impact: A user who stops watching a pool or removes a wallet while a shielded sync is scanning it and later re-watches it sees a balance reported as fully scanned that permanently omits the deleted notes.
  • Clear deletes the token watch list so owned token notes stay invisible after a rebuild — packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:379-390 (new)
    Impact: A user who runs Clear and then rebinds and syncs sees an empty Shielded Tokens list even though their token notes are still on chain, until they remember and manually re-watch each pool.

Adds wallet-local token shielded-pool watching, chunk-aligned scanning after the credit-pool pass, auto-watch on type-28 purchases, and FFI plus SwiftUI surfaces. CI is still running (Rust workspace tests and Kotlin build in progress, other jobs skipped or successful).

🔴 2 blocking | 🟡 5 suggestion(s)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: general); reviewer 4: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: architecture-layering); reviewer 5: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: rust-quality); reviewer 7: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: security-auditor); reviewer 8: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: general); reviewer 9: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: architecture-layering); reviewer 10: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: ffi-engineer); reviewer 11: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: rust-quality); reviewer 12: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: security-auditor); final verifier: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: sol-verifier, role: final-verifier)

  • Degraded mode: gpt-6.2-sol unavailable: Request rejected (429) · All credentials for model gpt-6.2-sol are cooling down (last error: usage_limit_reached: The us (detected by lane, since 2026-11-23T09:25:39Z); stand-ins gpt-5.6-luna → muse-spark-1.3-contributor, gpt-5.6-sol → muse-spark-1.3-contributor, gpt-5.6-terra → muse-spark-1.3-contributor, gpt-6-astra → muse-spark-1.3-contributor, gpt-6.1-sol → muse-spark-1.3-contributor, gpt-6.2-astra → muse-spark-1.3-contributor, gpt-6.2-sol → muse-spark-1.3-contributor; Phase 1 effort capped at high
  • Triage: normal by gpt-6.2-sol (effort low) — The scanner and its cross-language integration are intricate, but token_pool.rs uses existing cryptographic primitives and adds wallet-local tables without migrating existing records or changing how funds are spent.
  • 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)
  • 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: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — final-verifier; agent sol-verifier
  • Phase 2 reviewers: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — general (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — architecture-layering (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — ffi-engineer (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — rust-quality (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — security-auditor (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — general (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — architecture-layering (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — ffi-engineer (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-sol) — rust-quality (completed, effort high); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.2-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/rs-platform-wallet/src/wallet/shielded/token_pool.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:800-884: Unwatch or wallet removal mid-scan resurrects token rows and a later re-watch skips notes
  Impact: A user who stops watching a pool or removes a wallet while a shielded sync is scanning it and later re-watches it sees a balance reported as fully scanned that permanently omits the deleted notes.
  Consequence: purged notes, watermarks, leaves and scan state come back as orphans, and a later re-watch resumes from the resurrected high watermark over positions whose notes are gone, so those notes are never re-fetched without a full Clear. Mechanism: `sync_token_pools` snapshots the watch and watermark plan once up front and `scan_pool`/`apply_chunk` applies every later chunk under only the store read guard with no lifecycle lock and no per-chunk watch or registration recheck, while `unwatch_token_pool`, `unregister_wallet` and `clear` purge the same rows under the lifecycle plus store locks. A purge landing between the plan and a later chunk apply is therefore undone chunk-by-chunk: `apply_chunk` re-inserts leaves, saves notes and raises watermarks for a watch row that no longer exists, without recreating the watch, so `balances()` hides the orphans until a re-watch inherits the watermark. Fix in `rs-platform-wallet`: make the token pass respect the same lifecycle ownership, e.g. re-resolve watches or registration per chunk or per pool under the store guard and drop scanner entries whose watch or registration is gone before `apply_chunk`, or skip persisting chunks for unwatched pairs inside the apply transaction, plus a test that unwatches mid-scan, re-watches, and expects either a clean rescan or no orphan rows.
- [BLOCKING] packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:379-390: Clear deletes the token watch list so owned token notes stay invisible after a rebuild
  Impact: A user who runs Clear and then rebinds and syncs sees an empty Shielded Tokens list even though their token notes are still on chain, until they remember and manually re-watch each pool.
  Consequence: after a Clear, token-pool funds are misreported as absent. Mechanism: `purge_all` deletes every token-pool row including `shielded_token_pool_watches`, and `FileBackedShieldedStore::purge_all_subwallets` called by `NetworkShieldedCoordinator::clear` calls it, while watches live only in the shielded-store SQLite file and are never handed to the host persister, unlike the credit pool which rescans unconditionally after Clear. Token pools scan only watched pools, so deleting the watch list breaks the cold-rebuild contract that Clear promises. Fix: keep the watch list across Clear and delete only scan cache, e.g. use a `conn.transaction()` that deletes from `shielded_token_pool_scans`, `shielded_token_pool_watermarks`, `shielded_token_pool_leaves` and `shielded_token_pool_notes` but not `shielded_token_pool_watches`, so the post-Clear sync rescans the same pools.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:379-390: Token-pool Clear purge can leave the shared SQLite connection inside an open transaction
  Impact: If one DELETE in the Clear path fails, later token-pool reads and writes on the shared shielded-store connection fail until the process restarts.
  Consequence: a failed Clear reports failure but leaves some token tables already emptied and the shared `pending_conn` inside an open transaction. Mechanism: `purge_all` runs `BEGIN; DELETE...; COMMIT;` via `execute_batch`, so a mid-script error returns `Err` without reaching `COMMIT` or issuing `ROLLBACK`, unlike the siblings `purge_wallet`, `purge_subwallet` and `remove_watch` which use `conn.transaction()` with commit-on-success and RAII rollback. Fix: use the same `transaction()` shape as the sibling purges.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/token_pool.rs:563-608: Token balances load full note blobs just to add up small values
  Impact: Wallets watching busy token pools pay extra SQLite I/O and per-note allocations on every balances refresh, which is the UI-facing path.
  Consequence: wasted I/O and allocation on a refresh path. Mechanism: `balances()` calls `notes()`, which selects position, cmx, nullifier, value, 115-byte note_data, height and spent and hydrates a `Vec<u8>` per row, only to filter `!is_spent` and sum 8-byte values via `checked_add`. The cmx, nullifier, note bytes and heights are deserialized and discarded on this path. Fix: add a narrow totals query for `balances()` such as selecting only value and spent, or a SQL-side sum or count, and keep the full `notes()` load for the spend path that needs the blobs.

In `packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:1754-1758: Token-only scan results do not count toward the sync cooldown decision
  Impact: After a pass that finds token notes, marks token notes spent, or hits a token-pool error with no credit-pool activity, background syncs keep skipping for the cooldown window and delay token balance updates and error retries.
  Consequence: stale token balances and deferred error retries even though the pass just did meaningful or failed token work. Mechanism: the token-pool call's `TokenPoolSyncSummary` is awaited and dropped, and the cooldown decision below only looks at credit-pool signals (`notes.total_scanned`, `newly_spent_per_sub`) when stamping `last_caught_up_at`, which gates the next background pass including its token-pool scan. Fix: bind the summary and fold it into `any_activity` by counting token `new_notes`/`newly_spent` and treating a non-empty `failed` map as activity so the retry is not delayed, and consider surfacing token-pool failures in the per-wallet sync outcome instead of only in the per-row `last_error`.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/shielded/coordinator.rs:1010-1059: The network-verified token watch path has no test covering its refusals
  Impact: The FFI `watch` refusal paths for a token without a shielded pool or an unreadable token configuration can regress without any test failing.
  Consequence: the gate that refuses misconfigured tokens is unverified. Mechanism: the suite covers `record_token_pool_watch`, the no-network helper used by purchases and the existing coordinator test, but not `watch_token_pool` with its `ensure_token_has_shielded_pool` network read before recording; FFI tests assert error-message mapping with synthetic errors, not the actual gate. Fix: add a coordinator test with the mock SDK pinning at least the no-network refusal and the unreadable-configuration refusal produced by the mock fetch.

In `packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/manager/shielded_token_purchase.rs:70-90: A failed purchase-time pool watch leaves a confirmed purchase invisible with only a log
  Impact: On the rare path where recording the bought pool's watch fails, the purchase succeeds but the Shielded Tokens screen never shows the tokens until the user manually watches the pool.
  Consequence: confirmed purchase with missing tokens in the UI and no user-facing signal. Mechanism: `ShieldedTokenPurchaser::purchase` only `warn!`s when `record_token_pool_watch` fails from a store error or mid-purchase unbind and still returns success plus requests a sync, while later syncs skip unwatched pools and nothing retries the watch. Fix: surface the watch failure to the host alongside the purchase outcome or reconcile desired watches before the next scan so a transient store failure does not permanently hide that purchase.

@github-actions

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
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 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions

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 waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 23, 2026
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch 5 times, most recently from 93285c3 to db53f05 Compare November 23, 2026 11:16
@github-actions

github-actions Bot commented Nov 23, 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.

@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from db53f05 to a7ab835 Compare November 23, 2026 12:22
QuantumExplorer and others added 3 commits November 23, 2026 19:23
…'s notes

A wallet now keeps the notes it holds in the shielded pools of the
tokens it watches, and reports a balance per watched pool and account.
Each sync pass scans the watched pools after the credit pool, chunk by
chunk, advancing a per-account watermark only over chunks read whole,
so a short chunk ends the pass instead of leaving a gap. Spends are
seen from the nullifiers the pool's actions reveal. The state lives in
new tables of the shielded store's SQLite file; a type 28 purchase
watches the bought token's pool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FFI exports watch, unwatch and list a wallet's token shielded pools
(platform_wallet_manager_shielded_token_pool_{watch,unwatch,balances}
and the balances free function), marshalling the coordinator's results.
The Swift SDK wraps them, and a new Shielded Tokens screen in
SwiftExampleApp shows each watched token's balance per account, how far
the scan has got and the last scan error, refreshes through the shielded
sync, and watches or unwatches a known token. No SwiftData model changes.

Drops the manager wrappers the FFI does not use: it reaches the
coordinator directly, as the other shielded exports do.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n sound

- Each chunk rechecks, inside its transaction, that the wallet still
  watches the pool and the account's watermark row is still what the
  scan last wrote, so an unwatch, a wallet's removal, a Clear or a
  dropped account landing mid-scan is never undone; with no account
  left the chunk writes nothing and the scan stops.
- A Clear keeps the watch list and drops only scan state, in one
  transaction, so the next sync rescans the watched pools.
- Token notes found or spent, or a token pool failure, count as
  activity for the caught-up cooldown.
- A purchase records its pool watch before anything is reserved or
  sent; a watch that cannot be recorded refuses the purchase.
- Balances read only the unspent note values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@QuantumExplorer
QuantumExplorer force-pushed the feat/swift-example-shielded-token-notes branch from a7ab835 to 3a766bf Compare November 23, 2026 12:24
@github-actions

github-actions Bot commented Nov 23, 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.

@QuantumExplorer
QuantumExplorer merged commit 9e1ba58 into v5.1-dev Nov 23, 2026
6 of 8 checks passed
@QuantumExplorer
QuantumExplorer deleted the feat/swift-example-shielded-token-notes branch November 23, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-bots Waiting for the review bots to report on this head

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants