Skip to content

fix(wallet): send Platform address transfers and withdrawals through platform-wallet - #1165

Open
Claudius-Maginificent wants to merge 16 commits into
v1.0-devfrom
fix/platform-address-ops-via-platform-wallet
Open

Claudius-Maginificent wants to merge 16 commits into
v1.0-devfrom
fix/platform-address-ops-via-platform-wallet

Conversation

@Claudius-Maginificent

@Claudius-Maginificent Claudius-Maginificent commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: Sending, withdrawing or topping up an identity from Platform addresses now updates the wallet's balance immediately for every part of the app, so a later "Max" never offers credits the wallet no longer has.

User story

As a wallet user, I want my Platform balance to be correct everywhere right after I send, withdraw or top up an identity, to move the rest of my credits (for example, shield all of them with "Max") without a failed transaction.

Scenario

Base flow

A user sends credits from their Platform addresses to another address, withdraws some to their Core wallet, or uses them to top up an identity. Then they open Shield, pick their Platform balance and press "Max".

Actual behavior

The balance shown in the wallet updates, but the part of the wallet that prepares shielding keeps the old balance until the next background sync. "Max" can offer more than the wallet holds, and the shield transaction then fails.

Expected behavior

Each of these payments updates the one shared record of the Platform balance at once. Every screen, "Max" included, shows the post-payment balance.

Detailed discussion

What was done

  • New seam src/wallet_backend/platform_address_ops.rs (impl WalletBackend). Each method opens one JIT secret session over the HD seed and signs with DetPlatformSigner; the seed never leaves the session.
    • transfer_platform_address_credits → PlatformAddressWallet::transfer(0, InputSelection::Explicit(inputs), outputs, [DeductFromInput(fee_payer_index)], None, signer).
    • withdraw_platform_address_credits → PlatformAddressWallet::withdraw(…). Like before, it uses no change output and Pooling::Never. The existing signing-path self-heal runs inside the same session through a prepare_path_index hook, so a protected wallet is prompted once.
    • top_up_identity_from_platform_addresses → SDK Identity::top_up_from_addresses, then upstream's public PlatformAddressWallet::reconcile_address_infos(&infos, proof_height, "identity top-up"). That is the same seam the composite PlatformWallet::top_up_from_addresses uses internally. One PlatformWallet handle is resolved before the session and reused for reconciliation, so nothing after a successful broadcast can fail.
  • Inputs, outputs, the fee strategy, the fee estimate and every result variant are unchanged. The UI and MCP callers (identity_credits_topup_from_platform) need no changes.
  • DET's model now applies the entries platform-wallet actually committed (PlatformAddressChangeSet → PlatformAddressEntry → AppContext::apply_platform_address_spend). It no longer writes its own copy from the proof. The withdrawal path no longer runs a full platform-address rescan afterwards.
  • apply_platform_address_spend also merges the committed entries into the frame-safe wallet total, so wallet totals and selectors show the post-spend figure at once. That total is always the sum of a per-address ledger of (balance, as_of_height). Spends and coordinator passes merge into it in any order, and each address keeps its higher pin.
  • Per-address entries carry their proof-height pin (AddressFunds::as_of_height). A late, older result no longer overwrites a newer one, whether it is a coordinator pass that started before a spend, an older spend completing last, or a pass that omits a freshly spent address. Wallet::apply_pinned_platform_address_info and the ledger merge ignore a lower pin. An address a sync pass proves absent (a chain reset) that DET has tracked is zeroed at the scan's checkpoint height, in the per-address view and in the total, as platform-wallet zeroes its own copy. The zero is re-sent on every such pass, so a dropped notification heals on the next one.
  • An explicit Platform balance refresh is applied by height too (WalletAddressProvider::apply_results_to_wallet → apply_pinned_platform_address_info), so a refresh that started before a spend cannot bring back the pre-spend figure. The wallets screen no longer re-applies the refresh result the backend already wrote.
  • Identity creation from addresses and identity → address transfers apply their proof-verified address balances at the proof's height too (update_wallet_platform_address_info_from_sdk → apply_pinned_platform_address_info). A write that doesn't know its height resets the pin to 0 and never claims a newer one.
  • Errors: map_platform_address_spend_error
    • Sdk(e) → TaskError::from(e), the same classification and banners as before.
    • Upstream's promoted AddressNonceMismatch → new TaskError::PlatformAddressNonceMismatch: "Your Platform address balances changed while this payment was being prepared. Refresh the wallet, then send it again."
    • Everything else goes through the exhaustive identity_op_error_kind buckets. An unconfirmed broadcast becomes TransactionConfirmationUnknown, not a "retry" envelope.
  • Logging: the top-up's info line now logs the input count instead of the full address→amount map.

Behaviour difference: DET's per-address figures and wallet total follow platform-wallet's state. If platform-wallet commits nothing, they update on the next coordinator push instead of straight from the proof. That happens when its platform-address provider is not initialised yet (right after startup, before the first platform-address sync) or when it already holds an equal or fresher figure. Pinned by reconcile_commits_nothing_when_platform_wallet_is_not_behind and the module docs.

