Skip to content

fix(platform-wallet): report an identity balance refusal on withdrawal as insufficient credits - #5206

Merged
romchornyi merged 2 commits into
v5.0-devfrom
fix/identity-withdraw-insufficient-credits
Oct 5, 2026
Merged

romchornyi merged 2 commits into
v5.0-devfrom
fix/identity-withdraw-insufficient-credits

Conversation

@romchornyi

@romchornyi romchornyi commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

When Platform refuses an identity credit withdrawal (or a credit transfer to addresses) because the balance cannot cover the amount plus the transition's minimum fee, the wallet stringifies the consensus IdentityInsufficientBalanceError into InvalidIdentityData. The host receives only prose — Failed to withdraw credits: Protocol error: Insufficient identity <id> balance <n> required <n> — and Dash Wallet iOS shows exactly that text to the user.

The DPNS marketplace already promotes the same consensus error to the typed InsufficientIdentityCredits (FFI code 39); the withdrawal paths never did.

What was done?

  • rs-platform-wallet/src/error.rs: new promote_identity_insufficient_balance (+ _or owned-error wrapper, which then falls back to preserve_signer_key_unavailable_or). promote_document_trade_error reuses it for its IdentityInsufficientBalanceError arm.
  • wallet/identity/network/withdrawal.rs, transfer_to_addresses.rs: map SDK errors through promote_identity_insufficient_balance_or, so a balance refusal surfaces as PlatformWalletError::InsufficientIdentityCredits { required, available } (Platform's own figures). Every other error keeps its existing mapping.
  • rs-platform-wallet-ffi/src/error.rs: code-39 registry and doc list the new emitters. No new code, no ABI change — Swift already decodes it as PlatformWalletError.insufficientIdentityCredits.

How Has This Been Tested?

  • New error::identity_insufficient_balance_tests (3): CheckTx Protocol(ConsensusError) shape, wait-stream StateTransitionBroadcastError shape through the _or wrapper, unrelated errors left to the fallback.
  • cargo test -p platform-wallet --lib: 1180 passed.
  • Built the Swift SDK xcframework with this change on top of dd461eb8bd and ran Dash Wallet iOS against it on testnet (identity withdrawal and credit transfer to a Platform address both succeed).

Breaking Changes

None for the ABI. Behavioural: a host that matched the InvalidIdentityData text of a refused withdrawal now receives code 39 instead.

Checklist:

  • I have performed a self-review of my own code
  • 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

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

PR Hygiene · bcaa0fe

  • Bots — coderabbitai skipped after its own rate limit · thepastaclaw ✓
  • Self-review — posted; again after any push
  • Within your 5 open PRs
  • Build green
  • Approvals
    • rs-platform-wallet-ffi (packages/rs-platform-wallet-ffi/src/error.rs) — approved by llbartekll
    • rs-platform-wallet (packages/rs-platform-wallet/src/error.rs, packages/rs-platform-wallet/src/wallet/identity/network/transfer_to_addresses.rs, packages/rs-platform-wallet/src/wallet/identity/network/withdrawal.rs) — approved by llbartekll

When every box is checked the PR Hygiene check passes and this can merge.

@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 56 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 32d7be76-fef2-41c0-bcbc-a36026816b59

📥 Commits

Reviewing files that changed from the base of the PR and between 547f5a9 and bcaa0fe.

📒 Files selected for processing (4)
  • packages/rs-platform-wallet-ffi/src/error.rs
  • packages/rs-platform-wallet/src/error.rs
  • packages/rs-platform-wallet/src/wallet/identity/network/transfer_to_addresses.rs
  • packages/rs-platform-wallet/src/wallet/identity/network/withdrawal.rs
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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

Comment @coderabbitai help to get the list of available commands.

@thepastaclaw

thepastaclaw commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit bcaa0fe) · triage: low

@github-actions github-actions Bot added this to the v4.3.0 milestone Sep 29, 2026
@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 29, 2026

@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

The change correctly promotes identity balance refusals for withdrawals and transfers to addresses into the existing typed InsufficientIdentityCredits error while preserving signer-key and fallback behavior. The remaining identity-to-identity and masternode withdrawal paths stringify similar refusals, but those are pre-existing adjacent paths outside this PR's explicitly stated scope.

Review provenance

