Repository navigation
feat(platform-wallet): one address top-up for any identity - #5929
Conversation
…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 <[email protected]>
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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…r of the shielded spend plan codes The failed identity lookup code was 77, which the shielded spend plan PR already uses (77 plan changed, 78 too many notes, 79 withdrawal amount out of range). Renumber it to 80 in the FFI enum, the registry (next free is now 81), the Swift result code and the Kotlin error mapping, and update the Rust, Swift and Kotlin pin tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… unbound state snapshot The result proof of an identity top-up from addresses authenticates only the identity and address state at the proof's block, not that this transition executed. The wallet now signs with nonces it looked up itself and keeps the result only when the proof shows every input address at or past its submitted nonce. A snapshot from before is reported as the SDK's unconfirmed outcome, with nothing reconciled from it, on both the managed and the external top-up. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
… 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 <[email protected]>
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 <[email protected]>
… 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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
…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 <[email protected]>
Add `PlatformWallet::top_up_identity_from_addresses`: it fetches the identity from Platform whatever its owner, writes the proved balance back when the identity manager holds the identity, and never adds an identity to the manager. The host no longer decides whether an identity is its own; a managed identity topped up through the external route no longer keeps a stale cached balance until the next sync. The lifecycle gate, liveness check, nonce binding, balance-growth check and reconciliation at the proof's height are unchanged. The growth baseline is the balance in the fetched identity, as on the external route; the managed route read the same value through `IdentityBalance`. Exposed as `platform_wallet_top_up_identity_from_addresses_with_signer`, `ManagedPlatformWallet.topUpIdentityFromAddresses` (Swift) and `IdentityCredits.topUpIdentityFromAddresses` (Kotlin, new JNI bridge `CreditsNative.topUpIdentityFromAddresses`). The example apps use it. Deprecated, still working on top of the new operation: - `PlatformWallet::top_up_from_addresses` (`#[deprecated]`) and its export, Swift and Kotlin methods: still refuse an identity the manager does not hold with IdentityNotFound (7) before Platform is asked. - `PlatformWallet::top_up_external_identity_from_addresses` (`#[deprecated]`) and its export and Swift method: now the same call. Funding inputs are still chosen by the host (issue item 2 is later). Refs #5925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…signing The address top-up held the wallet generation's payment gate from before the identity fetch to the end of reconciliation, across the host's signing prompt. That was agreed on #5860 to close a window in which a retained handle could broadcast after removal. It contradicts the gate's own contract (`WalletGeneration::teardown_guard`): an operation awaiting an external signer takes the gate only after the signature returns, so an open signing prompt cannot stall teardown. With the wide gate, removing a wallet waited for whatever the host's signer did, and the write-preferring lock queued every later payment of that wallet behind the removal. The top-up now signs through `GatedAddressSigner`, as the contact request send signs through its `GatedSigner`: when the last input's witness returns, it takes the gate (`payment_guard_owned`) and checks under it that the handle's generation is still the registered one. The gate is then held through the broadcast, the result wait, the managed balance write-back and the address reconciliation. The transition needs every witness before it can be broadcast, so nothing reaches the network without the gate. A wallet removed or re-created while the host signed is refused there with WalletRemovedBeforeSend and nothing is broadcast; the window #5860 closed stays closed, because the liveness check and the broadcast are still one section under the gate. A handle already stale at the start is still refused before anything is fetched or signed (an ungated point-in-time check). Replaces `should_hold_a_wallets_removal_until_its_top_up_returns` with tests of the new contract: a removal during signing completes without waiting and the top-up then abandons before broadcast (also for a wallet re-created meanwhile), and a removal after the last signature waits until the top-up lets the gate go. This reverses the #5860 agreement, so it is a separate commit that can be dropped if maintainers prefer the wide gate. Refs #5925 Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
🔍 Review in progress (commit 8f91488) · live progress |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The Rust routing and lifecycle-gate changes are generally sound, and the supplied CI snapshot contains no failed code checks. One blocking Kotlin cancellation path can hide a completed native top-up and permit a duplicate retry; several lower-severity API, documentation, lifecycle-proof, and test-coverage issues also remain.
🔴 1 blocking | 🟡 6 suggestion(s) | 💬 1 nitpick(s)
2 finding(s) not shown inline (the lines are not part of this PR's diff)
🟡 Suggestion: Add compiler deprecation annotations to the old top-up wrappers
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:794-838
The Rust compatibility routes are marked with #[deprecated], but Swift's topUpFromAddresses and topUpExternalIdentityFromAddresses only contain a **Deprecated:** doc comment. The corresponding Kotlin IdentityCredits.topUpFromAddresses method likewise lacks @Deprecated. Consumers therefore receive no compiler warning or migration guidance even though the PR introduces topUpIdentityFromAddresses as the single replacement route. Add @available(*, deprecated, message: ...) to the Swift methods and @Deprecated(...) to the Kotlin method, updating internal dispatch-test call sites as needed.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
💬 Nitpick: Document the new JNI top-up export
packages/rs-unified-sdk-jni/src/credits.rs:9-18
The module-level bridge list still documents only platform_wallet_top_up_from_addresses_with_signer as the ID-06 entry point, while the primary export is now platform_wallet_top_up_identity_from_addresses_with_signer. Update the list to document the new any-identity export and identify the old export as the deprecated managed-only variant.
//! - [`platform_wallet_top_up_identity_from_addresses_with_signer`] — top up any
//! identity from Platform-address inputs (ID-06).
//! - [`platform_wallet_top_up_from_addresses_with_signer`] — deprecated managed-only
//! variant of the same top-up (ID-06).
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
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:
criticalbygpt-6.1-sol(effort low) — This is a large, intricate change to funds movement and signing/lifecycle safety in PlatformWallet::top_up_identity_from_addresses and GatedAddressSigner, including broadcast gating and balance reconciliation. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/credits/IdentityCredits.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/credits/IdentityCredits.kt:238-245: Preserve a completed native top-up when the coroutine is cancelled
This new payment method uses `gate.op`, which runs the synchronous JNI call through `withContext(Dispatchers.IO)`. If cancellation occurs after `addressTopUpNative.call` has broadcast and completed but before the dispatcher handoff returns the value, `withContext` can throw `CancellationException` and discard the completed balance. The caller cannot distinguish a completed top-up from an unsent one and may retry with newly resolved address nonces, crediting the identity twice. Use `gate.opReturningCompletedResult` here, as the neighboring money-moving Kotlin APIs already do, and add a cancellation-after-native-completion regression test.
In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift`:
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/ManagedPlatformWallet.swift:794-838: Add compiler deprecation annotations to the old top-up wrappers
The Rust compatibility routes are marked with `#[deprecated]`, but Swift's `topUpFromAddresses` and `topUpExternalIdentityFromAddresses` only contain a `**Deprecated:**` doc comment. The corresponding Kotlin `IdentityCredits.topUpFromAddresses` method likewise lacks `@Deprecated`. Consumers therefore receive no compiler warning or migration guidance even though the PR introduces `topUpIdentityFromAddresses` as the single replacement route. Add `@available(*, deprecated, message: ...)` to the Swift methods and `@Deprecated(...)` to the Kotlin method, updating internal dispatch-test call sites as needed.
In `packages/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:717-731: Recheck wallet liveness before prompting the host signer
`top_up_identity` performs its only ungated `is_current_generation` check before the Platform identity fetch. If the wallet is removed during that fetch or the subsequent nonce lookup, the operation still reaches the host signer and only fails when the last signature acquires the lifecycle gate. No funds are broadcast, but the user receives a needless signing prompt for an operation that is already known to be stale. Repeat the cheap current-generation check after the awaited pre-signing reads, ideally immediately before invoking the host signer; retain the gated check as the decisive race-safe check.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:722-755: Make the lifecycle gate a requirement of top-up bookkeeping
The production path stores the returned guard in `_lifecycle` and relies on it remaining alive while `record_top_up` writes the managed balance and reconciles addresses, but `record_top_up` accepts no guard parameter. Because it is `pub(crate)`, a future caller can invoke it with a stale handle after the wallet id has been re-created, causing the manager lookup to write into the replacement generation. Thread a reference to the owned lifecycle guard through `record_top_up` and `record_top_up_balance` so the required gate is enforced by the API rather than by documentation and variable scope.
In `packages/rs-unified-sdk-jni/src/credits.rs`:
- [NITPICK] packages/rs-unified-sdk-jni/src/credits.rs:9-18: Document the new JNI top-up export
The module-level bridge list still documents only `platform_wallet_top_up_from_addresses_with_signer` as the ID-06 entry point, while the primary export is now `platform_wallet_top_up_identity_from_addresses_with_signer`. Update the list to document the new any-identity export and identify the old export as the deprecated managed-only variant.
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:98-118: Replace the boolean top-up scope with a typed route
`top_up_identity_from_addresses` uses `managed_only: bool`, and the public methods pass literal `false` and `true` at `platform_wallet.rs:640` and `platform_wallet.rs:669`. Swapping those literals would silently invert the authorization behavior without compiler help. The FFI layer already models this distinction with `AddressTopUpRoute`; use an equivalent Rust enum such as `TopUpScope::AnyIdentity` and `TopUpScope::ManagedOnly` in the wallet core.
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:230-329: Share the lifecycle-gated signer state machine
This introduces a second lifecycle-gated signer state machine alongside `GatedSigner` in `contact_requests.rs`. Both implementations allow host signing without the teardown gate, acquire the generation read guard after the final signature, check generation identity under the manager lock, and retain the guard through publication and bookkeeping. Keeping these policies duplicated in separate network modules allows a future lock-ordering or stale-generation fix to update one payment path while leaving the other inconsistent. Extract the shared gating/finalization behavior into a common Rust wallet helper while retaining address- and identity-key-specific signing adapters.
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:684-735: Test that the returned gate spans bookkeeping
The lifecycle test holds the gate only until `gated.into_gate()` is immediately dropped, while the bookkeeping seam test calls `record_top_up` without any gate. There is no regression test proving that the production guard remains held across the manager write and address reconciliation, so dropping `_lifecycle` before bookkeeping would not be detected. Add a test that holds the returned gate while running `record_top_up` and verifies concurrent wallet removal remains blocked until bookkeeping completes.
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.
- Move account-scoped funding input selection into Rust — The Swift and Kotlin example flows still enumerate wallet addresses and greedily select funding rows in
TopUpIdentityView.buildInputsandTopUpIdentityScreen.packInputs. This leaves account selection and input-selection behavior host-specific even though the new API centralizes identity ownership and top-up orchestration in Rust.- Follow-up: Open and link a follow-up issue or PR for Rust-owned account-scoped funding selection, then route both mobile examples through that operation.
…ancelled IdentityCredits.topUpIdentityFromAddresses ran under gate.op, so a top-up that finished natively after its caller was cancelled had its balance dropped and the caller could not tell the credits moved. Run it under gate.opReturningCompletedResult, like the wallet's other credit-moving calls, and pin that with a regression test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…keeping record_top_up and record_top_up_balance now take the held lifecycle guard, so the identity-manager write and the address reconciliation cannot be called without it. The test seam acquires it the way production does. Mark the managed-only address top-up wrappers deprecated in favour of topUpIdentityFromAddresses (Swift topUpFromAddresses and topUpExternalIdentityFromAddresses, Kotlin IdentityCredits and CreditsNative topUpFromAddresses), and list platform_wallet_top_up_identity_from_addresses_with_signer in the JNI credits module doc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Replies to the findings shown only in the review body:
|
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The any-identity address top-up is consistently wired through the Rust wallet, FFI, JNI, Swift, and Kotlin layers, and the lifecycle guard is now enforced through bookkeeping. One blocking cancellation issue remains in the deprecated Kotlin managed-only route, along with two non-blocking Rust API/UX concerns. CI shows the Kotlin build and tests passing; the review check is still in progress.
🔴 1 blocking | 🟡 2 suggestion(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Deprecated Kotlin top-up still drops a completed result on cancellation
packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/credits/IdentityCredits.kt:266-280
The deprecated topUpFromAddresses route still uses gate.op, while the new any-identity route uses opReturningCompletedResult. If the synchronous JNI call broadcasts and completes before coroutine cancellation is observed during the withContext(Dispatchers.IO) handoff, gate.op can throw CancellationException and discard the completed balance. The caller cannot distinguish a completed top-up from an unsent one and may retry with newly resolved nonces, potentially crediting the identity twice. This route is explicitly retained and modified by this PR as the deprecated compatibility path, so it should preserve completed results under cancellation as well.
suspend fun topUpFromAddresses(
walletHandle: Long,
identityId: ByteArray,
inputs: List<FundingInput>,
signerHandle: Long,
): Long = gate.opReturningCompletedResult {
mapNativeErrors {
CreditsNative.topUpFromAddresses(
walletHandle,
identityId,
FundingInput.encode(inputs),
signerHandle,
)
}
}
source: muse-spark-1.3-contributor (phase1-reviewer: general)
Still open from earlier rounds (2)
- 🟡 Suggestion: Replace the boolean top-up scope with a typed route —
packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:98-118(thread) - 🟡 Suggestion: Recheck wallet liveness before prompting the host signer —
packages/rs-platform-wallet/src/wallet/platform_wallet.rs:714-731(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:
criticalbygpt-6.1-sol(effort low) — This is a large, intricate change to identity credit top-up transaction signing, broadcast, lifecycle gating, and balance write-back inPlatformWallet::top_up_identity_from_addressesandGatedAddressSigner, directly affecting funds movement and key-handling boundaries. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-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; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— ffi-engineer (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/credits/IdentityCredits.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/credits/IdentityCredits.kt:266-280: Deprecated Kotlin top-up still drops a completed result on cancellation
The deprecated `topUpFromAddresses` route still uses `gate.op`, while the new any-identity route uses `opReturningCompletedResult`. If the synchronous JNI call broadcasts and completes before coroutine cancellation is observed during the `withContext(Dispatchers.IO)` handoff, `gate.op` can throw `CancellationException` and discard the completed balance. The caller cannot distinguish a completed top-up from an unsent one and may retry with newly resolved nonces, potentially crediting the identity twice. This route is explicitly retained and modified by this PR as the deprecated compatibility path, so it should preserve completed results under cancellation as well.
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:98-118: Replace the boolean top-up scope with a typed route
(carried; thread: https://github.com/dashpay/platform/pull/5929#discussion_r4578944933)
In `packages/rs-platform-wallet/src/wallet/platform_wallet.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/platform_wallet.rs:714-731: Recheck wallet liveness before prompting the host signer
(carried; thread: https://github.com/dashpay/platform/pull/5929#discussion_r4578944929)
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.
- Bind address top-up completion to the exact transition — The existing nonce-and-balance heuristic can accept a result when another transition consumes the same address nonces and unrelated credits raise the target identity balance. That can make an unexecuted top-up appear complete, although this limitation predates the reviewed range and is documented in the current implementation.
- Follow-up: Create a follow-up PR adding an execution-bound proof or result binding for address-funded top-ups.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Reject out-of-range Kotlin address types before u8 encoding (not inline). Fixed in 620392e: every Kotlin funding row that reaches the top-up bridges is a |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
⚠️ DEGRADED — Re-review — Final validation — Phase 2 only (queue backlog)
⚠️ DEGRADED review. The primary review models were unavailable (gpt-6.2-solunavailable: All credentials for model gpt-6.2-sol are cooling down (last error: usage_limit_reached: The usage limit has been reache), so this review ran on stand-in models:gpt-5.6-luna→muse-spark-1.3-contributor,gpt-5.6-sol→muse-spark-1.3-contributor,gpt-5.6-terra→muse-spark-1.3-contributor,gpt-6-astra→muse-spark-1.3-contributor,gpt-6.1-sol→muse-spark-1.3-contributor,gpt-6.2-astra→muse-spark-1.3-contributor,gpt-6.2-sol→muse-spark-1.3-contributor. Both review phases and the independent verifiers still ran, but on weaker models, with Phase 1 capped athigheffort. Treat the verdict as provisional; a full-strength re-review will run on the next push once the primary models are back.
Nothing blocks: no blocking finding stands on this head.
New on this head: This head adds two commits since 661ce18: a Kotlin FundingInput addressType 0..255 guard with edge tests, and a one-line ERROR_CODE_REGISTRY row 69 wording restore. CI shows Rust workspace tests in progress and Kotlin emulator queued with no failed checks reported.
🟡 4 suggestion(s)
Still open from earlier rounds (4)
- 🟡 Suggestion: Bound wallet removal while the replacement test holds the signer —
packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:883-887(thread) - 🟡 Suggestion: Distinguish the managed and any-identity routes at the C boundary —
packages/rs-platform-wallet-ffi/src/identity_top_up/external_identity_tests.rs:267-274(thread) - 🟡 Suggestion: Fetch the proved balance without fetching every recipient key —
packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses.rs:131-136(thread) - 🟡 Suggestion: Make the liveness regression test remove the wallet after the reads —
packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:545-576(thread)
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: rust-quality); reviewer 5: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: phase2-reviewer, role: security-auditor); final verifier: muse-spark-1.3-contributor (standing in for gpt-6.2-sol) (agent: sol-verifier, role: final-verifier)
- Degraded mode:
gpt-6.2-solunavailable: All credentials for model gpt-6.2-sol are cooling down (last error: usage_limit_reached: The usage limit has been reache (detected by probe, since 2026-11-23T09:07:27Z); stand-insgpt-5.6-luna→muse-spark-1.3-contributor,gpt-5.6-sol→muse-spark-1.3-contributor,gpt-5.6-terra→muse-spark-1.3-contributor,gpt-6-astra→muse-spark-1.3-contributor,gpt-6.1-sol→muse-spark-1.3-contributor,gpt-6.2-astra→muse-spark-1.3-contributor,gpt-6.2-sol→muse-spark-1.3-contributor; Phase 1 effort capped athigh - Triage:
normalbymuse-spark-1.3-contributor(standing in forgpt-6.2-sol) (effort low) — Large cross-cutting wallet/FFI/SDK unification that reuses the existing signing/broadcast lifecycle unchanged rather than modifying consensus, coin selection, cryptography, or serialization logic. - Phase 1 reviewers: not run (skipped for throughput: 19 PRs queued, above the 10 limit)
- Fresh verifier:
muse-spark-1.3-contributor(standing in forgpt-6.2-sol) — final-verifier; agentsol-verifier - Phase 2 reviewers:
muse-spark-1.3-contributor(standing in forgpt-6.2-sol) — general (completed, effort high); agentphase2-reviewer,muse-spark-1.3-contributor(standing in forgpt-6.2-sol) — architecture-layering (completed, effort high); agentphase2-reviewer,muse-spark-1.3-contributor(standing in forgpt-6.2-sol) — ffi-engineer (completed, effort high); agentphase2-reviewer,muse-spark-1.3-contributor(standing in forgpt-6.2-sol) — rust-quality (completed, effort high); agentphase2-reviewer,muse-spark-1.3-contributor(standing in forgpt-6.2-sol) — security-auditor (completed, effort high); agentphase2-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/external_identity_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:883-887: Bound wallet removal while the replacement test holds the signer
(carried; thread: https://github.com/dashpay/platform/pull/5929#discussion_r4638084415)
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/top_up_from_addresses/external_identity_tests.rs:545-576: Make the liveness regression test remove the wallet after the reads
(carried; thread: https://github.com/dashpay/platform/pull/5929#discussion_r4580715823)
In `packages/rs-platform-wallet-ffi/src/identity_top_up/external_identity_tests.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/identity_top_up/external_identity_tests.rs:267-274: Distinguish the managed and any-identity routes at the C boundary
(carried; thread: https://github.com/dashpay/platform/pull/5929#discussion_r4638084408)
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:131-136: Fetch the proved balance without fetching every recipient key
(carried; thread: https://github.com/dashpay/platform/pull/5929#discussion_r4638084395)
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.
- Remaining Kotlin encoders still narrow addressType without a range check — Outside this diff, encodeCreditOutputs and encodeRecipients in ManagedPlatformWallet.kt still do dos.writeByte(addressType) without the 0..255 require added to FundingInput and encodeWithdrawalInputs, so an out-of-range Int would silently truncate to a different script type.
- Follow-up: File a follow-up to add the same 0..255 require or a shared checked encoder to encodeCreditOutputs and encodeRecipients, with tests pinning rejection of -1/256/257.
|
Bots are done — your move: post |
HashEngineering
left a comment
There was a problem hiding this comment.
Approving for kotlin-sdk.
Non-blocking notes:
- The deprecated
topUpFromAddressesKDoc says the unmanaged refusal isIdentityNotFound, but Kotlin surfaces code 7 asDashSdkError.NotFound. topUpIdentityFromAddressesdoesn't list its outcomes yet: 7NotFound, 80IdentityLookupFailed, 20TransactionBroadcastUnconfirmed(may have executed; do not resubmit), 98PlatformWallet.NotFound. It also doesn't say that the calling coroutine stays cancelled afteropReturningCompletedResultreturns a balance.
Plan for #5906: once this merges, it already covers the Kotlin top-up of someone else's identity, so I'll rescope #5906 instead of landing topUpExternalIdentityFromAddresses. It will drop that method and its JNI bridge, and move its outcome KDoc, error-mapping tests and the FfiSmokeTest JNI-binding check onto topUpIdentityFromAddresses. dash-wallet will call topUpIdentityFromAddresses for any identity.
|
/self-reviewed |
|
Policy satisfied — this can merge. |
identityNotFound is also the reason for an Identity-source send whose identity the wallet does not hold, where Platform is never asked, so it now reads "This identity could not be found". ADR-0045 (Proposed) records that the send pays the holder's own identity with the same top-up for any identity since dashpay/platform#5929; a test comment still described the old split. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ilure Moves ErrorShieldedIdentityCreateInputsConsumed from 77 to 81: #5865 holds 77-79 and #5929 took 80. The scoped broadcast tracker takes the base's spend_broadcast_dispatches(sdk, None) and single_dispatch_settings. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The send picked the managed top-up for the holder's Current identity and the external one for any other. The managed one answers an identity Platform does not show yet with identityBalanceUnavailable (58), which Send reads as in progress although nothing was signed. The send now takes the SDK's top-up for any identity (`topUpIdentityFromAddresses`, dashpay/platform#5929) for every identity: Platform reads the identity before signing, and one it does not show is identityNotFound, not sent, with Retry. The Top Up sheet keeps the managed top-up. identityNotFound now says "Platform could not find this identity" instead of "not found in your wallet", which was wrong for someone else's identity. The top-up compatibility harness implements the SDK's new call and tests that the sheet and the send take different top-ups; its funding policy fakes plan inputs instead of refusing. Co-Authored-By: Claude Opus 5.5 <[email protected]>
identityNotFound is also the reason for an Identity-source send whose identity the wallet does not hold, where Platform is never asked, so it now reads "This identity could not be found". ADR-0045 (Proposed) records that the send pays the holder's own identity with the same top-up for any identity since dashpay/platform#5929; a test comment still described the old split. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeps #5929's single address top-up export in place of this branch's copy of the external one, adds this branch's callers to registry row 80, and renames the Core route's balance write-back to record_core_top_up_balance beside #5929's record_top_up_balance. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in v5.2-dev (#5929) and PR A's review fixes. Co-Authored-By: Claude Opus 5.5 <[email protected]> # Conflicts: # packages/kotlin-sdk/PARITY_SUMMARY.md # packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/credits/IdentityCredits.kt
…e does not fit a byte CreditOutput and FundRecipient are written to their native blobs with DataOutputStream.writeByte, which keeps only the low 8 bits, so an addressType of 256 reached Rust as 0 (P2PKH) and the credits went to an address the caller did not name. Both now refuse a value outside 0..255 when constructed, as FundingInput and the withdrawal input already do. Which byte values are supported stays Rust's decision. Raised as an out-of-scope follow-up in the review of #5929. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e does not fit a byte CreditOutput and FundRecipient are written to their native blobs with DataOutputStream.writeByte, which keeps only the low 8 bits, so an addressType of 256 reached Rust as 0 (P2PKH) and the credits went to an address the caller did not name. Both now refuse a value outside 0..255 when constructed, as FundingInput and the withdrawal input already do. Which byte values are supported stays Rust's decision. Raised as an out-of-scope follow-up in the review of #5929. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Issue being fixed or feature implemented
Refs #5925 (this PR does items 1 and 3; item 2, Rust selecting the funding inputs, stays open in that issue for a follow-up). Based on
v5.2-dev, which now holds #5860 (e451c35); this PR is no longer stacked.Hosts had to choose between two top-up exports (managed vs any other identity), so each app decided "is this identity mine?" on its own, and a managed identity topped up through the external route kept a stale cached balance until the next sync.
What was done?
One address top-up for any identity
PlatformWallet::top_up_identity_from_addresses: always fetches the identity from Platform; after a confirmed proof,record_top_up_balancewrites the balance back only when the identity manager holds that id. No identity is ever added to the manager.generation_payment_guard) and a second liveness check before the broadcast, held through the result wait, the balance write-back and the reconciliation. A wallet removed or re-created before or during signing isWalletRemovedBeforeSend(FFI 98), nothing broadcast. Nonce binding, the balance-growth check against the balance read from Platform before signing, the oversized pre-check, the delivery rules (20 for anything possibly delivered, never 21) andfunding_inputsvalidation are feat(platform-wallet)!: top up an identity the wallet does not manage from Platform addresses #5860's, shared by every route.platform_wallet_top_up_identity_from_addresses_with_signer, SwiftManagedPlatformWallet.topUpIdentityFromAddresses, KotlinIdentityCredits.topUpIdentityFromAddresses(JNICreditsNative.topUpIdentityFromAddresses). A Kotlin caller cancelled after the native top-up completed still gets its balance (opReturningCompletedResult).top_up_from_addresses,top_up_external_identity_from_addresses, their FFI exports, SwifttopUpFromAddresses/topUpExternalIdentityFromAddresses, KotlintopUpFromAddresses. Their documented errors are feat(platform-wallet)!: top up an identity the wallet does not manage from Platform addresses #5860's: the managed route refuses an identity the manager does not hold (7) before Platform is asked, a failed lookup is 80, and Platform returning no identity for the managed one is 58; the external route is now the same call as the new one. The example apps call the new method.ERROR_CODE_REGISTRYrows 58 and 80 name the exports that return them.The earlier second commit of this PR (
GatedAddressSigner, taking the gate after the last signature) is dropped: #5860 merged its own split of the gate (sign outside,top_up_identity_withrechecks under the gate before send), which closes the same window.How Has This Been Tested?
cargo test -p platform-wallet -p platform-wallet-ffi --all-features: platform-wallet 2157 lib tests passed (27 address top-up tests), platform-wallet-ffi 611 passed and 1 ignored (18 top-up tests), plus the integration suites;rs-unified-sdk-jni78 passed. New or changed tests: the new route submits for an unmanaged and for a managed identity, leaves the identity manager unchanged, and writes a managed identity's proved balance back from a confirmed top-up (through the composite's seam); the deprecated managed route refuses an unmanaged identity with 7 before Platform is asked and reports 58 when Platform has no identity; empty rows, overflowing rows, a stale or re-created wallet and an oversized transition are refused on every route; removal during signing completes without waiting and the top-up fails withWalletRemovedBeforeSend, for a managed identity and for any other; a wallet re-created during signing is refused the same way; a wallet removed during the identity and nonce reads asks the host for no signature. FFI: every export (new and both deprecated) for the argument guards, empty rows as a list or as(NULL, 0), the panic code and the registry release.cargo fmt --all,cargo clippy -p platform-wallet -p platform-wallet-ffi -p rs-unified-sdk-jni --all-features --all-targets -- -D warnings;python3 scripts/check_sdk_parity_manifest.pypasses.:sdk:testDebugUnitTest :app:testDebugUnitTestgreen (619 + 300 tests), includingIdentityAddressTopUpTest.build_ios.sh --target all(release framework, SwiftExampleApp built with warnings as errors), thenswift test: 1052 tests, 0 failures (1 skipped); SwiftExampleAppxcodebuild teston the simulator: 262 unit tests and 8 UI tests (1 skipped) green.Breaking Changes
None in the API: additions and deprecations only (
#[deprecated]on the two Rust routes,@available(*, deprecated)in Swift,@Deprecatedin Kotlin). Behaviour of the deprecated routes:Identityfetch) instead of signing for the identity manager's copy; the result codes are the ones feat(platform-wallet)!: top up an identity the wallet does not manage from Platform addresses #5860 documents (7, 80, 58, 20, 98).Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull request🤖 Generated with Claude Code
PR Hygiene ·
8f91488sdk-parity— you own itkotlin-sdk(packages/kotlin-sdk/KotlinExampleApp/TEST_PLAN.md,packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/credits/TopUpIdentityScreen.kt,packages/kotlin-sdk/PARITY_SUMMARY.mdand 4 more) — approved by HashEngineeringrs-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.rsand 3 more) — approved by HashEngineeringrs-platform-wallet(packages/rs-platform-wallet/src/wallet/identity/network/mod.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.rsand 1 more) — approved by HashEngineeringswift-sdk— you own itWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.