Upstream gaps (the reason the top-up does not call the composite yet; TODO(upstream) at the call site):

  • the composite top-up rejects identities the paying wallet does not manage;
  • the composite top-up flattens SDK errors into InvalidIdentityData(String), losing the broadcast-outcome class.

Out of scope:

Testing

  • Unit tests, new, red then green (wallet_backend::platform_address_ops, 11 tests, plus 6 ordering tests in context, wallet_backend::event_bridge and model::wallet):

    • error mapping: SDK classification preserved, generic rejection, nonce mismatch, unconfirmed broadcast, preconditions;
    • plain-language nonce message;
    • changeset → entries conversion;
    • wired context: after a proof-attested spend, platform-wallet and DET's model hold the same balance and nonce, and a third-party recipient is dropped;
    • an older proof commits nothing;
    • identity top-up: a stale-nonce rejection gets the refresh-and-retry message, other failures keep the SDK classification;
    • ordering: a coordinator pass older than a spend, an older spend applied last, and a delayed pass omitting a spent address change neither the address's balance and nonce nor the wallet total (a_pass_older_than_a_spend_does_not_undo_it, an_older_spend_applied_last_does_not_undo_a_newer_one, pass_totals_skip_a_wallet_whose_pass_predates_its_spend, pass_totals_keep_a_spent_address_the_pass_omits, pinned_platform_address_info_keeps_the_newer_figure, platform_balances_merge_by_pin_in_any_order); a funded address proven absent is zeroed (summary_entries_zero_a_funded_address_proven_absent); a refresh older than a spend does not undo it (a_refresh_older_than_a_pinned_spend_does_not_undo_it); an identity-proof update is pinned against older syncs (sdk_proof_update_is_pinned_against_older_syncs); a zeroed address stays tracked after a dropped push (a_zeroed_address_stays_tracked_for_the_next_pass, a_dropped_absence_push_is_resent_by_the_next_pass).
  • cargo clippy --all-features --all-targets -- -D warnings clean. Lib tests for wallet_backend::, backend_task::wallet::, backend_task::identity:: and backend_task::error::: 843 passed. kittest send / top-up / platform suites: 50 passed.

  • Live testnet run of the GUI build of this branch, with an isolated data directory and the backend-e2e fixture wallet:

    Flow Tool Result
    Platform → Platform transfer, 0.001 DASH to an own address GUI Success, ST 1e7799ef…e59d. platform-wallet stored the source (nonce 4→5) and the destination (0 → 100 000 000 credits) at height 652959 immediately. The wallet total dropped by the fee only.
    Withdraw 0.01 DASH to an own Core address GUI Success, ST c057d7fb…7df7. platform-wallet stored nonce 6 at height 652960 immediately; the Core balance rose by 0.0099981 DASH.
    Identity top-up from addresses, 0.002 DASH GUI Success, ST e7b90ea1…5c24. The identity balance is 206 692 072 credits; the address is stored at nonce 7, height 652963.
    Identity top-up from addresses, 0.001 DASH det-cli Not broadcast. The tool skips the SPV/masternode-list gate, so proof verification fails with QuorumKeyUnavailable (pre-existing det-cli gap, unchanged by this PR).
    Shield → Platform balance → Max GUI Max is 60.93217497705 DASH, which is 60.93331637705 DASH minus the 0.0011414 DASH fee. That balance matches the sum of platform-wallet's stored balances (6 093 331 637 705 credits) to the credit.

    No panics in det.log or det-stderr.log. det-cli has no Platform-address transfer, withdraw or shield-preflight tools, so those flows were run in the GUI.

  • Backend-e2e only (not run): a live broadcast of each flow with a mocked rejection, and a shield actually built from the "Max" platform-wallet preflight (fix(wallet): make every Max and fee match what the upstream builders accept #1107).

Breaking changes

None.

Checklist

  • cargo fmt --all
  • clippy clean
  • no user-story change (no new feature)

Prior work

Attribution

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

PR Hygiene · e034801

  • Bots — coderabbitai skipped after its own rate limit · thepastaclaw skipped after the window
  • Self-review — not asked of a bot author
  • Build failed — review was already requested; it still has to pass to merge
  • Approvals
    • files with no dedicated owner (src/backend_task/error.rs, src/backend_task/identity/mod.rs, src/backend_task/identity/register_identity.rs and 9 more) — lklimek

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

lklimek and others added 2 commits October 29, 2026 16:48
…platform-wallet

Platform-address transfers, withdrawals and identity top-ups called the
SDK directly and updated only DET's model, so platform-wallet's balances
(read by its shield preflight) stayed stale until the next sync.

- transfers and withdrawals go through PlatformAddressWallet::transfer /
  ::withdraw with the same explicit inputs and fee strategy
- top-ups keep the SDK call and record the spend with upstream's public
  reconcile_address_infos, because the composite top-up rejects
  identities the paying wallet does not manage and flattens SDK errors
- DET's model applies the entries platform-wallet committed, instead of
  writing its own copy from the proof; withdrawals no longer rescan
- a stale-nonce rejection gets its own plain-language TaskError

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT
@coderabbitai

coderabbitai Bot commented Oct 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 21 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
Commits

Reviewing files that changed from the base of the PR and between c8c53f6 and e034801.

Files selected for processing: 12
  • src/backend_task/error.rs
  • src/backend_task/identity/mod.rs
  • src/backend_task/identity/register_identity.rs
  • src/backend_task/wallet/transfer_platform_credits.rs
  • src/backend_task/wallet/withdraw_from_platform_address.rs
  • src/context/mod.rs
  • src/context/wallet_lifecycle/bootstrap.rs
  • src/model/wallet/mod.rs
  • src/ui/wallets/wallets_screen/mod.rs
  • src/wallet_backend/event_bridge.rs
  • src/wallet_backend/mod.rs
  • src/wallet_backend/platform_address_ops.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

thepastaclaw commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

⛔ Final review complete — 1 blocking finding(s) (commit e034801)

@Claudius-Maginificent
Claudius-Maginificent marked this pull request as ready for review October 30, 2026 10:05
@github-actions github-actions Bot added the bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. label Oct 30, 2026
@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Ready for review — files with no dedicated owner: lklimek.
Full checklist in the description.

@github-actions github-actions Bot added the ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. label Oct 30, 2026
@github-actions
github-actions Bot requested a review from lklimek October 30, 2026 10:39

@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 2 only (no Phase 1 for this repository)

The platform-wallet integration correctly reconciles per-address state and preserves the JIT signing boundary, but the new callers do not update DET's separate frame-safe aggregate balance. In addition, an older coordinator push can overwrite a newer spend result, and identity top-ups bypass the newly introduced stale-nonce classification. The first two issues can leave the UI offering credits that were already spent, so changes are required.

🔴 2 blocking | 🟡 1 suggestion(s)

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The diff substantially changes funds movement, coin selection, transaction signing, secret-session handling, and balance reconciliation in src/wallet_backend/platform_address_ops.rs and the related wallet backend tasks.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/backend_task/wallet/transfer_platform_credits.rs`:
- [BLOCKING] src/backend_task/wallet/transfer_platform_credits.rs:55-56: Platform spends leave the frame-safe aggregate balance stale
  This applies the returned changeset only through `apply_platform_address_push`, which updates each wallet's `platform_address_info` entry but never updates `AppContext::platform_balances`. Wallet selectors, wallet totals, and Shield's Max flow read `platform_balance_duffs` from that separate frame-safe snapshot. The withdrawal and identity top-up callers make the same call, and the transfer screen's follow-up `FetchPlatformAddressBalances` also only updates per-address state. After a successful spend, those readers can therefore continue showing the pre-spend aggregate until a coordinator sync, directly contradicting the PR's goal that every part of the app immediately shows the post-payment balance.

In `src/wallet_backend/platform_address_ops.rs`:
- [BLOCKING] src/wallet_backend/platform_address_ops.rs:194-205: Older coordinator pushes can overwrite the reconciled spend result
  The conversion keeps balance, nonce, and derivation coordinates but drops the upstream freshness information such as the proof height. The resulting entries are applied by `AppContext::apply_platform_address_push` with unconditional `set_platform_address_info`. A coordinator sync can snapshot pre-spend balances, release platform-wallet's provider lock, and enqueue its older `PlatformAddressSyncPushed` result while the spend reconciles and applies newer proof-attested values. If the queued coordinator result is processed afterward, it overwrites the newer per-address state with the old balance and nonce. Upstream's provider freshness guard protects its own state, but it does not protect DET's separate model map. DET needs an ordering/freshness check or an operation-specific update path that prevents an older coordinator result from regressing the visible state.
- [SUGGESTION] src/wallet_backend/platform_address_ops.rs:164-167: Apply nonce-mismatch promotion to identity top-ups
  The direct identity top-up calls the SDK's `Identity::top_up_from_addresses` and maps its raw `dash_sdk::Error` directly to `TaskError`. The pinned platform-wallet identity wrapper explicitly promotes `AddressInvalidNonceError` to `PlatformWalletError::AddressNonceMismatch` before applying its fallback mapping, but this direct path omits that promotion. A stale address nonce during an identity top-up therefore receives the generic platform rejection instead of `PlatformAddressNonceMismatch` and loses the refresh-and-retry guidance that the new error variant documents. Apply the same typed promotion used by the transfer and withdrawal paths.

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

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet · thepastaclaw 2 threads unresolved — resolve them. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head 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-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. waiting-bots Waiting for the review bots to report on this head labels Oct 30, 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.

Re-review — Final validation — Phase 2 only (no Phase 1 for this repository)

The platform-wallet integration correctly reconciles committed per-address changes, but three correctness gaps remain. Identity top-ups bypass nonce-mismatch promotion, stale coordinator results can overwrite newer spend data in DET, and the frame-safe aggregate balance remains unchanged after successful spends, leaving wallet totals and Max selection stale.

🔴 2 blocking | 🟡 1 suggestion(s)

3 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The diff substantially changes funds movement, coin selection, transaction signing, and HD-seed handling in src/wallet_backend/platform_address_ops.rs and the related transfer, withdrawal, and identity top-up task paths.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/wallet_backend/platform_address_ops.rs`:
- [SUGGESTION] src/wallet_backend/platform_address_ops.rs:164-167: Apply nonce-mismatch promotion to identity top-ups
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1165#discussion_r4423469250)
  The transfer and withdrawal paths map platform-wallet errors through `map_platform_address_spend_error`, which preserves the upstream `AddressNonceMismatch` classification. The identity top-up path calls the SDK trait directly and maps its `dash_sdk::Error` with `TaskError::from`, so a stale address nonce is classified as a generic SDK failure instead of the actionable `TaskError::PlatformAddressNonceMismatch` guidance used by the other two flows. Apply the pinned platform-wallet `promote_address_nonce_error_or_sdk` conversion before passing the error to the shared mapper.
- [BLOCKING] src/wallet_backend/platform_address_ops.rs:194-205: Older coordinator pushes can overwrite the reconciled spend result
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1165#discussion_r4423469242)
  The pinned platform-wallet reconciliation uses `AddressFunds::as_of_height` to reject older coordinator data, but `changeset_platform_entries` copies only balance, nonce, and derivation coordinates into `PlatformAddressEntry`, discarding that freshness marker. `AppContext::apply_platform_address_push` then unconditionally calls `Wallet::set_platform_address_info`, which has no ordering guard. A coordinator query that started before the spend can therefore be delivered after the spend's fresh changeset and restore the pre-spend balance and nonce in DET, causing later input selection or Max calculations to use stale per-address data. Carry the proof/sync height or equivalent per-address ordering metadata through the update path and reject older pushes before mutating the model.

In `src/backend_task/wallet/transfer_platform_credits.rs`:
- [BLOCKING] src/backend_task/wallet/transfer_platform_credits.rs:55-56: Platform spends leave the frame-safe aggregate balance stale
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1165#discussion_r4423469233)
  The successful transfer path updates only per-address data through `apply_platform_address_push`; the withdrawal and identity top-up callers do the same. That method does not update `AppContext::platform_balances`, whose `platform_balance_duffs` value is consumed by wallet selectors, wallet totals, account summaries, and the Shield/Max flow. `platform_balances` is written by the coordinator callback only, so after any of these successful spends the aggregate remains at the pre-spend total until another coordinator sync, even though platform-wallet and the per-address DET cache already reflect the spend. Update the frame-safe aggregate from the reconciled platform-wallet state as part of the successful spend path, while preserving the existing credit-to-duff aggregation semantics.

lklimek and others added 2 commits November 4, 2026 10:34
…d withdrawals

The direct identity top-up from Platform addresses mapped its SDK error
straight to TaskError, so a stale address nonce got the generic rejection
banner instead of the refresh-and-retry PlatformAddressNonceMismatch.
Promote it with upstream's promote_address_nonce_error_or_sdk and share
map_platform_address_spend_error with the other two spends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ep older syncs off it

A transfer, withdrawal or identity top-up from Platform addresses updated
only the per-address view, so wallet totals and selectors kept the
pre-spend figure until the next coordinator pass. A coordinator pass that
started before the spend could also land after it and bring back the
pre-spend balance and nonce.

Each spend now returns platform-wallet's post-commit total with the
committed entries, and AppContext::apply_platform_address_spend writes it
into the frame-safe total. Entries carry their proof-height pin
(AddressFunds::as_of_height): the per-address model ignores an entry
pinned lower than the stored one, and the event bridge skips a wallet's
pass total while any of its entries is older than a spend pinned for that
address.

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

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 4 threads unresolved — resolve them. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added 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 Nov 4, 2026
… figures

Publishing whole totals let two results undo each other: an older spend
completing after a newer one installed its stale total, and a delayed
coordinator pass that predated a freshly funded and spent address passed
the per-address freshness check and published a total without it.

The frame-safe total is now always the sum of a per-address ledger of
(balance, as_of_height). Spends and coordinator passes merge into it under
the platform_balances lock, keeping the higher pin per address, so neither
completion order nor an omitted address can regress it. Warm start seeds
the ledger from persisted rows. Spends no longer read platform-wallet's
total.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lklimek and others added 4 commits November 4, 2026 11:19
The coordinator's raw found set omits an address the tree scan proves
absent (a chain reset), so DET kept its last balance per address and, now
that the wallet total is summed per address, in the total too. Emit a zero
entry for each absent address DET still shows funds for, pinned at the
scan's checkpoint height, as upstream zeroes its own copy. Never-funded
derived addresses stay out of the push.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A refresh that started before a spend and finished after it went through
set_platform_address_info, which replaced the balance and nonce while
keeping the stored pin, so the pre-spend figure came back under the
spend's height. The wallets screen also replayed the refresh result, an
unversioned copy of the wallet's own state, after the backend had applied
it.

WalletAddressProvider::apply_results_to_wallet now writes through
apply_pinned_platform_address_info with each address's as_of_height, a
write of unknown height resets the pin to 0 instead of claiming a newer
one, and the wallets screen no longer re-applies the result.

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

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 2 threads unresolved — resolve them. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

lklimek and others added 2 commits November 4, 2026 11:39
… proof height

Identity creation from addresses and identity-to-address transfers applied
their proof-verified balances through set_platform_address_info, which
resets the height pin to 0, so a delayed older sync could restore the
pre-spend balance and nonce. update_wallet_platform_address_info_from_sdk
now takes the proof height both flows already have and writes through
apply_pinned_platform_address_info.

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

The zero entry for a funded address a sync proves absent was emitted only
while the ledger still showed funds. If the push carrying it was dropped
on a full channel, the ledger was already zero, so no later pass sent it
and the per-address view kept the old balance. Emit the zero for every
address the ledger tracks, so the next pass heals a dropped push.

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

@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 2 only (no Phase 1 for this repository)

Static verification at head 388553d confirms that all seven prior findings are fixed. Three blocking gaps remain: stale upstream managed balances can still affect Shield, address-funded identity registration bypasses reconciliation, and dropped absence notifications do not recover; one additional suggestion strengthens refresh regression coverage. Current Clippy, Test Suite, and Platform pin guard checks pass; the inspected base-drift commits do not supersede these changes, and the supplied merge evidence reports no conflicts.

🔴 3 blocking | 🟡 1 suggestion(s)

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

🔴 Blocking: Reconcile the address-funded identity registration sibling
src/backend_task/identity/register_identity.rs:368-372

Address-funded identity registration still submits directly through the SDK and applies the successful proof only through update_wallet_platform_address_info_from_sdk. That helper updates DET's per-address map, but neither platform-wallet's managed account balances nor the new frame-safe ledger. Creating an identity with Platform credits and then opening Shield → Max therefore leaves the same stale funding balances that this PR fixes for address-funded top-ups. This is an outgoing Platform-address payment sibling, not the incoming identity-to-address transfer explicitly excluded from the PR. The pinned upstream PlatformWallet::register_from_addresses already reconciles these funding addresses through reconcile_address_infos. Route this successful registration through a wallet-backend operation that reconciles upstream state and publishes committed entries through apply_platform_address_spend; retaining the direct SDK submission followed by reconciliation is an option if needed to preserve current identity behavior and typed errors. Add registration-to-balance/preflight coverage. Because this is an unchanged missed sibling, a reasonable separate fix can be tracked instead, but a linked issue or PR covering it is needed before deferring it; none is identified in the supplied PR discussion.

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

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The intricate cross-layer change directly rewires funds movement and signing/key-session handling in src/wallet_backend/platform_address_ops.rs, including transfers, withdrawals, and identity top-ups, while adding height-pinned balance reconciliation.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort xhigh); agent phase2-reviewer
  • Model comparison: every Phase-2 reviewer also ran on gpt-6-astra; the verifier weighed both sets without knowing which model wrote which
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/model/wallet/mod.rs`:
- [BLOCKING] src/model/wallet/mod.rs:1880-1886: Protect the upstream balances used by Shield, not only DET's mirrors
  This guard preserves DET's newer address figure, but it does not protect the managed balance that Shield actually reads. In the pinned dashpay/platform commit 575d961, PlatformPaymentAddressProvider::on_address_found unconditionally calls account.set_address_credit_balance at packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs:696. The height check in sync_finished protects the provider's committed found map only; it does not undo that managed-account mutation. A full scan from a lagging replica can therefore restore a pre-spend managed balance after reconciliation at a higher height. The SDK permits one-block metadata lag by default, and its full-scan callbacks do not reject this lower-height figure. PlatformWallet::shielded_shield_plan_for_account then reads account.address_credit_balance and can offer an oversized Max even while DET retains the correct post-spend balance. An unchanged incremental pass seeds its result without replaying the callback, so it need not repair the managed value. The relevant provider and Shield implementations remain unchanged at the supplied upstream default tip. Fix freshness before managed-account mutation in dashpay/platform and consume that fix here, with a regression exercising a real lower-height on_address_found callback after a spend and checking Shield preflight. This is a behavioral gap in the PR's stated Max guarantee, not an objection to maintaining display caches.
- [SUGGESTION] src/model/wallet/mod.rs:2598-2602: Exercise nonzero refresh heights through the provider
  The production adapter correctly forwards funds.as_of_height, but this regression populates the provider through update_balance, which always assigns height zero. The test would therefore still pass if apply_results_to_wallet accidentally forwarded a constant zero instead of the scan's actual height. That regression would reject legitimate refreshes of spend-pinned addresses, and the direct setter tests do not exercise this adapter boundary. Populate the provider with scan-shaped AddressFunds carrying a nonzero older height, verify rejection after a newer spend, then apply a refresh newer than the spend and assert that its balance, nonce, and height are accepted.

In `src/backend_task/identity/register_identity.rs`:
- [BLOCKING] src/backend_task/identity/register_identity.rs:368-372: Reconcile the address-funded identity registration sibling
  Address-funded identity registration still submits directly through the SDK and applies the successful proof only through update_wallet_platform_address_info_from_sdk. That helper updates DET's per-address map, but neither platform-wallet's managed account balances nor the new frame-safe ledger. Creating an identity with Platform credits and then opening Shield → Max therefore leaves the same stale funding balances that this PR fixes for address-funded top-ups. This is an outgoing Platform-address payment sibling, not the incoming identity-to-address transfer explicitly excluded from the PR. The pinned upstream PlatformWallet::register_from_addresses already reconciles these funding addresses through reconcile_address_infos. Route this successful registration through a wallet-backend operation that reconciles upstream state and publishes committed entries through apply_platform_address_spend; retaining the direct SDK submission followed by reconciliation is an option if needed to preserve current identity behavior and typed errors. Add registration-to-balance/preflight coverage. Because this is an unchanged missed sibling, a reasonable separate fix can be tracked instead, but a linked issue or PR covering it is needed before deferring it; none is identified in the supplied PR discussion.

In `src/wallet_backend/event_bridge.rs`:
- [BLOCKING] src/wallet_backend/event_bridge.rs:361-365: Retain zero-balance updates until the per-address cache receives them
  A zero ledger balance is not an acknowledgement that the per-address cache received the absence update. When a scan proves a previously funded address absent, write_pass_totals first merges its zero entry into the ledger. The later non-blocking PlatformAddressSyncPushed send can fail when the channel is full, and its error is discarded. On subsequent passes this predicate is false because the ledger already contains zero, so summary_ok_platform_entries stops emitting the absence record even when absence is proved again. The aggregate then shows zero while wallet.platform_address_info retains the old spendable balance until some separate event repairs it. Explicit refresh does not clear this case either: WalletAddressProvider::apply_results_to_wallet iterates only found entries. Preserve replayable committed zero records or pending delivery state independently of the aggregate balance, and resend until the per-address consumer can converge. Prefer exposing upstream committed address state rather than adding another absence-inference policy. Add a regression that fills the channel, drops the first absence push, drains it, and verifies a subsequent pass clears the per-address cache.

Comment thread src/model/wallet/mod.rs Resolved
Comment thread src/wallet_backend/event_bridge.rs Resolved
Comment thread src/model/wallet/mod.rs Resolved
…bsence push

The refresh regression fed the provider through update_balance, which
always pins at 0, so it could not catch apply_results_to_wallet forwarding
a constant height. It now uses scan-shaped funds pinned below and above
the spend. A new event-bridge test drops the first absence push and checks
that the next pass still carries the zero.

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

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet · thepastaclaw requested changes — dismiss the review or push a fix, 1 thread unresolved — resolve it. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

The coordinator's per-address push was dropped when the task channel was
full. A later pass repairs found addresses, but not an address proven
absent: upstream drops it from its baseline, so incremental passes carry
neither a found nor an absent record and its zero never reached the
per-address view. The bridge now keeps refused updates, coalesced to the
newest pin per address, and sends them with the next pass whatever that
pass contains.

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

@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 2 only (no Phase 1 for this repository)

Three balance-consistency gaps remain: dropped absence updates are not replayed by ordinary incremental passes, address-funded registration bypasses reconciliation, and warm-start hydration discards persisted height pins. Eight prior findings are addressed; the independently confirmed upstream managed-account race is now explicitly tracked in dashpay/platform#5760 and reasonably deferred. This was a static review of head 61f87f2: no builds or tests were run, Clippy and Test Suite remain pending, and the supplied four-commit base drift contains no conflicts or superseding fix.

🔴 4 blocking

2 carried-forward finding(s) already raised on this PR; not re-posting as new inline comments.

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 3: gpt-6-astra (agent: phase2-reviewer, role: general); reviewer 4: gpt-6-astra (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — The large, intricate diff directly changes funds movement and signing in src/wallet_backend/platform_address_ops.rs through transfer_platform_address_credits, withdraw_platform_address_credits, and top_up_identity_from_platform_addresses, alongside height-pinned balance reconciliation across concurrent updates.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — general (completed, effort xhigh); agent phase2-reviewer, gpt-6-astra — rust-quality (completed, effort xhigh); agent phase2-reviewer
  • Model comparison: every Phase-2 reviewer also ran on gpt-6-astra; the verifier weighed both sets without knowing which model wrote which
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/backend_task/identity/register_identity.rs`:
- [BLOCKING] src/backend_task/identity/register_identity.rs:368-374: Reconcile the address-funded identity registration sibling
  This address-consuming success path still applies the proof only through `update_wallet_platform_address_info_from_sdk`. That helper changes DET's per-address map, but neither reconciles platform-wallet's managed-account balances nor updates `platform_balance_ledger` and `platform_balances`. Registration can consequently consume Platform-address funds while Shield's planner and the frame-safe total retain the pre-registration figure. Adding the proof height protects this one mirror from older pushes; it does not establish the shared post-spend state. This is a missed spending sibling whose result application and shared helper are being extended in this PR, rather than unrelated cleanup. Resolve the paying platform-wallet handle before broadcast, reconcile the returned address information through the backend seam, and publish the committed entries through `apply_platform_address_spend`, preserving registration's existing result and error behavior. If this sibling is deferred, link a tracking issue or PR; no registration reconciliation follow-up is linked in the current description or supplied discussion.

In `src/context/mod.rs`:
- [BLOCKING] src/context/mod.rs:1086-1088: Preserve persisted height pins when warming per-address balances
  `persisted_platform_address_warm_start` supplies each entry's `as_of_height`, and the new ledger retains it, but this call discards it. `seed_platform_address_info` delegates to `set_platform_address_info`, which inserts a height of zero. Hydration initializes the per-address map empty, so restarting with a post-spend balance persisted at height H really does establish a zero pin here. An explicit refresh returning an older valid pre-spend figure can then pass `apply_pinned_platform_address_info` and restore the old balance and nonce, while the aggregate ledger remains pinned at H. Pass the persisted height into the insert-if-absent seeding operation without weakening its protection for an already-present live entry. Add a warm-start regression that rejects a lower-height refresh and separately verifies that seeding cannot overwrite live state.

In `src/wallet_backend/event_bridge.rs`:
- [BLOCKING] src/wallet_backend/event_bridge.rs:538-550: Retain zero-balance updates until the per-address cache receives them
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1165#discussion_r4467098629)
  The balance-independent predicate permits replay only when another summary contains the address in `result.absent`. The next normal coordinator pass does not repeat that absence proof. In pinned platform-wallet, `sync_finished` removes the address from committed `found`, `prepare_for_sync` clears the previous absence set, and `sync_balances` supplies the updated timestamp to the SDK. The SDK's incremental-only branch seeds from the remaining `current_balances` and produces neither a found nor an absent entry for the unchanged absent address. If `try_send` drops the first zero update, the aggregate ledger therefore remains zero while `wallet.platform_address_info` retains its old spendable balance. The new regression calls extraction twice on the same full-scan summary, so it does not establish recovery across actual successive passes. Retain the proof-attested zero record or pending delivery independently of subsequent summaries, and test a full channel dropping the first push followed by a distinct incremental summary with no repeated absence.

In `src/model/wallet/mod.rs`:
- [BLOCKING] src/model/wallet/mod.rs:1880-1886: Protect the upstream balances used by Shield, not only DET's mirrors
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1165#discussion_r4467098622)
  This guard preserves DET's newer address figure, but it does not protect the managed balance that Shield actually reads. In the pinned dashpay/platform commit 575d961, PlatformPaymentAddressProvider::on_address_found unconditionally calls account.set_address_credit_balance at packages/rs-platform-wallet/src/wallet/platform_addresses/provider.rs:696. The height check in sync_finished protects the provider's committed found map only; it does not undo that managed-account mutation. A full scan from a lagging replica can therefore restore a pre-spend managed balance after reconciliation at a higher height. The SDK permits one-block metadata lag by default, and its full-scan callbacks do not reject this lower-height figure. PlatformWallet::shielded_shield_plan_for_account then reads account.address_credit_balance and can offer an oversized Max even while DET retains the correct post-spend balance. An unchanged incremental pass seeds its result without replaying the callback, so it need not repair the managed value. The relevant provider and Shield implementations remain unchanged at the supplied upstream default tip. Fix freshness before managed-account mutation in dashpay/platform and consume that fix here, with a regression exercising a real lower-height on_address_found callback after a spend and checking Shield preflight. This is a behavioral gap in the PR's stated Max guarantee, not an objection to maintaining display caches.

⏸️ Needs a tracking issue before it can be deferred (1): Protect the upstream balances used by Shield, not only DET's mirrors. Link one in the finding's thread, or ask there and PastaClaw files it.

Comment thread src/context/mod.rs Resolved
… balances

Warm start seeded each address through set_platform_address_info, which
stores height 0, so after a restart an older refresh could restore a
pre-spend balance and nonce while the wallet total stayed pinned.
seed_platform_address_info now takes the persisted as_of_height and
stores it.

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

Copy link
Copy Markdown
Collaborator Author

Re latest review-body findings:

Retain zero-balance updates until the per-address cache receives them (FIXED): Carried-forward item; fixed in 3b81494. Refused pushes are kept, trimmed to the newest pin per address, and re-sent with the next pass whatever it contains (EventBridge::deliver_platform_updates). Regression: a_dropped_platform_push_is_delivered_by_the_next_pass.

🤖 Co-authored by Claudius the Magnificent AI Agent

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai skipped after its own rate limit · thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@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 2 only (no Phase 1 for this repository)

Verified the Phase-2 findings against head e034801: ten prior findings are fixed, and registration reconciliation and upstream managed-balance freshness are reasonably deferred to linked follow-ups. One blocking issue remains: coordinator pushes can install another network's proof-height pin, preventing legitimate current-network updates from repairing the per-address balance. This was static verification only; Test Suite and Clippy are still pending.