Source: reviewer 1: glm-5.3-flash (agent: phase1-reviewer, role: general); reviewer 2: glm-5.3-flash (agent: phase1-reviewer, role: architecture-layering); reviewer 3: glm-5.3-flash (agent: phase1-reviewer, role: ffi-engineer); reviewer 4: glm-5.3-flash (agent: phase1-reviewer, role: rust-quality); reviewer 5: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 6: gpt-6-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 7: gpt-6-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 8: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6-astra (agent: astra-verifier, role: final-verifier)

  • Triage: low by gpt-6-astra (effort low) — The diff makes a small, contained error-mapping change that reuses an existing typed insufficient-credit error for two wallet operations, preserves other error fallbacks, and adds focused tests without changing funds movement, consensus rules, or the FFI ABI.
  • Phase 1 reviewers: glm-5.3-flash — general (completed, effort high); agent phase1-reviewer, glm-5.3-flash — architecture-layering (completed, effort high); agent phase1-reviewer, glm-5.3-flash — ffi-engineer (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 99% left, weekly 82% left; passed over gemini-3.8-flash-high (antigravity below 15% reserve: weekly 13% left, 5h 100% left)
  • Fresh verifier: gpt-6-astra — final-verifier; agent astra-verifier
  • Phase 2 reviewers: gpt-6-astra — general (completed, effort medium); agent phase2-reviewer, gpt-6-astra — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6-astra — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort medium); agent phase2-reviewer
Out-of-scope follow-up suggestions (2)

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.

  • Other identity-funded credit paths still stringify balance refusals — The identity-to-identity credit transfer path in transfer.rs and the masternode withdrawal path still route IdentityInsufficientBalanceError through preserve_signer_key_unavailable_or, producing InvalidIdentityData prose instead of the typed InsufficientIdentityCredits result. These paths are unchanged by this PR and are outside the stated withdrawal and transfer-to-addresses scope, but a follow-up could route them through the new centralized promotion helper for consistent host-facing errors.
    • Follow-up: Track a separate maintainer-requested change to apply promote_identity_insufficient_balance_or to transfer_credits_with_external_signer and execute_masternode_withdrawal.
  • Sibling identity→identity credit transfer still stringifies the same balance refusal this PR promotes — Already covered by the consolidated out-of-scope follow-up; transfer.rs is an unchanged sibling path outside the PR's explicitly documented scope.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.

romchornyi pushed a commit to dashpay/dashwallet-ios that referenced this pull request Sep 30, 2026
… dependency

- Add the new refusal string to every Localizable.strings (English in all
  locales until Transifex supplies translations), at the position the
  catalog tooling sorts it to.
- Say in the doc comment that the typed branch is not reached until the
  SDK ships dashpay/platform#5206, as a TODO rather than a present-tense
  claim.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. waiting-self-review Waiting for the author to post /self-reviewed labels Sep 30, 2026
@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: address llbartekll left a review thread unresolved, then post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Oct 2, 2026
llbartekll
llbartekll previously approved these changes Oct 2, 2026

@llbartekll llbartekll left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Promotion order (balance refusal -> signer key-unavailable -> stringify) is right, required/available match IdentityInsufficientBalanceError::new(id, balance, required_balance), and both CheckTx and wait-stream shapes are covered via consensus_error_of. No ABI change; Swift already decodes code 39.

Non-blocking follow-up: the plain identity -> identity credit transfer (wallet/identity/network/transfer.rs:116) still goes through preserve_signer_key_unavailable_or and stringifies into InvalidIdentityData, while Platform emits the same IdentityInsufficientBalanceError for IdentityCreditTransfer (identity_credit_transfer/state/v0 + its estimated-fee validation). Swapping it to promote_identity_insufficient_balance_or would make all three credit-moving paths consistent; fine as a separate PR.

The red Kotlin SDK build + tests check is a runner issue (checkdir error: cannot create cmdline-tools while unpacking the Android SDK), unrelated to this change.

…l as insufficient credits

