Repository navigation
rs-sdk: put_to_platform_and_wait_* fails with AlreadyExists when a timed-out broadcast was already accepted #4998
Description
Expected Behavior
When a state transition's broadcast times out after a node has already accepted it, and the DAPI client's retry is answered with AlreadyExists, put_to_platform_and_wait_for_response* should treat the transition as submitted and go on to wait for its result.
Current Behavior
The put fails with SDK error: Object already exists: tx already exists in cache, although Platform executes the transition.
Sequence from a testnet reproduction (identifiers replaced):
dapi_client: received error: … "Timeout expired" … # attempt 1, node A, after the 10 s client timeout
dapi_client: ban address https://<node-A>:1443/ due to error: … Timeout expired
dapi_client: retrying error with sleeping 0.01 secs
dapi_client: received error: … AlreadyExists, message: "tx already exists in cache" # attempt 2, node B
broadcast: failed after retries error=AlreadyExists("tx already exists in cache")
Node A had taken the transition into the mempool before the client gave up, so node B already had it. The IdentityCreate executed: getIdentity for its id returns the identity with the submitted keys. The caller, however, got an error, and a retry is then refused with IdentityAssetLockTransactionOutPointAlreadyConsumedError. From the user's side a paid registration looks failed and cannot be repeated.
Possible Solution
put_identity_with_asset_lock_and_private_key / …_and_signer call state_transition.broadcast(sdk, settings).await? (put_identity.rs#L310, #L344). The ? returns AlreadyExists from broadcast() before the caller reaches Self::wait_for_response (put_identity.rs#L183). Identity::wait_for_response already handles AlreadyExists by fetching the identity (waitable.rs), but it is never reached.
The same shape applies to every broadcast → wait path, not only identities.
Fix direction:
- In
broadcast(): treatAlreadyExistsas "this exact transition is already accepted" (the mempool reports it for identical bytes) and returnOk(()), so every put proceeds to its wait. The wait then yields the real outcome. - Nonce: keep the existing
refresh_identity_nonceonly for genuine failures. A transition that is in the mempool has consumed its nonce.
#4997 works around this for claim_invitation only: on AlreadyExists / outpoint-consumed it fetches the identity at the prospective id and adopts it when the keys match. Registration via register_identity_with_funding and document/contract puts still surface the error.
Steps to Reproduce (for bugs)
- On a slow testnet (DAPI answers take > 10 s under load), register an identity or claim an invitation through
put_to_platform_and_wait_for_response*. - When the first broadcast attempt hits the client timeout after the node accepted the transition, the retry gets
AlreadyExistsand the put returns it. getIdentityfor the transition's identity id returns the identity.
It is timing-dependent. In our run the load came from the shielded notes sync (see the linked issue); a unit test can script it with a mock DAPI that times out on the first broadcast and answers AlreadyExists on the second.
Context
Found on testnet while testing the iOS invitation claim (dashpay/dashwallet-ios#1156). The user sees "Registration failed" for an identity that exists and was paid for. Partial fix for invitations: #4997.
Your Environment
- Version used:
v4.3-dev@b1a4f35f9b(same code onv4.2-dev) - Environment name and version: SwiftDashSDK via
rs-platform-wallet-ffi, iOS 26.5 simulator - Operating System and version: macOS 27 host, testnet
- Link to your project: dashpay/dashwallet-ios
Activity
romchornyi commentedon Sep 25, 2026
Related: #4999 is the load that pushed the broadcast past its timeout in the reproduction. #4997 works around this for
claim_invitationonly.romchornyi commentedon Sep 26, 2026
Partly fixed by #5012 (merged into #4997's branch): identity creates through
put_to_platform_and_wait_for_response_with_private_key/_with_signernow treat a broadcastAlreadyExistsas delivered and wait for the result. Still open: top-ups (broadcast_and_wait_for_affected_state) and otherbroadcast→waitpaths such as documents.llbartekll commentedon Oct 29, 2026
Tracking two remaining broadcast → proof-wait callers from the final review of #5556 here, rather than opening duplicate issues. This issue already tracks the wider family of combined submission paths and remains open.
The PR owner has explicitly decided to defer these two pre-existing paths from #5556:
contract.rs:547–554:transition.broadcast(...).awaitpropagates an error beforeDataContract::wait_for_response. A lost acknowledgement after possible acceptance can prevent the existing proof lookup from running.put_profile_write: the raw broadcast?similarly skipswait_for_document_and_owner_balance_with_metadataafter an ambiguous broadcast error.Both sequences are unchanged in #5556. They are real retained limitations, not fixes delivered by that PR. The code paths demonstrate the early return; we have not performed a new live reproduction for either of these operations.
For a focused follow-up, preserve the broadcast observation and use the existing proof wait for the same signed transition. Verify a lost acknowledgement reaches that wait, a definite refusal without prior uncertainty does not, an invalid/missing proof cannot become success, and no replacement operation or additional nonce is constructed. Keep existing retry budgets; this does not require a new persistence or recovery mechanism.
Review: #5556 (review)
Do not close this issue merely because #5556 merges; the two items above remain outstanding.
Claudius-Maginificent commentedon Oct 29, 2026
Another member of this family:
masternode_withdrawreturns a plainInvalidIdentityDatafor a broadcast that failed with gRPCUnavailable, although the transition may have been delivered, and a retry can withdraw twice. Tracked in #5665.🤖 Co-authored by Claudius the Magnificent AI Agent
llbartekll commentedon Nov 24, 2026
Status of the DashPay profile create/update item above, checked at
v5.1-dev05694a4 (2026-11-24): unchanged.put_profile_writestill runsstate_transition.broadcast(self, None).await?and then a barewait_for_document_and_owner_balance_with_metadata(...). The other document writers go throughwait_after_broadcast. That leaves two gaps:wait_after_broadcastmaps it withError::into_unconfirmed, because a result-stream error is decoded before the proof is verified. The profile writer skips that mapping, so a caller cannot tell a refusal reported during the wait from an initial refusal of the transition.Where the second gap shows in a client: dashwallet-ios saves a profile with a create when it has none cached, and switches to an update when the create is refused as a duplicate (the unique
$ownerIdindex). If the wallet's own create has landed and a duplicate refusal then comes back from the wait, the app sends an update the user did not need and pays its fee.dashpay/dashwallet-ios#1476 stopped the switch for results the SDK marks as unconfirmed. It cannot cover the second gap, which needs the SDK to mark the wait error. Review thread: dashpay/dashwallet-ios#1476 (comment)
This comes from reading the code. It has not been reproduced on a network.