🔴 1 blocking

Review provenance

Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This large, intricate change directly alters funds movement and signing in src/wallet_backend/platform_address_ops.rs through transfer_platform_address_credits, withdraw_platform_address_credits, and top_up_identity_from_platform_addresses, alongside cross-cutting balance reconciliation.
  • Phase 1 reviewers: not run (disabled for this repository)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `src/wallet_backend/event_bridge.rs`:
- [BLOCKING] src/wallet_backend/event_bridge.rs:138-143: Scope pinned coordinator updates to their originating network
  This sends height-pinned entries without their producing network: `unattributed_success` assigns `BackendTaskContext::Unknown`, and `AppState` applies `PlatformAddressSyncPushed` to `active_context` unconditionally at src/app.rs:2288–2292. Network contexts share the GUI result channel, and `finalize_network_switch` retains the outgoing backend. With the same seed loaded on Testnet and Regtest/Devnet, the wallet seed hash and DIP-17 addresses match because those networks share coin type 1. A queued Testnet update pinned at height 600000 can therefore populate the lower-height network's per-address cache. The new freshness guard makes the existing routing defect worse: legitimate refreshes, coordinator pushes, and spend results below that foreign height are rejected, leaving the foreign balance and nonce stuck while the current network's aggregate follows its own ledger. Carry the producing network in the typed push and apply it only to the corresponding context. Add a regression that queues a high-height push, switches to a lower-height network containing the same wallet, and verifies that its per-address balance and pin remain uncontaminated.