Platform refuses an identity credit withdrawal or credit transfer to
addresses with IdentityInsufficientBalanceError when the balance cannot
cover the amount plus the transition's minimum fee. Both wallet paths
stringified it into InvalidIdentityData ("Failed to withdraw credits:
Protocol error: Insufficient identity <id> balance <n> required <n>"),
so hosts could only show the raw protocol text.

Promote it to the typed InsufficientIdentityCredits (FFI code 39, with
Platform's required/available figures) the way the DPNS marketplace
already does, through a shared promote_identity_insufficient_balance
helper that the document-trade promotion now reuses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@romchornyi
romchornyi force-pushed the fix/identity-withdraw-insufficient-credits branch from 96c9109 to 7a77f6c Compare October 2, 2026 10:19
@romchornyi
romchornyi changed the base branch from v5.1-dev to v5.0-dev October 2, 2026 10:19
@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Oct 2, 2026
@github-actions github-actions Bot modified the milestones: v5.1.0, v5.0.0 Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

📖 Book Preview built successfully.

Download the preview from the workflow artifacts.
To view locally: download the artifact, unzip, and open index.html.

Updated at 2026-10-02T10:21:48.790Z

…_identity_insufficient_balance_or

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@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

Static verification of the complete diff at bcaa0fe found no actionable in-scope defects: withdrawal and transfer-to-addresses balance refusals preserve Platform's required and available amounts through the existing code-39 JSON mapping, while signer-key-unavailable and unrelated-error handling remain intact. The added tests cover CheckTx, wait-stream, fallback, and signer-error preservation; the adjacent consistency follow-ups are pre-existing and outside the stated scope. The supplied exact-head CI snapshot reports successful Rust wallet tests, Swift SDK build/tests and frozen-schema checks, and Kotlin SDK build/tests; Rust workspace tests were skipped and PR Hygiene remains pending, with no local builds or tests run.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Review provenance

Source: reviewer 1: gemini-3.8-flash-high (agent: phase1-reviewer, role: general); reviewer 2: gemini-3.8-flash-high (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: general); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: low by gpt-6.1-sol (effort low) — The diff makes a small, contained error-mapping change in withdrawal and transfer paths, reuses existing typed errors without changing funds movement or the ABI, and adds focused regression tests.
  • Phase 1 reviewers: gemini-3.8-flash-high — general (completed, effort high); agent phase1-reviewer, gemini-3.8-flash-high — rust-quality (completed, effort high); agent phase1-reviewer
  • Phase 1 model: gemini-3.8-flash-high — antigravity quota: weekly 51% left, 5h 82% left
  • Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — general (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — architecture-layering (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — ffi-engineer (completed, effort medium); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort medium); 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 (2)

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.

  • Identity-to-identity credit transfer in transfer.rs does not promote IdentityInsufficientBalanceError — Outside scope — transfer.rs:111-121 still preserves signer-key-unavailable errors and stringifies other failures in transfer_credits_with_external_signer, but the identical mapping exists at the PR base. The stated goal explicitly covers identity withdrawals and transfers to addresses, not identity-to-identity transfers. Extending typed reporting to this sibling operation is routine adjacent consistency work, not an exceptional follow-up to retain.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.
  • Promote IdentityInsufficientBalanceError in identity-to-identity transfers and masternode withdrawals — Outside scope — transfer.rs:115-120 and masternode_withdrawal.rs:456-460 use preserve_signer_key_unavailable_or with an InvalidIdentityData fallback at both base and head. Neither path is changed or newly relied upon by this PR, whose description specifically targets the ordinary identity withdrawal and transfer-to-addresses callers. Broader adoption of the helper is routine adjacent improvement and does not warrant expanding this review or retaining an exceptional follow-up.
    • Follow-up: Consider creating a separate issue or author/maintainer-requested PR for this.

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-self-review Waiting for the author to post /self-reviewed label Oct 2, 2026
@github-actions github-actions Bot added bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Oct 2, 2026
@romchornyi

Copy link
Copy Markdown
Contributor Author

/self-reviewed

@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Ready for review — rs-platform-wallet-ffi: HashEngineering or ZocoLini or llbartekll · rs-platform-wallet: HashEngineering or ZocoLini or llbartekll.
Full checklist in the description.

@github-actions github-actions Bot added ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 2, 2026
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Policy satisfied — this can merge.
Full checklist in the description.

@github-actions github-actions Bot removed the ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. label Oct 2, 2026
@romchornyi
romchornyi merged commit 3f029d8 into v5.0-dev Oct 5, 2026
28 checks passed
@romchornyi
romchornyi deleted the fix/identity-withdraw-insufficient-credits branch October 5, 2026 07:17
romchornyi pushed a commit that referenced this pull request Oct 5, 2026
Resolves the error.rs conflict with #5206 by keeping both sides: this branch's DASH-amount helpers for CoreFundsAwaitingNetwork and #5206's identity_insufficient_balance_tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@PastaPastaPasta PastaPastaPasta mentioned this pull request Oct 5, 2026
1 of 22 tasks
PastaPastaPasta pushed a commit to PastaPastaPasta/dashwallet-ios that referenced this pull request Oct 6, 2026
…pt it

Max from Identity to Transparent held back 0.002 DASH, a reserve borrowed
from identity funding (the opposite direction, where it must stay small).
Platform checks an IdentityCreditWithdrawal against amount + 0.004 DASH,
so every Max was refused at Confirm with the raw protocol error.

The reserve is now owned by the withdrawal and depends on the target:
- Transparent: the 0.004 DASH consensus minimum + 0.001 margin (0.005,
  the same the evonode withdrawal holds back).
- Platform: 0.002 DASH, unchanged — its minimum is 0.000065 DASH.

Max, the Continue gate and the inline validation all use it. A balance
refusal that still reaches Confirm (the balance moved in between) is
shown as a sentence instead of the protocol dump, once the SDK reports
it typed (dashpay/platform#5206).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants