Skip to content

feat(platform-wallet)!: top up an identity the wallet does not manage from Platform addresses - #5860

Open
romchornyi wants to merge 20 commits into
v5.2-devfrom
feat/platform-wallet-external-identity-top-up
Open

romchornyi wants to merge 20 commits into
v5.2-devfrom
feat/platform-wallet-external-identity-top-up

Conversation

@romchornyi

@romchornyi romchornyi commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

A wallet cannot pay credits from its Platform addresses to someone else's identity. IdentityWallet::top_up_from_addresses (and the PlatformWallet composite over it) reads the identity from the wallet's identity manager and returns IdentityNotFound for any identity the wallet does not manage. Dash Wallet iOS needs this for Platform → Identity ID sends in its new Send flow (dashpay/dashwallet-ios#1358); today that pair fails before anything is submitted.

What was done?

  • IdentityWallet::top_up_external_from_addresses — fetches the identity from Platform (Identity::fetch) and runs the same IdentityTopUpFromAddresses transition with the given inputs and address signer. It never adds the identity to the identity manager and persists nothing about it. An identity Platform does not know is IdentityNotFound, with nothing signed or broadcast.
  • PlatformWallet::top_up_external_identity_from_addresses — the composite: reconciles the spent Platform addresses through the same reconcile_address_infos path as the managed top-up.
  • The build / broadcast / error mapping now lives in one private helper used by both the managed and the external path.
  • FFI: platform_wallet_top_up_external_identity_from_addresses_with_signer, the same shape as the managed export; the input marshalling is shared between the two exports.
  • Swift: ManagedPlatformWallet.topUpExternalIdentityFromAddresses(identityId:inputs:addressSigner:) async throws -> UInt64 returns the identity's new balance and writes nothing to SwiftData. The managed and external wrappers share one marshalling helper.
  • docs/sdk/sdk-parity-manifest.json: new capability identity.external_top_up_from_addresses, Kotlin recorded as unsupported (PARITY_SUMMARY.md regenerated).

How Has This Been Tested?

  • cargo test -p platform-wallet -p platform-wallet-ffi — all pass. New Rust tests:
    • an unmanaged identity's transition is built, signed once and broadcast once, and the identity manager's identities are unchanged afterwards (should_submit_a_top_up_for_an_identity_the_wallet_does_not_manage); an unknown identity returns IdentityNotFound with 0 signatures and 0 broadcasts;
    • confirmation binding (nonce_binding_tests): a snapshot behind the submitted nonces, and used nonces without a higher identity balance, are unconfirmed; used nonces with growth stand; growth is measured against Platform's balance, not a stale cache (should_keep_growth_over_platforms_balance_that_a_stale_cache_hides);
    • the managed route reads the identity's balance from Platform before signing (should_read_the_managed_identitys_balance_from_platform_before_signing);
    • empty funding rows are InvalidParameter before any lookup, on both routes (should_report_empty_inputs_as_an_invalid_parameter_on_both_routes);
    • lifecycle: a removed or re-created wallet is refused on both routes, and a removal waits for a running top-up (should_refuse_a_top_up_from_a_wallet_no_longer_current_on_both_routes, should_hold_a_wallets_removal_until_its_top_up_returns);
    • a confirmed result reconciles the spent addresses through the top_up_identity_with seam (should_reconcile_the_spent_addresses_of_a_confirmed_top_up).
  • FFI tests: null pointers, zero inputs, a bad address type, not-found through a real handle, the registry released while the host signs.
  • cargo fmt --all -- --check clean; cargo clippy -p platform-wallet-ffi --all-targets -- -D warnings clean. cargo clippy -p platform-wallet --all-targets -- -D warnings reports no lint in this PR's changes; it fails only on dead-code warnings already present on the base in files this PR does not touch (asset_lock/operation.rs, asset_lock/sync/tracking.rs, and dash-sdk's verify_response_metadata_as_of).
  • Swift: ExternalIdentityTopUpTests 6/6 (marshalling, 32-byte id guard, error mapping). The full SwiftDashSDKTests target ran 942 tests with 2 failures in KeychainSignerAdditionalSigningKeysTests (the keychain write returns nil on the simulator); they fail the same way without this change.
  • Not covered: a confirmed result coming from the real SDK. The mock SDK verifies the result proof for real and there are no recorded vectors for this transition, so the SDK-driven tests stop at "built, signed, broadcast once"; the reconciliation of a confirmed result is covered through the top_up_identity_with seam instead. It will be exercised by a testnet send from the wallet.