Comment thread src/wallet_backend/event_bridge.rs Resolved
@lklimek
lklimek dismissed thepastaclaw’s stale review November 4, 2026 12:59

Dismissed by maintainer decision: the remaining blocker (Platform-address sync pushes applied to the active network without checking their origin) predates this PR on v1.0-dev and is fixed by #1159 — see #1165 (comment)

@github-actions github-actions Bot added the bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. label Nov 4, 2026
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@thepastaclaw review

No review for e0348013 yet, so PR Hygiene is asking once. If nothing arrives, the requirement is dropped for this commit and the pull request is labelled bot-review-skipped.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Ready for review — files with no dedicated owner: lklimek.
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-bots Waiting for the review bots to report on this head labels Nov 5, 2026
@Claudius-Maginificent Claudius-Maginificent added priority: high High priority — address soon priority: medium Medium priority and removed priority: high High priority — address soon priority: medium Medium priority labels Nov 5, 2026
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Found during the 2026-11-10 weekly release review (v1.0.0-weekly.20261110, testnet). Both issues are in the Platform address transfer path this PR moves onto platform-wallet, so please fix them here.

1. Platform → Platform "Max" is always refused. This also happens in v1.0.0-weekly.20261027, so it is not a regression from #1107. Reproduced 2/2.

  • Max reserves estimate_platform_fee(1, 1) (src/model/fee_estimation.rs:1015): the static minimum, plus a storage guess, plus 20%, for a total of 15,200,400 credits.
  • Drive checks the remaining balance against a worst-case pre-check instead (validate_fees_of_event/v0 runs the operations with apply = false). For 1 input and 1 output that is 15,308,500.
  • The broadcast fails with AddressesNotEnoughFundsError (have 15,200,400, need 15,308,500), even though the fee actually charged is only about 3–9.5M.
  • Options:
    • (a) reserve the pre-check figure;
    • (b) for Max, use ReduceOutput so the fee comes out of the sent amount;
    • (c) ask upstream for a client-side estimator of the pre-check, since none exists as of platform 6323a43.
  • Please add a test that covers Platform → Platform Max. The current "Platform Max" kittest is Core → Platform.

2. AddressesNotEnoughFundsError reaches the user as "An unexpected error occurred. Please try again later."

  • From<SdkError> has no arm for it, so it falls through to TaskError::SdkError (src/backend_task/error.rs ~4886).
  • Retrying fails the same way, so the advice is wrong.
  • Please add a dedicated TaskError variant that carries the available and required amounts, with an actionable message (for example, lower the amount by the shortfall).

Full analysis with file:line citations is in the release-review artifacts (investigation-platform-max.md).

🤖 Co-authored by Claudius the Magnificent AI Agent

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. priority: high High priority — address soon ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants