Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ class IdentityRegistrationController(
data class Failed(val message: String) : Phase

/**
* Broadcast-succeeded-but-confirmation-failed terminal state
* (shielded only). The identity at [identityId] MAY already be live;
* the slot must stay held so a re-submission can't burn funds against
* the registered-key-hash check.
* Unconfirmed terminal state (shielded only): the transition may have
* reached a node and its result is not proved. The identity at
* [identityId] MAY already be live; the slot must stay held so a
* re-submission can't burn funds against the registered-key-hash check.
*/
data class Unconfirmed(val identityId: ByteArray, val message: String) : Phase {
override fun equals(other: Any?): Boolean =
Expand All @@ -90,12 +90,13 @@ class IdentityRegistrationController(

/**
* Which stage a shielded [Phase.Failed] failed at, so the progress
* screen can attribute the red marker. Only [BroadcastRejected] is
* attributable with confidence; every other failure leaves this null and
* the progress screen falls back to its elapsed-time heuristic.
* screen can attribute the red marker. Only [BroadcastNotSent] (the
* transition was refused before anything was sent) is attributable with
* confidence; every other failure leaves this null and the progress
* screen falls back to its elapsed-time heuristic.
* ← Swift `FailureStage`.
*/
enum class FailureStage { BroadcastRejected }
enum class FailureStage { BroadcastNotSent }

private val _phase = MutableStateFlow<Phase>(Phase.Idle)
val phase: StateFlow<Phase> = _phase.asStateFlow()
Expand Down Expand Up @@ -136,7 +137,7 @@ class IdentityRegistrationController(
fun submit(
body: suspend () -> ByteArray,
isUnconfirmed: (Throwable) -> ByteArray? = { null },
isBroadcastRejected: (Throwable) -> Boolean = { false },
isBroadcastNotSent: (Throwable) -> Boolean = { false },
) {
when (_phase.value) {
is Phase.Idle, is Phase.PreparingKeys, is Phase.Failed -> Unit
Expand All @@ -157,7 +158,7 @@ class IdentityRegistrationController(
terminalAt = now()
_phase.value = Phase.Unconfirmed(unconfirmedId, e.message ?: "Confirmation pending")
} else {
_failureStage.value = if (isBroadcastRejected(e)) FailureStage.BroadcastRejected else null
_failureStage.value = if (isBroadcastNotSent(e)) FailureStage.BroadcastNotSent else null
terminalAt = now()
_phase.value = Phase.Failed(e.message ?: "Registration failed")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RegistrationCoordinator(
fundingKind: IdentityRegistrationController.FundingKind = IdentityRegistrationController.FundingKind.AssetLock,
body: suspend () -> ByteArray,
isUnconfirmed: (Throwable) -> ByteArray? = { null },
isBroadcastRejected: (Throwable) -> Boolean = { false },
isBroadcastNotSent: (Throwable) -> Boolean = { false },
): IdentityRegistrationController {
val key = SlotKey(walletId.toHex(), identityIndex)
val existing = _controllers.value[key]
Expand All @@ -89,7 +89,7 @@ class RegistrationCoordinator(
-> {
// Legitimate restart: a fresh idle controller, or a retry after failure.
existing.enterPreparingKeys()
existing.submit(body, isUnconfirmed, isBroadcastRejected)
existing.submit(body, isUnconfirmed, isBroadcastNotSent)
scheduleRetentionSweep(key, existing)
return existing
}
Expand All @@ -98,7 +98,7 @@ class RegistrationCoordinator(
val controller = IdentityRegistrationController(walletId, identityIndex, fundingKind, scope, now)
_controllers.update { it + (key to controller) }
controller.enterPreparingKeys()
controller.submit(body, isUnconfirmed, isBroadcastRejected)
controller.submit(body, isUnconfirmed, isBroadcastNotSent)
scheduleRetentionSweep(key, controller)
return controller
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,11 @@ fun SendTransactionScreen(
}
}
} catch (e: DashSdkError.PlatformWallet.ShieldedSpendUnconfirmed) {
// Broadcast accepted but its execution result couldn't
// be confirmed — the spend may already be on chain and
// the notes stay reserved Rust-side, so this must NOT
// read as a retryable failure (← SendViewModel.swift:790).
// It may have reached a node and its result is not
// proved (a node's refusal or verdict included), so it
// may already be on chain and a retry signs a second
// transition: this must NOT read as a retryable
// failure (← SendViewModel.swift:790).
successMessage = "Transaction may have gone through — waiting for " +
"the next shielded sync to confirm. Do not retry."
} catch (t: Throwable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class RegistrationCoordinatorTest {
}

@Test
fun `broadcast-rejected classifier sets failure stage`() = runTest {
fun `broadcast-not-sent classifier sets failure stage`() = runTest {
val coordinator = coordinator()
val gate = CompletableDeferred<ByteArray>()

Expand All @@ -119,14 +119,14 @@ class RegistrationCoordinatorTest {
identityIndex = 0,
fundingKind = IdentityRegistrationController.FundingKind.ShieldedPool,
body = { gate.await() },
isBroadcastRejected = { true },
isBroadcastNotSent = { true },
)
gate.completeExceptionally(RuntimeException("broadcast rejected"))
gate.completeExceptionally(RuntimeException("nothing was sent"))
advanceUntilIdle()

assertTrue(controller.phase.value is Phase.Failed)
assertEquals(
IdentityRegistrationController.FailureStage.BroadcastRejected,
IdentityRegistrationController.FailureStage.BroadcastNotSent,
controller.failureStage.value,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,31 +267,32 @@ sealed class DashSdkError(

/**
* `ErrorShieldedSpendUnconfirmed` (native code 18). A shielded spend
* (transfer / unshield / withdraw / shield) was broadcast and
* accepted, but its execution result couldn't be confirmed — it may
* already be on chain. Rust intentionally KEEPS the spent notes'
* reservations, so the caller must NOT retry (a retry would rebuild
* the bundle against other notes and could double-spend); the next
* shielded sync reconciles the outcome. The Android analog of
* (transfer / unshield / withdraw / shield from Platform addresses)
* may have reached a node and its result is not proved (a failed
* result wait, a node's refusal or a consensus verdict, stale address
* nonce included), so it may already be on chain. Do NOT retry: a
* retry signs a second transition. Spends keep their notes reserved
* for the wallet to resolve; a shield stays pending until the
* shielded scan observes its note. The Android analog of
* Swift's `PlatformWalletError.shieldedSpendUnconfirmed`, which the
* iOS send flow surfaces as a non-retryable "may have gone through"
* outcome rather than an error.
*/
class ShieldedSpendUnconfirmed(message: String, cause: Throwable? = null) :
PlatformWallet(
"$message (do NOT retry: the spend may already be on chain; " +
"the wallet keeps the spent notes reserved until the next " +
"shielded sync reconciles the outcome)",
"$message (do NOT retry: it may already be on chain or may " +
"still execute, and a retry signs a second transition)",
cause,
)

/**
* `ErrorMasternodeWithdrawalUnconfirmed` (native code 42). A
* masternode (evonode) identity credit withdrawal was broadcast and
* accepted, but its execution result couldn't be confirmed — it may
* already have executed, and the identity nonce was consumed for it,
* so a blind retry could submit a SECOND withdrawal. Do NOT retry;
* re-read the identity's claimable balance and reconcile first. The
* masternode (evonode) identity credit withdrawal may have reached a
* node and its remaining balance is not proved (a failed result wait,
* a node's refusal or a consensus verdict included). It may have
* executed; a retry signs a second withdrawal with the next identity
* nonce. Do NOT retry; re-read the claimable balance first. Only a
* failure before anything was sent keeps an ordinary code. The
* Android analog of Swift's
* `PlatformWalletError.masternodeWithdrawalUnconfirmed`.
*/
Expand All @@ -304,10 +305,10 @@ sealed class DashSdkError(

/**
* `ErrorShieldedBroadcastFailed` (native code 16). A DEFINITIVE
* non-execution outcome — relay/CheckTx rejected the transaction
* before it entered the chain, and any note reservations were
* released. Safe to retry (the opposite of the ambiguous
* [ShieldedSpendUnconfirmed]).
* non-execution outcome: the transition never left the wallet
* (refused before anything was sent), so it can never execute, and
* any note reservations were released. Safe to retry (the opposite
* of the ambiguous [ShieldedSpendUnconfirmed]).
*/
class ShieldedBroadcastFailed(message: String, cause: Throwable? = null) :
PlatformWallet(message, cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2010,10 +2010,11 @@ class PlatformWalletManager(
// (cached by [bindShielded]), so no signer or resolver handle crosses
// JNI — matching the Swift counterparts, which take no signer either.
// Each blocks for the ~30s Halo 2 proof on Dispatchers.IO. On the
// AMBIGUOUS outcome (broadcast accepted, execution unconfirmed) they
// throw [org.dashfoundation.dashsdk.errors.DashSdkError.PlatformWallet.ShieldedSpendUnconfirmed]
// — the caller must NOT retry (the spent notes stay reserved Rust-side;
// the next shielded sync reconciles the outcome).
// AMBIGUOUS outcome (the spend may have reached a node and its result is
// not proved, a node's refusal or verdict included) they
// throw [org.dashfoundation.dashsdk.errors.DashSdkError.PlatformWallet.ShieldedSpendUnconfirmed]:
// the caller must NOT retry (the spent notes stay reserved Rust-side
// until a later shielded sync resolves them).

/**
* Shielded → shielded transfer (Type 16) — port of Swift's
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class DashSdkErrorTest {
DashSdkError.fromNative(DashSDKException(offset + 18, "ambiguous spend"))
assertTrue(spendUnconfirmed is DashSdkError.PlatformWallet.ShieldedSpendUnconfirmed)
assertFalse(
"ShieldedSpendUnconfirmed must NOT be retryable (notes stay reserved)",
"ShieldedSpendUnconfirmed must NOT be retryable (a retry signs a second transition)",
spendUnconfirmed.isRetryable,
)
// The message must warn against retrying, like the broadcast sibling.
Expand Down
8 changes: 4 additions & 4 deletions packages/rs-platform-wallet-ffi/ERROR_CODE_REGISTRY.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ These are shipped ABI. Do not renumber.
| 13 | `ErrorArithmeticOverflow` | Produced in-tree by `shielded_send.rs` (the shielded-send amount/fee overflow guard). Its rustdoc was corrected by #4360 (`e0b8baa850`), which documents the `PlatformWalletError::InputSumOverflow` mapping — the stale no-producer comment this row used to track is gone |
| 14 | `ErrorNoSelectableInputs` | |
| 15 | `ErrorWalletAlreadyExists` | |
| 16 | `ErrorShieldedBroadcastFailed` | For a shielded spend that consumes notes, since #5810: only a transition refused before anything was sent (no address to send it to, or the SDK's own refusal), its notes released. An endpoint's verdict (CheckTx or execution, which no proof backs) and every transport failure after a dispatch, which note spends reported here before, now report 18, or 17 for an identity created from the pool. A shield into the pool still reports a verdict here |
| 16 | `ErrorShieldedBroadcastFailed` | Only a transition refused before anything was sent (no address to send it to, or the SDK's own refusal), its notes released. For a shielded spend that consumes notes, since #5810: an endpoint's verdict (CheckTx or execution, which no proof backs) and every transport failure after a dispatch, which note spends reported here before, now report 18, or 17 for an identity created from the pool. A shield from Platform addresses no longer reports an endpoint's refusal or verdict here either: that is 18 |
| 17 | `ErrorShieldedBroadcastUnconfirmed` | |
| 18 | `ErrorShieldedSpendUnconfirmed` | Also, since #5810, what note spends (shielded transfers, unshields, withdrawals, identity top-ups and private document creations from the pool) reported as 16 before: an endpoint's verdict and any transport failure after a dispatch, as the transition may have been delivered. Also `ShieldedBroadcastMaybeDelivered`. The notes and the redrive record are kept; a host must not pay again with other notes |
| 18 | `ErrorShieldedSpendUnconfirmed` | Also, since #5810, what note spends (shielded transfers, unshields, withdrawals, identity top-ups and private document creations from the pool) reported as 16 before: an endpoint's verdict and any transport failure after a dispatch, as the transition may have been delivered. Also `ShieldedBroadcastMaybeDelivered`. The notes and the redrive record are kept, the record saved before the broadcast and the reservation restored from it after a restart; a host must not pay again with other notes. Also what a shield from Platform addresses returns once a dispatch may have reached a node and its result is not proved, an endpoint's refusal or consensus verdict included |
| 19 | `ErrorShieldedNoRecordedAnchor` | |
| 20 | `ErrorTransactionBroadcastUnconfirmed` | |
| 21 | `ErrorAddressNonceMismatch` | |
| 21 | `ErrorAddressNonceMismatch` | No longer returned by a shield from Platform addresses: an endpoint's nonce verdict on a dispatched shield is 18. Transfers and withdrawals from Platform addresses, and identity registrations and top-ups from them, still return it |
| 22 | `ErrorCoreInsufficientFunds` | |
| 23 | `ErrorAssetLockNotTracked` | |
| 24 | `ErrorAssetLockAlreadyConsumed` | |
Expand All @@ -109,7 +109,7 @@ These are shipped ABI. Do not renumber.
| 39 | `ErrorInsufficientIdentityCredits` | Merged 2026-08-09 by **#4348** (`6373e00f0c`) |
| 40 | `ErrorContestedNameNotTradable` | Merged 2026-08-09 by **#4348** (`6373e00f0c`) |
| 41 | `ErrorShieldedInsufficientBalance` | Merged 2026-08-11 by **#4360** (`e0b8baa850`) |
| 42 | `ErrorMasternodeWithdrawalUnconfirmed` | Merged 2026-08-22 by **#4451** (masternode-credit claiming). **Took the number active #4356 had claimed** for `ErrorAssetLockInputConflict` — see the proposed table's 42 note; #4356 renumbers via the frontier |
| 42 | `ErrorMasternodeWithdrawalUnconfirmed` | Merged 2026-08-22 by **#4451** (masternode-credit claiming). **Took the number active #4356 had claimed** for `ErrorAssetLockInputConflict`; see the proposed table's 42 note. #4356 renumbers via the frontier. Returned once a dispatch may have reached a node and the result is not proved, an endpoint's refusal or consensus verdict included; only a withdrawal that never left the wallet keeps an ordinary, retryable code |
| 46 | `ErrorMasternodeListUnavailable` | Merged 2026-08-24 by **#4465** (`8dd964277`). Initially minted as 43 (already held by active #4313's `ErrorShieldedInviteAlreadyClaimed` across all three layers) — collision flagged in review and renumbered to the then-frontier same day, Rust and Swift together |
| 98 | `NotFound` | Sentinel — `Option` returned as an error |
| 99 | `ErrorUnknown` | Sentinel — unmapped/flattened errors |
Expand Down
Loading
Loading