Breaking Changes

  • platform_wallet_top_up_from_addresses_with_signer and PlatformWallet::top_up_from_addresses no longer saturate when the funding rows naming one address sum past u64::MAX: the sum is refused with PlatformWalletError::InvalidParameter (FFI ErrorInvalidParameter, 2) before anything is signed or sent. Before, the FFI wrapper saturated the sum silently and topped up with u64::MAX credits for that address.

  • An empty list of funding rows still returns FFI ErrorInvalidParameter (2), but the check moved from the FFI wrapper ("inputs_count is zero") into the library (funding_inputs), still before any lookup or network I/O on both routes. Rust callers of top_up_from_addresses now get PlatformWalletError::InvalidParameter where they got InvalidIdentityData before.

  • The managed top-up (top_up_from_addresses, FFI platform_wallet_top_up_from_addresses_with_signer) now reads the identity's balance from Platform before signing, as the baseline the confirmation must see the balance grow from. This adds one Platform request, and two pre-sign outcomes: a failed read is IdentityLookupFailed (80) and an identity Platform does not know is IdentityNotFound (7); nothing is signed or broadcast in either case.

  • The managed top-up now also goes through the wallet's generation lifecycle gate (as the external one does): for a wallet removed or re-created since the handle was taken it returns WalletRemovedBeforeSend (FFI NotFound) before anything is sent, and a removal waits until a running top-up returns.

  • IdentityWallet::top_up_from_addresses (reachable through PlatformWallet::identity()) is now crate-private, like the external route's identity-side method: it skipped the lifecycle gate and the address reconciliation. Rust callers use PlatformWallet::top_up_from_addresses; the FFI already did.

  • New FFI code 80 ErrorIdentityLookupFailed (PlatformWalletError::IdentityLookupFailed, Swift PlatformWalletError.identityLookupFailed, Kotlin DashSdkError.PlatformWallet.IdentityLookupFailed): the new external top-up (platform_wallet_top_up_external_identity_from_addresses_with_signer) reports a failed recipient lookup as this code, with nothing signed or broadcast, so the call may be retried as it is. A missing identity stays ErrorIdentityNotFound (7). Hosts should treat 80 as "not sent", not as a possibly delivered top-up.

  • Both address top-ups (managed and external) now bind the confirmation to this top-up: the result stands only when the proof shows every input address at or past the nonce it was signed with and the identity balance above the balance read before signing. Otherwise it is reported as StateTransitionResultUnconfirmed (FFI 20, do not submit again) with nothing reconciled, where it was reported as success. The affected-state proof cannot rule out a competing transition with the same nonces plus an unrelated credit to the identity; that needs an execution-bound proof (Bind affected-state proofs to transition execution #4270). A failed wait or proof after the broadcast is also 20 now (it was 99). Other SDK errors keep their typed Sdk variant instead of InvalidIdentityData.

  • A panic inside either export returns 20 instead of unwinding across the C boundary — on unwinding targets only. The iOS profiles (dev-ios, release-ios) build with panic = "abort", so on iOS a panic still aborts the process; that workspace-wide profile is tracked in FFI panic guards cannot catch on iOS: the iOS profiles use panic = abort #5920.

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 · 2ce86e8

  • Bots — coderabbitai 1 thread unresolved — resolve it · thepastaclaw ✓, 4 threads unresolved — resolve them
  • 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 green
  • Approvals
    • files with no dedicated owner (docs/sdk/sdk-parity-manifest.json) — QuantumExplorer or shumkov
    • kotlin-sdk (packages/kotlin-sdk/PARITY_SUMMARY.md, packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/errors/DashSdkError.kt, packages/kotlin-sdk/sdk/src/test/kotlin/org/dashfoundation/dashsdk/errors/DashSdkErrorTest.kt) — HashEngineering
    • rs-platform-wallet-ffi (packages/rs-platform-wallet-ffi/ERROR_CODE_REGISTRY.md, packages/rs-platform-wallet-ffi/src/error.rs, packages/rs-platform-wallet-ffi/src/identity_top_up.rs and 3 more) — HashEngineering or ZocoLini or llbartekll
    • rs-platform-wallet (packages/rs-platform-wallet/src/error.rs, packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs, packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs and 1 more) — HashEngineering or ZocoLini or llbartekll
    • swift-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.

Summary by CodeRabbit

  • New Features
    • Added support for topping up identities not managed by the wallet using address-based funding.
    • Address-based top-ups now accept repeated addresses and combine their amounts.
  • Bug Fixes
    • Identity lookup failures now return a specific, retryable error instead of a generic error.
    • Invalid or overflowing funding inputs are rejected, and failed lookups do not submit a top-up.

romchornyi and others added 2 commits November 11, 2026 13:18
…from Platform addresses

top_up_from_addresses reads the identity from the wallet's identity manager and
returns IdentityNotFound for any other identity, so a wallet could not pay
credits from its Platform addresses to someone else's identity.

- IdentityWallet::top_up_external_from_addresses fetches the identity from
  Platform and runs the same transition; it never adds the identity to the
  manager or persists anything about it. An unknown identity is IdentityNotFound
  with nothing signed or broadcast.
- PlatformWallet::top_up_external_identity_from_addresses reconciles the spent
  addresses through the same path as the managed composite.
- FFI: platform_wallet_top_up_external_identity_from_addresses_with_signer,
  sharing the input marshalling with the managed export.
- The build/broadcast/error mapping is shared by both paths.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Swift wrapper over platform_wallet_top_up_external_identity_from_addresses_with_signer:
tops up an identity the wallet does not manage from the wallet's Platform
addresses and returns the identity's new balance. It writes nothing to
SwiftData. The managed and external wrappers share one marshalling helper.
The parity manifest records the capability as unsupported in Kotlin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The wallet now supports address-funded top-ups for identities it does not manage. The FFI and Swift SDK expose the operation. Native error code 77 identifies Platform identity lookup failures, with typed error mappings and tests in Swift and Kotlin.

Changes: External identity top-up

Layer / File(s) Summary
Wallet top-up and lifecycle
packages/rs-platform-wallet/src/error.rs, packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs, packages/rs-platform-wallet/src/wallet/platform_wallet.rs, packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs
Managed top-ups now accept funding rows. The wallet aggregates duplicate addresses with checked addition. External top-ups fetch an unmanaged identity, submit the transaction, and reconcile confirmed address information without adding the identity to the manager.
FFI entry point and error mapping
packages/rs-platform-wallet-ffi/ERROR_CODE_REGISTRY.md, packages/rs-platform-wallet-ffi/src/error.rs, packages/rs-platform-wallet-ffi/src/identity_top_up.rs, packages/rs-platform-wallet-ffi/src/identity_top_up/*
The FFI adds an external-identity top-up export and maps lookup failures to code 77. Tests cover input validation, missing identities, and registry access while signing is pending.
SDK wrappers, typed errors, and parity
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/*, packages/swift-sdk/SwiftTests/SwiftDashSDKTests/*, packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/errors/DashSdkError.kt, packages/kotlin-sdk/sdk/src/test/kotlin/org/dashfoundation/dashsdk/errors/DashSdkErrorTest.kt, docs/sdk/sdk-parity-manifest.json, packages/kotlin-sdk/PARITY_SUMMARY.md
Swift adds the external top-up wrapper and a typed lookup error. Kotlin maps code 77 to IdentityLookupFailed. Tests and parity records document the support status.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant IdentityTopUpFFI
  participant PlatformWallet
  participant Platform
  participant AddressSigner
  Caller->>IdentityTopUpFFI: Call external identity top-up
  IdentityTopUpFFI->>PlatformWallet: Pass identity and funding rows
  PlatformWallet->>Platform: Fetch target identity
  Platform-->>PlatformWallet: Return identity or lookup result
  PlatformWallet->>AddressSigner: Sign top-up inputs
  AddressSigner-->>PlatformWallet: Return signature
  PlatformWallet->>Platform: Submit top-up
  Platform-->>PlatformWallet: Return result and address information
  PlatformWallet-->>IdentityTopUpFFI: Return balance or error
  IdentityTopUpFFI-->>Caller: Return FFI result
Loading

Possibly related PRs

  • dashpay/platform#5865: Both PRs use error code 77 in the platform-wallet FFI error mapping. This PR assigns it to IdentityLookupFailed; the related PR assigns it to ShieldedPlanChanged.

Suggested reviewers: quantumexplorer, shumkov

Merge Risk: Moderate · up to ccf95

Topping up an external identity from Platform addresses may report success when the recipient's balance has not yet changed, so a send could be recorded without crediting the identity. Funding shortfalls also cannot be identified programmatically, and the Kotlin lookup-failure error is not marked retryable. Resolve the success-confirmation concern before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a new capability to top up an identity that the wallet does not manage, using Platform addresses. The changeset adds the external-identity top-up path in the Rust, FFI…
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.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: a new capability to top up an identity that the wallet does not manage, using Platform addresses. The changeset adds the external-identity top-up path in the Rust, FFI, Swift and Kotlin layers, and the PR objectives state the same feature. The conventional-commit scope (platform-wallet) and breaking marker (!) match the breaking changes described in the PR, namely the overflow handling change and the BTreeMap-to-iterator signature change. The title is specific and concise.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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 11, 2026
@github-actions

github-actions Bot commented Nov 11, 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 11, 2026
@thepastaclaw

thepastaclaw commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 2ce86e8) · 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 b1b7129. The external top-up retains the existing proof-verification path, but the new spending route lacks wallet-generation protection, the shared FFI decoder owns funding-amount policy, and the reused Swift helper does not explicitly pin its signer across the FFI call. This was a static review: current Rust workspace, Swift SDK, and Kotlin SDK checks pass; dedicated Rust wallet tests were skipped, and review/hygiene checks remain pending.

🔴 3 blocking | 🟡 3 suggestion(s)

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

🔴 Blocking: Pin the address signer across the synchronous FFI call
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:896-907

The shared helper captures addressSigner only through the earlier _ = addressSigner, then invokes Rust using the separately captured raw handle. That discard is not a lifetime fence across the subsequent call in optimized Swift. KeychainSigner registers self with passUnretained, and its deinit destroys the Rust signer handle, so a short-lived signer can leave Rust with a freed handle or callback context while lookup, signing, or confirmation is still running. Other wrappers in this same file explicitly use withExtendedLifetime for this ownership arrangement and explain why a bare discard is insufficient. Wrap the complete synchronous call and its buffer-pinning closures in withExtendedLifetime(addressSigner). This is in scope: the PR moves this implementation into a shared helper and adds the external entry point as another caller, rather than merely sitting beside the existing pattern.

source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)

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: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 11: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 12: 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 production changes add a straightforward external-recipient top-up path across Rust, FFI and Swift while reusing existing signing, submission and reconciliation logic, so the substantial test coverage does not make the implementation large or intricate enough for critical.
  • 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: 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 — rust-quality (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 — rust-quality (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/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:622-628: Fence external top-ups against wallet removal and recreation
  A retained wallet Arc or FFI handle can execute this spend after remove_wallet completes. Unlike the managed route's initial wallet-manager lookup, top_up_external_from_addresses only fetches the recipient and delegates to the SDK; neither it nor this composite checks the registered generation or participates in its lifecycle gate. Removal can also complete while recipient lookup or signing is suspended, after which the operation can still broadcast and reconcile through stale wallet state. The existing WalletGeneration contract explicitly requires network-publishing operations to exclude teardown, and the FFI removal hook does not invalidate PlatformWallet handles. Apply generation-aware protection in the Rust orchestration, covering submission and reconciliation and protecting the public identity-side route as well. Test retained handles, same-id recreation, and removal during signing; a wallet-id check before an await does not close the race.

In `packages/rs-platform-wallet-ffi/src/identity_top_up.rs`:
- [BLOCKING] packages/rs-platform-wallet-ffi/src/identity_top_up.rs:150-161: Move funding-row normalization into the wallet library
  This helper decides that repeated funding rows are additive and that overflowing amounts are silently saturated. Those are funding-amount decisions, not representation conversion: the wallet library receives only the resulting map and cannot own or consistently expose the normalization policy to native callers. The book's “FFI and mobile SDKs hold no business logic” rule explicitly places decisions about how many in the Rust library. This PR extracts that policy and extends it to the external export, so its pre-existence on the managed route does not exempt the new shared boundary. Introduce wallet-owned row normalization used by both routes, leaving the FFI to decode address representations and forward rows. Handle overflow explicitly in that owner and add duplicate-address and overflow tests there; neither branch is currently covered by the top-up FFI tests.

In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:896-907: Pin the address signer across the synchronous FFI call
  The shared helper captures addressSigner only through the earlier `_ = addressSigner`, then invokes Rust using the separately captured raw handle. That discard is not a lifetime fence across the subsequent call in optimized Swift. KeychainSigner registers self with passUnretained, and its deinit destroys the Rust signer handle, so a short-lived signer can leave Rust with a freed handle or callback context while lookup, signing, or confirmation is still running. Other wrappers in this same file explicitly use withExtendedLifetime for this ownership arrangement and explain why a bare discard is insufficient. Wrap the complete synchronous call and its buffer-pinning closures in withExtendedLifetime(addressSigner). This is in scope: the PR moves this implementation into a shared helper and adds the external entry point as another caller, rather than merely sitting beside the existing pattern.

In `packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:281-288: Exercise successful external top-up reconciliation
  The present-identity fixture returns an empty, unverifiable result proof, so submitted top-ups always exit with StateTransitionResultUnconfirmed. This test discards that result and therefore establishes unchanged identity membership only on the unconfirmed path. Removing the new composite's reconciliation call, forwarding an incorrect proof height, or recording the recipient only after confirmation would leave the tests passing. Add a deterministic successful-result fixture or a narrow confirmed-submission test seam at the Rust composite boundary. Assert the returned identity balance, reconciled and persisted funding-address balances/nonces and height pin, and that the external recipient is neither added nor persisted as a managed identity. Existing reconciliation-seam tests do not cover this new route's wiring, and a future testnet send is not an automated regression test.

In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ExternalIdentityTopUpTests.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/ExternalIdentityTopUpTests.swift:90-101: Verify the external wrapper selects the external export
  The parity manifest names this test as verification for identity.external_top_up_from_addresses, but it calls the shared topUpFromAddresses helper with a fake closure, bypassing the public external wrapper and its export selection. The code-7 test does the same. Tests that reach the public external method use malformed arguments or a null wallet handle, which cannot distinguish the managed and external exports. Consequently, changing the external wrapper to select the managed export would still pass this suite. Add a dispatch regression that distinguishes the two exports—for example, invoke the public wrapper with a mock-backed wallet and a recipient present on Platform but absent from its identity manager—and retain these shared-marshalling tests as separate coverage.

In `packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:159-166: Preserve empty-input failures as invalid parameters
  For an existing recipient, an empty Rust input map is rejected by the SDK's fetch_inputs_with_nonce with a typed TransitionNoInputsError, but this fallback converts it into InvalidIdentityData. The FFI rejects the same caller mistake as ErrorInvalidParameter, and PlatformWalletError::InvalidParameter explicitly documents that distinction. Native callers therefore receive an identity-data failure for a malformed funding argument and lose the typed repair signal. Preserve the SDK's empty-input discriminator as InvalidParameter in this error mapping and add coverage for both top-up routes. Reuse the SDK's validation rather than adding another copy of the empty-input rule.
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.

  • External top-up leaves a managed identity's cached balance stale if called with an owned id — The API is explicitly documented at both Rust entry points as topping up an identity this wallet does not manage, and it deliberately neither reads nor writes the identity manager. Managed recipients already have a separate operation that updates their cached balance. The proposed documentation alternative is already present; using the external API outside that documented recipient contract does not establish a defect.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.

@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 11, 2026
…funding-row policy

Review fixes for the external identity top-up:
- The external composite takes the wallet generation's payment guard and
  checks the generation is current before fetching the identity, holding it
  through signing, broadcast and reconcile; a removed or recreated wallet gets
  WalletRemovedBeforeSend with nothing signed or sent.
- platform-wallet now takes the funding rows, sums repeated addresses and
  refuses an overflowing sum with InvalidParameter; the FFI only converts row
  types, for both the managed and the external export. The managed export now
  errors on overflow instead of saturating, and its empty-input check moves to
  the library.
- The SDK's TransitionNoInputsError maps to InvalidParameter on both routes.
- Swift: the shared helper pins addressSigner with withExtendedLifetime across
  the synchronous FFI call; the exports are injectable and a test through both
  public wrappers shows each calls its own export.
- A composite seam test covers a confirmed external top-up: balance returned,
  spent address reconciled and persisted at the proof height, identity manager
  unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@romchornyi

Copy link
Copy Markdown
Contributor Author

Re "Pin the address signer across the synchronous FFI call": fixed in 2271e8c — the shared helper pins addressSigner with withExtendedLifetime across the whole synchronous FFI call and its buffer pinning.

@github-actions

github-actions Bot commented Nov 11, 2026 •

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.

@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

On 2271e8c, five prior findings are fixed, with wallet-owned checked funding normalization, signer pinning, and new dispatch/reconciliation coverage. A new blocking registry-lock issue is confirmed in the external FFI export, and one prior finding remains open. Static-only verification: Rust workspace, Swift and Kotlin CI checks pass; dedicated wallet tests are skipped, and review/hygiene checks remain pending.

🔴 2 blocking

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

🔴 Blocking: Release the wallet registry before waiting on the host signer
packages/rs-platform-wallet-ffi/src/identity_top_up.rs:185-194

HandleStorage::with_item holds its process-global parking_lot registry read guard throughout this closure, including block_on_worker. Cloning the wallet inside the closure therefore does not release the registry during recipient lookup, foreign signer callbacks, broadcast or proof waiting. ManagedPlatformWallet.deinit synchronously calls platform_wallet_destroy, which needs this registry's write lock, so releasing even an unrelated wallet wrapper on the UI thread blocks it for the network/signing wait.

A queued destroy also prevents subsequent registry readers from proceeding. If host signing completion work reads a wallet balance, it waits behind that writer while the export waits for signing, producing a lock cycle; an asynchronously returning signer only escapes through its timeout. Clone the wallet Arc in a short with_item call, unwrap it, and invoke block_on_worker after that call has returned, as the existing DashPay exports do. Add a regression that holds signing while destroying another wrapper and reading a balance.

source: gpt-6.1-sol (phase2-reviewer: ffi-engineer)

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: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The change is intricate across Rust, FFI and Swift and directly extends funds movement through IdentityWallet::top_up_external_from_addresses and PlatformWallet::top_up_external_identity_from_addresses, including signing, broadcasting and spent-address reconciliation.
  • 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-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:151-158: Fence external top-ups against wallet removal and recreation
  The new composite guard protects PlatformWallet and FFI callers, but the separately public IdentityWallet entry point still bypasses it. A native caller can retain wallet.identity().clone(), await manager.remove_wallet(...), then invoke this method: it fetches the recipient and reaches SDK signing and broadcast without checking self.generation or taking its lifecycle gate. Removal can also complete while a direct call is suspended in signing, allowing the spend afterward. Same-ID recreation does not invalidate the retained SDK or external signer.

  This is the new external API, not the pre-existing managed-route gap you left unchanged. The non-reentrant gate prevents simply nesting another acquisition, but does not require leaving a public spending route unprotected. Provide a guarded public identity-side method backed by a separate internal already-guarded implementation, so the composite retains one guard through reconciliation; alternatively, make the unfenced method internal and expose only the guarded composite. Add direct identity-handle regressions for removal, recreation and suspended signing; the current lifecycle tests invoke only the composite.

In `packages/rs-platform-wallet-ffi/src/identity_top_up.rs`:
- [BLOCKING] packages/rs-platform-wallet-ffi/src/identity_top_up.rs:185-194: Release the wallet registry before waiting on the host signer
  HandleStorage::with_item holds its process-global parking_lot registry read guard throughout this closure, including block_on_worker. Cloning the wallet inside the closure therefore does not release the registry during recipient lookup, foreign signer callbacks, broadcast or proof waiting. ManagedPlatformWallet.deinit synchronously calls platform_wallet_destroy, which needs this registry's write lock, so releasing even an unrelated wallet wrapper on the UI thread blocks it for the network/signing wait.

  A queued destroy also prevents subsequent registry readers from proceeding. If host signing completion work reads a wallet balance, it waits behind that writer while the export waits for signing, producing a lock cycle; an asynchronously returning signer only escapes through its timeout. Clone the wallet Arc in a short with_item call, unwrap it, and invoke block_on_worker after that call has returned, as the existing DashPay exports do. Add a regression that holds signing while destroying another wrapper and reading a balance.
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.

  • Fence the existing managed address-funded top-up separately — The managed top-up releases its wallet-manager lookup before submission and later updates identity state by wallet ID without lifecycle exclusion or generation comparison. Removal can interleave with submission, and same-ID recreation can receive a stale handle's confirmed balance update. This lifecycle defect exists in the review base and is separate from the newly added external API.
    • Follow-up: Create a follow-up issue or PR adding generation-aware lifecycle protection to the managed identity-side and composite routes, covering submission, identity persistence and address reconciliation.

romchornyi and others added 2 commits November 12, 2026 11:17
…on the signer

Both address top-up exports ran block_on_worker inside
PLATFORM_WALLET_STORAGE.with_item, so the registry read guard stayed held
while the host signed. A wallet handle destroy (write lock) queued behind it,
and any registry read queued behind that destroy, so a signing completion that
reads a balance could never finish.

Clone the wallet Arc in a short with_item and wait on the signer after it
returns. The regression test holds a callback signer pending, then destroys a
second wallet handle and reads a balance; both must finish before the signer
is answered, for both exports.

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

Make IdentityWallet::top_up_external_from_addresses crate-private so the
only public route to topping up someone else's identity is
PlatformWallet::top_up_external_identity_from_addresses, which holds the
wallet lifecycle gate and refuses a removed or re-created wallet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@romchornyi

Copy link
Copy Markdown
Contributor Author

Registry-lock finding from the re-review (identity_top_up.rs:185): fixed in 77c2161. Both address top-up exports take the wallet out of the registry in a short with_item and wait on the signer after it returns; a regression holds a callback signer pending while destroying a second wallet handle and reading a balance, for both exports.

@github-actions

github-actions Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Your move: thepastaclaw left review threads unresolved; resolve them.
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.

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

At a982205, one blocking ownership violation remains: the shared Swift top-up helper duplicates empty-funding validation already owned by Rust. The new lifecycle regression also needs a bounded signer rendezvous. This was static verification only; current CI reports passing Rust workspace and Kotlin checks, while Swift build/tests remain pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 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.

Follow-up candidates (optional) (2)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: Bound the lifecycle test's signer rendezvous
packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:470

If recipient lookup or transition preparation returns an error or panics before HeldSigner::sign, the spawned task finishes without notifying this wait. Notify does not report producer termination, and the test does not inspect the top-up JoinHandle until after receiving the notification, so the regression hangs instead of reporting the preparation failure. Add a deadline to this rendezvous, or select between the notification, task completion, and a deadline.

    tokio::time::timeout(Duration::from_secs(60), signer.entered.notified())
        .await
        .expect("the top-up never reached the signer");

source: gpt-6.1-sol (phase2-reviewer: rust-quality)

🟡 Suggestion: Keep empty-funding validation in Rust
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:852-854

The extracted helper extends this Swift-side input-count rule to the new external top-up API. DPP's IdentityTopUpFromAddressesTransitionV0::validate_structure already owns the rule, the SDK's fetch_inputs_with_nonce rejects empty inputs before signing, and the shared wallet submission helper maps that typed refusal to InvalidParameter. Unlike byte-width checks needed to construct fixed-size C values, rejecting an empty collection is semantic validation. This violates the book's explicit prohibition on duplicating DPP count checks in bindings and bypasses Rust's error ordering: an empty call through a removed wallet returns WalletRemovedBeforeSend natively but invalidParameter here. Remove this guard and forward empty funding collections to Rust. Update both FFI exports to accept a null input pointer when the count is zero, and construct an empty collection without calling slice::from_raw_parts on null. Replace the Swift test requiring pre-FFI rejection with coverage that the public wrapper forwards the Rust-emitted refusal.

source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)

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: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 11: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 12: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); 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 funds movement, transaction construction, address reconciliation, signing, broadcasting, and FFI/Swift key-handling paths in IdentityWallet::top_up_external_from_addresses and its platform-wallet/FFI wrappers.
  • 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 final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Code unchanged since the last final review (2271e8cd): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 not confirmed (now follow-up candidates); 1 new suggestion(s) listed as follow-up candidates, not posted inline
  • 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, 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. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.
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.

  • Fence the pre-existing managed top-up route against wallet teardown — IdentityWallet::top_up_from_addresses releases its initial wallet-manager read before signing and submission without holding the generation lifecycle gate. A signature suspended during removal can resume and broadcast after removal completes, and subsequent local reconciliation can report WalletNotFound despite the spend. This race is present in the merge-base; the new external composite protects its own route.
    • Follow-up: Create a separate follow-up PR protecting both public managed address-top-up entry points against removal and same-ID recreation, with a regression that suspends signing during removal.

@github-actions

Copy link
Copy Markdown
Contributor

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

@romchornyi

Copy link
Copy Markdown
Contributor Author

/self-reviewed

@github-actions

Copy link
Copy Markdown
Contributor

Missing human approval. Automatic reviewer requests are paused and this PR is excluded from reviewers' queues. Merge, close, or draft another active PR by this author to free a review slot. Required human review can be satisfied without a slot; once all merge requirements are met, PR Hygiene passes.
Full checklist in the description.

@github-actions github-actions Bot added too-many-open-prs Beyond the author's 5 open PRs; waits for one to merge before a human is asked. and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 12, 2026

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

Approving. Two notes, non-blocking:

  • The managed top_up_from_addresses path changes on edge cases: an overflowing sum of funding rows now returns InvalidParameter instead of saturating, and the empty-inputs error code changed. Worth a line under Breaking Changes in the PR body.
  • On the external path, a failed Identity::fetch surfaces as a generic Sdk error even though nothing was signed or broadcast yet; a dedicated not-sent classification would help hosts that treat unknown errors as "may have gone through".

The Kotlin binding will follow in a separate PR.

romchornyi and others added 2 commits November 13, 2026 08:24
…let-external-identity-top-up

# Conflicts:
#	packages/kotlin-sdk/PARITY_SUMMARY.md
…l top-up as not sent

A failed `Identity::fetch` on the external identity top-up surfaced as a
generic `Sdk` error although nothing had been signed or broadcast, which
a host treating unknown errors as "may have gone through" cannot tell
from a failure after a dispatch. It is now
`PlatformWalletError::IdentityLookupFailed`, mapped to the new FFI code
77 `ErrorIdentityLookupFailed` and mirrored in Swift and Kotlin. A missing
identity keeps `IdentityNotFound` (7). No existing code meant "refused
before anything was sent" for a Platform state transition.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
romchornyi and others added 3 commits November 13, 2026 12:04
…into a result code

Both address top-up exports ran the composite through block_on_worker,
which re-panics a worker panic inside the extern "C" function and ends
the host. Their bodies now run under catch_panic_to_code and report
ErrorTransactionBroadcastUnconfirmed (20): the panic may strike after
signing or broadcast, so the top-up may still execute and must not be
submitted again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The address top-up promotes a nonce race and an empty input map to their
own errors; every other SDK error was flattened into an
InvalidIdentityData string, losing its typed variant and consensus cause.
It is now kept as PlatformWalletError::Sdk.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IdentityLookupFailed (code 80) means nothing was signed, reserved or
broadcast, so the operation may be retried as it is; isRetryable now says
so, as the code-80 mapping test asserts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@romchornyi

Copy link
Copy Markdown
Contributor Author

@HashEngineering correction to my earlier note: the identity lookup failure is FFI code 80, not 77 (a08f7ff) — 77–79 are taken by #5865. The Breaking Changes section is updated, including the new unconfirmed (20) results from this round.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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

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

Four in-scope blocking correctness defects remain: nonce advancement can be caused by a competing transition, the iOS panic-abort profiles defeat the new panic catcher, detached Swift top-ups do not retain the wallet owning the FFI handle, and the managed address-top-up route remains unfenced against wallet removal. The Rust workspace and Swift SDK code checks reported success, with no failed code checks attributed to this change.

A pattern across this PR's review rounds

This is review round 5, and the PR has drawn 8 blocking findings so far. 4 of them share one underlying cause. They are listed with the other findings as usual; fixing the cause is likely to be cheaper than fixing each case.

1. No operation-scoped lifetime owner (1 new in this round, 3 earlier finding(s))

The address top-up has no single owner for the resources it uses across the Swift and Rust boundaries. The detached Swift call copies raw wallet and signer handles, while Rust lifecycle protection is attached to selected entry points, so each review fix adds a fence at one path and leaves another owner or entry point able to outlive the operation. This is why retaining the signer still left the wallet handle vulnerable during the same network-publishing call.

In this round: Keep ManagedPlatformWallet alive for the detached top-up call

Suggested decision (redesign the component): Redesign the address-top-up boundary around one operation-scoped lease instead of adding more per-call lifetime guards. The lease must retain the Swift wallet and signer owners and hold one Rust wallet generation through lookup, signing, broadcast, confirmation, and reconciliation, with both managed and external APIs using that same path. Do not extend this feature with further entry points until that ownership model is in place.

If a later review again finds new blockers from this cause, it will ask for that decision and pause automatic re-review until it is made.

🔴 4 blocking

Still open from earlier rounds (3)

  • 🔴 Blocking: Do not report an affected-state snapshot as a completed external top-up — packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:277-291 (thread)
  • 🔴 Blocking: Prevent worker panics from escaping the address top-up C exports — packages/rs-platform-wallet-ffi/src/identity_top_up.rs:62-70 (thread)
  • 🔴 Blocking: Fence managed address top-ups against wallet removal and recreation — packages/rs-platform-wallet/src/wallet/platform_wallet.rs:617-620 (thread)
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: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); 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, cross-language change that modifies identity top-up funds movement and transaction signing in IdentityWallet, PlatformWallet, FFI, and Swift wrappers, including new external-identity handling and changed validation behavior.
  • 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)
  • Code unchanged since the last final review (ccf95e59): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed
  • 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
Several findings on this PR share an underlying cause (the review's "pattern" section): No operation-scoped lifetime owner. When you fix the findings below, fix the cause, not only the reported case. The review suggests (redesign the component): Redesign the address-top-up boundary around one operation-scoped lease instead of adding more per-call lifetime guards. The lease must retain the Swift wallet and signer owners and hold one Rust wallet generation through lookup, signing, broadcast, confirmation, and reconciliation, with both managed and external APIs using that same path. Do not extend this feature with further entry points until that ownership model is in place. If that decision is not yours to make, say so to the PR's author or maintainer.

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/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift`:
- [BLOCKING] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:872-873: Keep ManagedPlatformWallet alive for the detached top-up call
  The detached closure captures `handle` and `addressSignerHandle`, but not the `ManagedPlatformWallet` instance that owns `handle` in the FFI registry. Swift may release the last wallet reference after the local handle is copied and before the detached task invokes the export; `deinit` then destroys the registry handle while the task is still pending. The export can fail before Rust obtains its protective wallet clone, and a future handle reuse could make the call target a different wallet. Capture the wallet owner or otherwise use `withExtendedLifetime(self)` across the synchronous FFI invocation, and add a regression that releases the wallet while the export is blocked.

  _Raised on code unchanged since the last review, and confirmed by an independent pass: After `self.handle` is copied, the detached closure captures only the raw handle and not `self`; the wallet can therefore deinitialize while the task is pending, destroying the FFI registry handle before the export resolves it. The call then fails or, if the handle is reused, can dispatch against a different wallet._

In `packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:277-291: Do not report an affected-state snapshot as a completed external top-up
  (carried; thread: https://github.com/dashpay/platform/pull/5860#discussion_r4561405120)

In `packages/rs-platform-wallet-ffi/src/identity_top_up.rs`:
- [BLOCKING] packages/rs-platform-wallet-ffi/src/identity_top_up.rs:62-70: Prevent worker panics from escaping the address top-up C exports
  (carried; thread: https://github.com/dashpay/platform/pull/5860#discussion_r4561405132)

In `packages/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:617-620: Fence managed address top-ups against wallet removal and recreation
  (carried; thread: https://github.com/dashpay/platform/pull/5860#discussion_r4538714345)

Comment on lines 872 to +873
return try await Task.detached(priority: .userInitiated) { () -> UInt64 in
// Keepalive — see `registerIdentityFromAddresses` for
// rationale. The trampoline ctx pointer dangles unless
// the Swift owner stays alive across this detached work.
_ = addressSigner

var idTuple: (
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
var idTuple: IdentityIdBytes = (

@thepastaclaw thepastaclaw Nov 13, 2026 •

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.

✅ Resolved at d448bb9d; see the replies below.

🔴 Blocking: Keep ManagedPlatformWallet alive for the detached top-up call

The detached closure captures handle and addressSignerHandle, but not the ManagedPlatformWallet instance that owns handle in the FFI registry. Swift may release the last wallet reference after the local handle is copied and before the detached task invokes the export; deinit then destroys the registry handle while the task is still pending. The export can fail before Rust obtains its protective wallet clone, and a future handle reuse could make the call target a different wallet. Capture the wallet owner or otherwise use withExtendedLifetime(self) across the synchronous FFI invocation, and add a regression that releases the wallet while the export is blocked.

Raised on code unchanged since the last review, and confirmed by an independent pass: After self.handle is copied, the detached closure captures only the raw handle and not self; the wallet can therefore deinitialize while the task is pending, destroying the FFI registry handle before the export resolves it. The call then fails or, if the handle is reused, can dispatch against a different wallet.

source: gpt-6.1-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 9470844. The detached call now pins the wallet together with the signer (withExtendedLifetime((self, addressSigner))) for the whole synchronous export call, as refreshIdentityBalance does. (The caller already holds self until .value returns, so this makes the guarantee explicit rather than closing a reachable path.)

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.

Resolved (re-reviewed at d448bb9d): Fixed: the shared Swift helper now pins (self, addressSigner) with withExtendedLifetime across the whole synchronous FFI call and buffer pinning, so release of the last wallet reference cannot destroy the handle mid-call.

romchornyi and others added 2 commits November 13, 2026 15:52
… did not grow as unconfirmed

Used input nonces show that a transition this wallet signed with them executed, not that it paid the
identity: another transition with the same nonces could have spent them elsewhere. The result now also
needs the proved identity balance above the one the top-up started from; otherwise it is
StateTransitionResultUnconfirmed(ExecutionNotProved) (FFI 20) and nothing is reconciled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The detached call copies the wallet handle that ManagedPlatformWallet's deinit destroys; pin the wallet
together with the signer for the whole synchronous FFI call, as refreshIdentityBalance does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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

… removal

PlatformWallet::top_up_from_addresses now runs through the same seam as the external top-up
(top_up_identity_with): it holds the generation's lifecycle gate from the liveness check through signing,
broadcast and reconciliation, and a wallet removed or re-created since the handle was taken is refused
with WalletRemovedBeforeSend, nothing signed or sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them; thepastaclaw left review threads unresolved; resolve them.
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 — Re-review — Final validation — Phase 1 + Phase 2

⚠️ DEGRADED review. The primary review models were unavailable (gpt-6.1-sol unavailable: {"detail":"Rate limit exceeded"}), 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. 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.

External address-funded top-up is complete at this head: lifecycle-gated composites, nonce-and-balance-bound confirmation, panic-to-20 exports, library-owned funding policy, and code-80 plumbing all verify. Two in-scope polish items remain: fail-fast empty-input validation and stale confirmation docs. No blocking defect.

🟡 1 suggestion(s) | 💬 1 nitpick(s)

Review provenance

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

  • Degraded mode: gpt-6.1-sol unavailable: {"detail":"Rate limit exceeded"} (detected by probe); 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; Phase 1 effort capped at high
  • Triage: critical by muse-spark-1.3-contributor (standing in for gpt-6.1-sol) (effort low) — Large multi-language change adding IdentityWallet::top_up_external_from_addresses which builds, signs, and broadcasts a funds-moving top-up for arbitrary identities.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: glm-5.3-flash — zai quota: 5h 97% left, weekly 57% left; passed over gemini-3.8-flash-high (antigravity quota lookup failed)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — final-verifier; agent sol-verifier
  • Phase 2 reviewers: muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — general (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — architecture-layering (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — platform-versioning (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — rust-quality (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — security-auditor (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — general (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — architecture-layering (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — ffi-engineer (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — platform-versioning (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for gpt-6.1-sol) — rust-quality (completed, effort xhigh); agent phase2-reviewer, muse-spark-1.3-contributor (standing in for 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-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:235-248: Reject empty funding rows before the Platform fetch
  funding_inputs accepts an empty row list as Ok(empty) and leaves the refusal to fetch_inputs_with_nonce inside submit_top_up_from_addresses. On the external route Identity::fetch runs first, so a caller bug (zero rows) costs a network round-trip and a transport or proof failure masks it as IdentityLookupFailed instead of InvalidParameter; an unknown identity plus zero rows also reports IdentityNotFound before the malformed-argument error. Rejecting empty locally keeps local validation before remote IO and restores stable error precedence on both routes. The change is fail-fast only and does not alter the overflow or nonce behavior.

In `packages/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [NITPICK] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:645-650: Sync composite and FFI docs with the balance-growth condition
  69ffa84598 extended the unconfirmed predicate with the balance-growth condition but updated only the submit_top_up_from_addresses doc. The composite docs and both FFI export docs still describe the predicate as nonce-only, so a host integrator reading the FFI contract never learns that a proof with all nonces used but no balance growth is also code 20. The statements made are not false (sufficient conditions for 20) but the documented predicate is incomplete on a do-not-resubmit funds-safety contract. Copy the bind_to_submitted_nonces condition into those four doc paragraphs.
Out-of-scope follow-up suggestions (3)

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.

  • Gate or scope the direct managed IdentityWallet spend — IdentityWallet::top_up_from_addresses stays pub and reachable via the public PlatformWallet::identity() accessor, performing fetch/sign/broadcast plus persisted-balance write without holding generation_payment_guard. The FFI/Swift/Kotlin hosts use the gated composites, so this is hardening for in-process Rust callers (stale handle spending after removal or onto a recreated generation), not a defect this PR introduces.
    • Follow-up: Follow-up PR to make the direct IdentityWallet address top-up pub(crate) like the external one, or gate it identically, with direct-handle removal/recreation regressions.
  • Route registration funding rows through the wallet-owned normalizer — identity_registration_with_signer.rs still sums repeated funding rows with saturating_add in the FFI, silently clamping an overflowing sum to u64::MAX, while the top-up routes now refuse overflow as InvalidParameter in funding_inputs. Same funds-safety policy should live once in the library.
    • Follow-up: Follow-up routing the registration export rows through funding_inputs or a shared helper with overflow-refusal and duplicate-row tests.
  • Track iOS panic=abort and execution-binder gaps outside this PR — On dev-ios/release-ios panic=abort profiles the new catch_address_top_up_panic guard cannot return code 20, and the nonce-plus-balance binding remains heuristic (same-nonce competing spend plus unrelated credit) until the proving side ships execution binders for IdentityTopUpFromAddresses (#4270 Tier 3). Both are pre-existing/workspace-wide, not defects this PR introduces.
    • Follow-up: Separate issues: iOS staticlib panic strategy for all FFI exports; execution binding for this transition family under #4270.

Comment on lines +235 to +248
pub(crate) fn funding_inputs(
rows: impl IntoIterator<Item = (PlatformAddress, Credits)>,
) -> Result<BTreeMap<PlatformAddress, Credits>, PlatformWalletError> {
let mut inputs = BTreeMap::new();
for (address, credits) in rows {
let sum: &mut Credits = inputs.entry(address).or_default();
*sum = sum.checked_add(credits).ok_or_else(|| {
PlatformWalletError::InvalidParameter(format!(
"the funding amounts for {address:?} overflow"
))
})?;
}
Ok(inputs)
}

@thepastaclaw thepastaclaw Nov 13, 2026 •

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.

✅ Resolved at 8089a7e5; see the replies below.

🟡 Suggestion: Reject empty funding rows before the Platform fetch

funding_inputs accepts an empty row list as Ok(empty) and leaves the refusal to fetch_inputs_with_nonce inside submit_top_up_from_addresses. On the external route Identity::fetch runs first, so a caller bug (zero rows) costs a network round-trip and a transport or proof failure masks it as IdentityLookupFailed instead of InvalidParameter; an unknown identity plus zero rows also reports IdentityNotFound before the malformed-argument error. Rejecting empty locally keeps local validation before remote IO and restores stable error precedence on both routes. The change is fail-fast only and does not alter the overflow or nonce behavior.

Suggested change
pub(crate) fn funding_inputs(
rows: impl IntoIterator<Item = (PlatformAddress, Credits)>,
) -> Result<BTreeMap<PlatformAddress, Credits>, PlatformWalletError> {
let mut inputs = BTreeMap::new();
for (address, credits) in rows {
let sum: &mut Credits = inputs.entry(address).or_default();
*sum = sum.checked_add(credits).ok_or_else(|| {
PlatformWalletError::InvalidParameter(format!(
"the funding amounts for {address:?} overflow"
))
})?;
}
Ok(inputs)
}
pub(crate) fn funding_inputs(
rows: impl IntoIterator<Item = (PlatformAddress, Credits)>,
) -> Result<BTreeMap<PlatformAddress, Credits>, PlatformWalletError> {
let mut inputs = BTreeMap::new();
for (address, credits) in rows {
let sum: &mut Credits = inputs.entry(address).or_default();
*sum = sum.checked_add(credits).ok_or_else(|| {
PlatformWalletError::InvalidParameter(format!(
"the funding amounts for {address:?} overflow"
))
})?;
}
if inputs.is_empty() {
return Err(PlatformWalletError::InvalidParameter(
"no funding rows were provided".to_string(),
));
}
Ok(inputs)
}

source: muse-spark-1.3-contributor (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, rust-quality, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 12b698e. funding_inputs refuses an empty row list as InvalidParameter("no funding rows were provided") before any network I/O on both routes; the now unreachable no_inputs_as_invalid_parameter promotion is removed. Test: should_report_empty_inputs_as_an_invalid_parameter_on_both_routes (unknown identity, unreachable Platform and a known identity, on the external route and the managed route; nothing is submitted).

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.

Resolved (re-reviewed at 8089a7e5): Fixed in the current head: funding_inputs rejects an empty row set before either route performs identity lookup or other network I/O.

Comment on lines +645 to +650
/// A result proof that does not show the input addresses' nonces this
/// top-up was signed with as used does not prove it executed: it is
/// reported as `PlatformWalletError::Sdk` holding
/// `dash_sdk::Error::StateTransitionResultUnconfirmed` (it may still
/// execute, so do not submit it again), and the addresses are not
/// updated from it; the next sync settles them.

@thepastaclaw thepastaclaw Nov 13, 2026 •

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.

✅ Resolved at 8089a7e5; see the replies below.

💬 Nitpick: Sync composite and FFI docs with the balance-growth condition

69ffa84 extended the unconfirmed predicate with the balance-growth condition but updated only the submit_top_up_from_addresses doc. The composite docs and both FFI export docs still describe the predicate as nonce-only, so a host integrator reading the FFI contract never learns that a proof with all nonces used but no balance growth is also code 20. The statements made are not false (sufficient conditions for 20) but the documented predicate is incomplete on a do-not-resubmit funds-safety contract. Copy the bind_to_submitted_nonces condition into those four doc paragraphs.

source: glm-5.3-flash (phase1-reviewer: general, rust-quality)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in bb2e0f2. Both composite docs and both FFI export docs now state the full condition: every input address at or past its submitted nonce and the proved identity balance above the balance the top-up started from, otherwise 20 with nothing reconciled. Since d41a053 that starting balance is a fresh Platform read taken before signing on both routes (the managed route no longer uses the identity manager's cached balance, which could turn an executed top-up into 20); the managed export doc also lists its new pre-sign codes 80 and 7.

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.

Resolved (re-reviewed at 8089a7e5): Fixed in the current head: both composite doc blocks and both address-top-up FFI doc blocks now state the submitted-nonce and balance-growth requirements, including the unconfirmed code-20 outcome.

@github-actions

Copy link
Copy Markdown
Contributor

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

romchornyi and others added 4 commits November 13, 2026 21:02
…efore any lookup

An empty row list was accepted and only refused later by the SDK, after
the external route's identity fetch, so it could surface as
IdentityLookupFailed or IdentityNotFound instead of InvalidParameter.
`funding_inputs` now refuses it on both routes before any network I/O,
which leaves the SDK's empty-input refusal unreachable from the top-up;
its promotion is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rm's balance

The managed route took the balance the top-up must grow from the identity
manager's cache. A cache above Platform's value (credits spent from
another device, not yet synced) made an executed top-up report
unconfirmed. The managed route now reads the identity's balance from
Platform before signing and binds the proof to it, as the external route
already does through its identity fetch. A failed read is
IdentityLookupFailed and an unknown identity IdentityNotFound, both
before anything is signed; the managed identity is still the one signed
for and reconciled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…firmed address top-up

The composite and FFI export docs described the unconfirmed outcome
(FFI 20) as nonces-only. A result stands only when its proof shows every
input address at or past its submitted nonce and the identity balance
above the balance the top-up started from, a fresh Platform read taken
before signing on both routes; otherwise it is 20 and nothing is
reconciled. The managed export also documents its new balance-read
errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…roof to its nonces

A competing transition signed by the same seam with the same nonces plus
an unrelated credit to the same identity still satisfies both checks;
closing that needs an execution-bound proof of this transition. The doc
also states that the wallet does not serialise address spends per input
address in-process: the address top-up holds only the shared lifecycle
read guard, and shield_guard covers shield-class operations only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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

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

The external and composite top-up paths correctly preserve the previously identified proof, FFI, error-mapping, and lifecycle fixes. One blocking lifecycle escape remains: the public IdentityWallet managed top-up can bypass the composite generation guard, and code 80 documentation does not state that the managed export can also return it. Rust workspace tests are still in progress; no completed code-check failure is reported.

Step back: this PR keeps drawing new blockers

This is review round 7, and the PR has drawn 9 blocking findings so far. The review of 46428085 named this cause and the decision that would settle it; this round found 1 more finding(s) from the same place. Fixing them one at a time is not converging, so this review asks for that decision before another round.

1. No operation-scoped lifetime owner (1 new in this round, 4 earlier finding(s))

The address top-up has no single operation owner at the API boundary. PlatformWallet::top_up_identity_with takes a generation guard only through the composite path, while public IdentityWallet::top_up_from_addresses remains reachable through PlatformWallet::identity() and bypasses it; Swift and FFI also pass raw handles whose owners need separate lifetime fences. Each patch therefore protects the route that exposed the latest race while another entry point or owner can still outlive the lookup, signing, broadcast, confirmation, and reconciliation operation.

In this round: Guard the public IdentityWallet managed top-up against wallet teardown

Requested decision (redesign the component): Redesign the address-top-up boundary around one operation-scoped lease. The lease must retain the Swift wallet and signer owners and hold one Rust wallet generation across lookup, signing, broadcast, confirmation, and reconciliation. Route both managed and external APIs—including PlatformWallet::identity().top_up_from_addresses—through that same path, rather than adding another per-entry-point fence.

Automatic re-review is paused until then: later pushes keep this review's verdict and are not reviewed on their own. Comment @thepastaclaw review once the decision is made: that resumes automatic re-review, and reviews the current commit if it has not been reviewed.

🔴 1 blocking

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: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); 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 platform-wallet top-up flows that builds and signs identity funding transitions and broadcasts funds, directly affecting funds movement and key handling in top_up_from_addresses and its external counterpart.
  • 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)
  • Code unchanged since the last final review (46428085): 1 new nitpick(s) dropped
  • 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
Before fixing anything, read the review's "Step back" section. This PR keeps drawing new blocking findings from the same underlying causes, and patching the findings below one at a time is not converging. The review asks for this decision first (redesign the component): Redesign the address-top-up boundary around one operation-scoped lease. The lease must retain the Swift wallet and signer owners and hold one Rust wallet generation across lookup, signing, broadcast, confirmation, and reconciliation. Route both managed and external APIs—including `PlatformWallet::identity().top_up_from_addresses`—through that same path, rather than adding another per-entry-point fence. Raise that decision with the PR's author or maintainer instead of only patching; if it is theirs to make, stop and ask them.

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/identity/network/top_up_from_addresses.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:74-102: Guard the public IdentityWallet managed top-up against wallet teardown
  `PlatformWallet::top_up_from_addresses` acquires the generation guard only in the composite, while `PlatformWallet::identity()` remains public and exposes this `IdentityWallet::top_up_from_addresses` method directly. A caller retaining that identity handle can pass the manager lookup, then suspend during the Platform read, signing, broadcast, or result processing while the wallet is removed or recreated under the same ID. The direct method can still broadcast using stale state and subsequently fail its manager write or update the replacement entry. Since this PR changes the managed top-up implementation and documents lifecycle fencing for that operation, the public lower-level route remains an in-scope funds-safety escape. Split the operation into an internal already-guarded implementation used by the composite and a public identity-side entry point that acquires the guard, or make the direct method non-public; add retained-handle tests covering removal, same-ID recreation, and removal during signing.

Comment on lines +74 to +102
@@ -73,20 +96,26 @@ impl IdentityWallet {
.map(|m| m.identity.clone())
.ok_or(PlatformWalletError::IdentityNotFound(*identity_id))?
};

let (address_infos, mut new_balance, metadata) = identity
.top_up_from_addresses_with_metadata(&self.sdk, inputs, address_signer, settings)
// The cached balance can sit above Platform's (credits spent from
// another device, not yet synced): growth is measured against
// Platform's own balance, read before anything is signed.
let balance_before = IdentityBalance::fetch(&self.sdk, *identity_id)

@thepastaclaw thepastaclaw Nov 13, 2026 •

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.

✅ Resolved at 2ce86e84; see the replies below.

🔴 Blocking: Guard the public IdentityWallet managed top-up against wallet teardown

PlatformWallet::top_up_from_addresses acquires the generation guard only in the composite, while PlatformWallet::identity() remains public and exposes this IdentityWallet::top_up_from_addresses method directly. A caller retaining that identity handle can pass the manager lookup, then suspend during the Platform read, signing, broadcast, or result processing while the wallet is removed or recreated under the same ID. The direct method can still broadcast using stale state and subsequently fail its manager write or update the replacement entry. Since this PR changes the managed top-up implementation and documents lifecycle fencing for that operation, the public lower-level route remains an in-scope funds-safety escape. Split the operation into an internal already-guarded implementation used by the composite and a public identity-side entry point that acquires the guard, or make the direct method non-public; add retained-handle tests covering removal, same-ID recreation, and removal during signing.

source: gpt-6.1-sol (phase2-reviewer: general)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 2ce86e8. IdentityWallet::top_up_from_addresses is now pub(crate), as the external route's identity-side method already is, so the only public route is PlatformWallet::top_up_from_addresses, which holds the lifecycle gate (tested on both routes); a retained identity() handle can no longer reach it.

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.

Resolved (re-reviewed at 2ce86e84): The managed identity-side method is now pub(crate), so retained identity handles cannot bypass the lifecycle-gated public composite route.

…cycle gate

`IdentityWallet::top_up_from_addresses` was public and reachable through
`PlatformWallet::identity()`, so a retained identity handle could spend
around the wallet-generation gate the composite holds. It is now
crate-private, as the external route's identity-side method already is;
callers outside the crate use `PlatformWallet::top_up_from_addresses`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Your move: coderabbitai left review threads unresolved; resolve them; thepastaclaw left review threads unresolved; resolve them.
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.

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

The current head preserves the major lifecycle, FFI, and confirmation-safety fixes, and the Rust, Swift, and Kotlin code checks reported for this revision succeeded. Four in-scope suggestions remain: distinguish an absent managed balance from an unknown managed identity, document code 80 for managed calls, preserve retryability in Swift recovery handling, and test confirmed reconciliation through the public external route. The execution-bound confirmation limitation remains intentionally deferred under #4270 rather than re-raised as a new finding.

🟡 2 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.

Still open from earlier rounds (1)

  • 🟡 Suggestion: Exercise successful external top-up reconciliation — packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:657-661 (thread)
Follow-up candidates (optional) (2)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: Document code 80 for managed top-ups as well
packages/rs-platform-wallet-ffi/src/error.rs:771-778

The managed route now maps a failed IdentityBalance::fetch to PlatformWalletError::IdentityLookupFailed, and the blanket FFI conversion returns code 80 for it. This rustdoc currently says code 80 is returned only by the external top-up; ERROR_CODE_REGISTRY.md repeats the same omission. Host integrators may therefore miss that the retryable, not-sent result also applies to the managed export. Update both public descriptions to cover managed and external address-funded identity top-ups.

    /// is; a host need not treat it as possibly delivered. Returned by the
    /// managed and external identity top-ups from Platform addresses.

source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)

🟡 Suggestion: Preserve retryability for identity lookup failures in Swift recovery handling
packages/swift-sdk/Sources/SwiftDashSDK/Utils/ErrorHandling.swift:326-363

The FFI maps IdentityLookupFailed as a pre-signing failure that is safe to retry, and the Kotlin mapping preserves that classification. Swift's ErrorCategorizer does not recognize identityLookupFailed as a network or timeout error, so toUserFacingError falls through to .unknown with isRetryable == false. Swift callers using the standard recovery helper can therefore suppress a retry even though nothing was signed or broadcast. Add an explicit retryable classification for .identityLookupFailed.

        if let walletError = error as? PlatformWalletError,
           case .identityLookupFailed = walletError {
            return UserFacingError(
                title: ErrorCategory.network.rawValue,
                message: ErrorFormatter.userFriendlyMessage(from: walletError),
                category: .network,
                recoverySuggestion: ErrorRecovery.suggestion(for: .network),
                underlyingError: String(describing: walletError),
                isRetryable: true
            )
        }


source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)

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: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 6: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 11: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 12: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); 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 change to platform-wallet top-up submission, identity balance confirmation, address reconciliation, signing, and broadcast paths that directly moves funds and handles cryptographic signatures, particularly in top_up_external_from_addresses and the shared submission helper.
  • 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 final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Code unchanged since the last final review (8089a7e5): 2 new suggestion(s) listed as follow-up candidates, not posted inline
  • 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, 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-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:107-113: Preserve the managed identity balance-unavailable error
  The managed route has already established that this identity belongs to the wallet, then queries only `IdentityBalance`. When Platform returns `None`, this is the same balance-unavailable condition handled by `refresh_identity_balance`, not evidence that the managed identity is absent. Mapping it to `IdentityNotFound` causes a newly registered or temporarily lagging managed identity to appear permanently missing and loses the retryable FFI code 58. Keep `IdentityNotFound` for the external full-identity lookup and map an absent managed balance to `IdentityBalanceUnavailable`.

In `packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:657-661: Exercise successful external top-up reconciliation
  (carried; thread: https://github.com/dashpay/platform/pull/5860#discussion_r4538714368)

Comment on lines +107 to +113
let balance_before = IdentityBalance::fetch(&self.sdk, *identity_id)
.await
.map_err(|e| {
preserve_signer_key_unavailable_or(e, |e| {
promote_address_nonce_error(&e).unwrap_or_else(|| {
PlatformWalletError::InvalidIdentityData(format!(
"Failed to top up identity from addresses: {}",
e
))
})
})
})?;
.map_err(|source| PlatformWalletError::IdentityLookupFailed {
identity_id: *identity_id,
source,
})?
.ok_or(PlatformWalletError::IdentityNotFound(*identity_id))?;

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.

🟡 Suggestion: Preserve the managed identity balance-unavailable error

The managed route has already established that this identity belongs to the wallet, then queries only IdentityBalance. When Platform returns None, this is the same balance-unavailable condition handled by refresh_identity_balance, not evidence that the managed identity is absent. Mapping it to IdentityNotFound causes a newly registered or temporarily lagging managed identity to appear permanently missing and loses the retryable FFI code 58. Keep IdentityNotFound for the external full-identity lookup and map an absent managed balance to IdentityBalanceUnavailable.

Suggested change
let balance_before = IdentityBalance::fetch(&self.sdk, *identity_id)
.await
.map_err(|e| {
preserve_signer_key_unavailable_or(e, |e| {
promote_address_nonce_error(&e).unwrap_or_else(|| {
PlatformWalletError::InvalidIdentityData(format!(
"Failed to top up identity from addresses: {}",
e
))
})
})
})?;
.map_err(|source| PlatformWalletError::IdentityLookupFailed {
identity_id: *identity_id,
source,
})?
.ok_or(PlatformWalletError::IdentityNotFound(*identity_id))?;
let balance_before = IdentityBalance::fetch(&self.sdk, *identity_id)
.await
.map_err(|source| PlatformWalletError::IdentityLookupFailed {
identity_id: *identity_id,
source,
})?
.ok_or(PlatformWalletError::IdentityBalanceUnavailable(*identity_id))?;

source: gpt-6.1-sol (phase2-reviewer: architecture-layering)

@github-actions

Copy link
Copy Markdown
Contributor

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

HashEngineering added a commit to dashpay/dash-wallet that referenced this pull request Nov 13, 2026
…tity

int39 adds IdentityCredits.topUpExternalIdentityFromAddresses (a Kotlin
binding of dashpay/platform#5860). Platform -> Identity now uses
topUpFromAddresses for an identity the SDK wallet manages and the external
top-up for any other; an unreadable managed set is NotSent. A missing
identity fails DashSdkError.NotFound before signing, read as NotSent.
Core -> someone else's identity stays unsupported.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
HashEngineering added a commit that referenced this pull request Nov 16, 2026
…irmed outcomes

#5860 now reports a failed identity read as IdentityLookupFailed (80,
retryable, nothing sent) and an unproved result as
TransactionBroadcastUnconfirmed (20, do not resubmit), alongside
NotFound (7). The KDoc says which is which, and the test pins each
code's mapping, including that 80 is retryable.

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

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants