Skip to content

fix(wallet): make every Max and fee match what the upstream builders accept - #1107

Merged
lklimek merged 62 commits into
v1.0-devfrom
feat/wallet-max-send-limits
Nov 5, 2026
Merged

lklimek merged 62 commits into
v1.0-devfrom
feat/wallet-max-send-limits

Conversation

@Claudius-Maginificent

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

Copy link
Copy Markdown
Collaborator

TL;DR: "Max" for Core sends, asset locks and shielding from Platform now comes from the wallet library's own quotes, so a Max can no longer fail when you send. Username registration checks every fee the network will charge, including the real cost of joining a crowded vote, before anything is paid.

User story

As a wallet user, I want Max to send exactly what the wallet can actually send, and username registration to tell me the real price up front, so that I never lose a fee on a transaction that was bound to fail.

Scenario

Actual behavior

  • Max on a Core send or an asset lock is estimated from the main account only and can exceed what the transaction builder accepts, or need more than the 100 inputs a funding transaction may have.
  • Max when shielding from Platform reserves less fee headroom than the planner needs, so it can be refused.
  • Username registration ignores the extra 0.001 DASH the name contract requires and states the base vote fee even when the vote is crowded enough that joining costs more, or when it is already full. The first payment can then go through and the name be refused.

Expected behavior

  • Core sends and asset locks spend from all of the wallet's regular accounts (CoinJoin excluded), Max is the amount the real build accepts, and asset locks stay within 100 inputs.
  • Shield-from-Platform Max is the planner's own quote.
  • Username registration requires the 0.001 DASH reserve, shows and charges the fund to join the vote at its current size, and refuses a full vote with a clear message before anything is spent.

Detailed discussion

Based on v1.0-dev (Platform v5.1-dev 575d961). Rebuilt from #1015's stale base by replaying only this PR's own commits.

  • DPNS admission reserve: username_name_admission_reserve_credits is derived from the contract's chooseFirst declaration and the platform version (0 before DPNS v3). The backend guard and the confirmation both require it. The backend guard checks the balance read from Platform right before the preorder.
  • Asset-lock Max: the probe uses the same pooled funding sources as the real build; a dry run above max_asset_lock_transaction_inputs counts as unbuildable. Exact-amount asset locks that would need more inputs are refused before any secret is opened (TaskError::AssetLockTooManyInputs) at all five entry points.
  • Core send: send_payment calls finalize_transaction over the pooled sources and broadcast_finalized_transaction; change goes to BIP-44, coin selection is upstream's default. Max is pooled_max_sendable via WalletTask::GetSpendLimit and the ui/state/spend_limit.rs cache. A pooled dry run before signing keeps shortfalls and too-many-inputs typed and avoids a passphrase prompt for a send that cannot work. The old UI-side Max helpers are removed. When Max is zero the form says why, from typed outcomes (TaskError::CoreSendMaxUnavailable): nothing spendable outside CoinJoin, coins below their own fee, or coins held by an unfinished transaction. A search that times out offers a retry instead. The quote is keyed on the coins the pooled build can spend, so new blocks and chainlocks do not re-quote it.
  • Platform→Shielded Max: shielded_shield_preflight(0).max_shieldable_credits; the Max hint names the planner's 2× reserve, while the fee preview and confirmation state the two-action fee the shield is charged; TaskError::ShieldFromPlatformCapacityExceeded. Upstream's shield drops its inputs' proven post-state, so after a confirmed shield DET runs upstream's Platform-address sync pass (bounded 10 s wait, best-effort). The next Max is then quoted from the spent-down balances.
  • Contest fund to join: the availability check quotes Sdk::contest_fund_to_join; the result carries contest_fund, shown in the review and consent dialog. The backend re-quotes before the preorder and refuses a stale approval as UsernameRegistrationTermsChanged. document_create_contest_fund_cap uses the poll's required_vote_resolution_fund (moderation elections get the moderation fund).
  • Full vote: TaskError::UsernameContestFull and a ContestFull availability row, from max_contenders_per_contest under protocol 14 create validation (none before). DET counts contenders itself from proved vote-tally pages, because the SDK does not expose the count.

Fee estimates: upstream first, corrected in one place

  • One correction point. Every fee, size, limit and Max in model/fee_estimation.rs calls the upstream function and then one constant in fee_estimation::tolerance. The upstream functions are key-wallet estimate_tx_size + FeeRate::normal(), dpp calculate_min_required_fee / estimate_min_fee, the PlatformVersion fee tables, and platform-wallet's planner reserves. Each constant is an EstimateTolerance { percent, floor }. apply_fee only raises a fee. apply_max lowers a Max by exactly what apply_fee adds, so a Max plus its fee never exceeds the funds. The arithmetic saturates: the headroom is computed in u128, and a Max below the headroom becomes 0. The module doc makes it the only place DET corrects an upstream estimate. A future tolerance, such as feat(documents): agree to document action fees before broadcasting #1122's multiplier increase, would become one more constant there.
  • WRAP (upstream value, no margin):
    • Core send fee and Max: the pooled build's own pricing, priced for the destination script.
    • Platform storage and minimum-fee tables at the network's protocol version, not latest().
    • Identity create, top-up and update; address withdrawal; address funding; batch; address transfer.
    • The identity minimum fundings; the shielded fee and the shield planner's reserve, with the shield Max lowered by the same tolerance.
    • The Platform input cap (max_address_inputs).
    • The single-key send screen's fee, which no longer carries its own size formula.
  • KEEP + RESERVE (no upstream function, so DET's estimate with a reserve through the hook, floored at upstream's minimum):
    • Asset-lock Core fee +15% (payload bytes are not in upstream's size).
    • Transitions spending address inputs +20%; identity transfer +10%; username registration +10%.
    • Address funding from an asset lock +50% with a 10,000-duff floor.
    • Shield-from-Core L1 fee: flat 3,000-duff floor.
    • Document and contract storage estimates: 0%.
    • Two mirrors with TODO(upstream), because both are private upstream: the 500-input standard cap and pooled_max_sendable's per-input pricing. The 546-duff change remainder key-wallet may give the miner is a third such mirror.
  • DROP: estimate_contract_create_detailed + ContractComponents, estimate_masternode_vote, the *_with_size variants, the hand-kept StorageFeeConstants / StateTransitionMinFees / DataContractRegistrationFees tables.
  • What the user sees move (deliberately):
    • Core fee shown for a send: this is no longer "+15% of a guessed size". The Max quote carries the fee its proven build charged and the coins the pooled build can spend; upstream's all-coins drain counts them under the same lock, without reserved or CoinJoin coins. At the Max the fee shown is that build's fee, for the destination script. Max + fee is therefore exactly what the build spends, even with a coin reserved by another build or a Max cut short by the search deadline. Below the Max the fee shown is, over the spendable coins, the fee with change plus the up-to-546-duff remainder the build may give the miner, capped at what those coins hold beyond the amount. It is never below the charge.
    • Advanced Send: the preview now counts the change output.
    • Address funding from an asset lock: the fee estimate is now never below the network's required funding (56,000 / 62,000 duffs instead of 10,000 / 18,750). The smallest amount with the fee added on top drops to 500 duffs (the minimum output). The surplus goes to the change address.
    • Address withdrawal: the estimate reserves one input's cost.
    • Every other value is unchanged at the current protocol version.

Known limitations

  • Max can over-quote when a send's broadcast outcome was ambiguous and its spend goes unobserved for more than 24 blocks: platform-wallet's broadcast fence is not public, so the quote cannot see it. The real send is then refused before broadcast (no double spend).
  • An unexpected error while searching the Core Max makes Max under-offer instead of showing a retryable failure; fixed in feat(send): one From/To Send form with Auto routing #1112.
  • The fund to join can still double between the backend's re-quote and the name document landing; only a protocol change can close that window.
  • Below the Max, the Core fee shown is an upper bound, up to 546 duffs above the charge when the build returns change. An exact figure needs platform-wallet to quote a payment's fee without building and reserving it.
  • The identity-creation Max keeps the creation fee back from the wallet ceiling, although the fee comes out of the funded amount, so about 0.0024 DASH stays in the wallet. This predates this PR (same reserve on v1.0-dev) and is safe; it is left for a follow-up.
  • A Platform-address transfer, withdrawal or top-up started while the Shield form is open does not refresh the cached shield Max until those spends go through platform-wallet (fix(wallet): send Platform address transfers and withdrawals through platform-wallet #1165). No funds are at risk: the planner refuses a stale amount before proving it.
  • Shield-from-Platform Max is still offered while a shield from the same wallet is in progress. No funds are at risk, because upstream refuses the second shield before proving it, but the user can be prompted and then refused. Withholding it needs a Platform-spend guard keyed into the shield quote.
  • A Core send Max held back by a pending reservation is not recomputed when that reservation expires (after 24 blocks); key-wallet exposes no expiry signal. Max is only understated until the next coin change or send.
  • Upstream gaps (not filed): the exact-amount asset-lock builder does not enforce the input cap; finalize_transaction stringifies TooManyInputs; the pooled-source resolver and contender count are crate-private.

Testing

  • New behaviour tests were shown failing on the old code first (DPNS reserve, asset-lock Max, fund to join, full vote, pooled-finalize shortfall, address sync after a Platform shield).
  • Red first: the Core Max cache key ignores CoinJoin coins; the preview equals the pooled build's fee at the Max; Advanced counts change; the fee shown is never below the build's charge (one coin with change, P2SH Max); with a reserved coin Max + fee = the free coin; a deadline-cut Max carries its build's fee (640); the tolerance saturates at the extremes.
  • Local: cargo clippy --all-features --all-targets -- -D warnings clean. These library suites pass: fee estimation, wallet-backend payments/snapshot, the Send and single-key Send screens, identity, and shielded. cargo test --test kittest send_screen passes.
  • Live, testnet, GUI (det-cli has no Max or fee-preview command):
Flow Transaction Fee shown Fee charged Result
Core send, Max, 2 coins → 1 output e532ebf8bd2e26751f819311e98faa5de9041269c6810390e6caa4e1e75bda7b 340 duffs 340 duffs InstantSend-locked; Max 1.7999966 + fee = 1.8
Advanced send, 2 coins → 2 outputs + change cd10033310acca48eb95abbcf8fafba7ee391f81884f726163319b43e38fd884 374 duffs 408 duffs InstantSend-locked; run on a build whose preview left out the change output, which the preview now counts
Create identity, Max from wallet balance asset lock 3f7b6870c6c3208ad3c9380f291ea508dffc5654fb965324e259e4d55710bc7f 0.00241 DASH Platform fee 263 duffs Core fee InstantSend-locked; identity registered

No panics in det.log / det-stderr.log. Not run locally: full kittest and e2e (CI covers them); no live shields.

🤖 Co-authored by Claudius the Magnificent AI Agent

🤖 Generated with Claude Code

https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
https://claude.ai/code/session_01WunYYhY7P2FJqHVgkHiXtT

PR Hygiene · 2d99079

  • Bots — coderabbitai skipped after the window · thepastaclaw ✓
  • Self-review — not asked of a bot author
  • Build green
  • Approvals
    • files with no dedicated owner (docs/user-stories.md, src/backend_task/dashpay/contact_info.rs, src/backend_task/error.rs and 39 more) — approved by 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.

Summary by CodeRabbit

  • New Features
    • Send screens now show backend-quoted maximum amounts and fee estimates for Core sends and Platform shielding, with clearer states when a quote is pending, unavailable, or another wallet transaction is in progress.
    • Core sends and identity funding can proceed to backend validation when wallet balances are being checked; Max remains unavailable while the wallet is busy.
    • Username registration now reflects full voting contests, changing contest fees, and the required balance reserve before confirmation.
  • Bug Fixes
    • Improved handling of spend limits, funding errors, and Platform shielding capacity, including clearer insufficient-funds messages.
    • Username registration rechecks contest availability and required funds before broadcasting.

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

The PR adds backend-quoted spending limits for Core sends and Platform shielding, updates fee estimation and asset-lock validation, and tracks wallet operations that can change available funds. DPNS availability and registration now account for vote capacity, quoted contest fees, and admission reserves.

Changes: Wallet spending limits and shielding

Layer / File(s) Summary
Quote types and fee calculations
src/model/spend_limit.rs, src/model/fee_estimation.rs, src/context/mod.rs, src/ui/wallets/single_key_send_screen.rs, src/backend_task/wallet/*, src/ui/wallets/wallets_screen/*
Adds spend-limit and fee-quote types. Fee estimation now uses platform-version data, upstream fee minima, and Core transaction sizing.
Pooled inputs and spend revisions
src/wallet_backend/snapshot.rs, src/wallet_backend/spend_activity.rs, src/wallet_backend/mod.rs, src/wallet_backend/identity_ops.rs
Wallet snapshots publish pooled Core-send input keys and counts. Spend activity tracks per-wallet revisions and in-flight operations. Asset-lock input limits are checked before and after secret-session prompts.
Backend quotes and shielding operations
src/backend_task/*, src/wallet_backend/shielded.rs, src/wallet_backend/mod.rs, src/backend_task/error.rs, tests/backend-e2e/framework/cleanup.rs
Backend tasks carry spend-limit requests and return quoted limits. Shielding checks planner capacity and performs a bounded post-shield address sync.
Quote cache and send-screen integration
src/ui/state/*, src/ui/identity/*, src/ui/wallets/send_screen.rs, tests/kittest/send_screen.rs
The UI caches quotes by wallet, operation, and revision. Send screens use quotes for Core Max and Platform-to-Shielded Max. Asset-lock screens distinguish busy checks from other unavailable or failed checks.

DPNS contest registration

Layer / File(s) Summary
Contest limits and availability quotes
src/model/dpns.rs, src/model/dpns_usernames.rs, src/backend_task/identity/dpns_usernames.rs, src/model/fee_estimation.rs, src/backend_task/mod.rs, docs/user-stories.md
Availability checks count vote contenders when required, report full contests, and return the contest fund for the current name.
Registration fee and balance checks
src/backend_task/identity/register_dpns_name.rs, src/backend_task/error.rs
Registration rechecks the current contest fund and checks the live identity balance against the registration charge and admission reserve.
Registration review and contest feedback
src/ui/identity/register_dpns_name_screen.rs, src/ui/identity/username_copy.rs, tests/kittest/identity_usernames.rs, tests/kittest/register_dpns_name_screen.rs, docs/user-stories.md
The review uses a label-matched contest-fee quote, includes the admission reserve in required balance, and shows contest-full and raised-fee messages.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant WalletSendScreen
  participant BackendTask
  participant WalletBackend
  WalletSendScreen->>BackendTask: request spend-limit quote
  BackendTask->>WalletBackend: calculate maximum and optional Core fee
  WalletBackend-->>BackendTask: return quote or error
  BackendTask-->>WalletSendScreen: return revision-tagged result
Loading

Possibly related issues

  • Issue 1105: The PR uses a shield-planner quote for Platform-to-Shielded Max, but does not add the other route types described in the issue.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 69.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: aligning wallet Max amounts and fee estimates with upstream builder behavior.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 69.89% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 176 functions across 40 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Review coverage is incomplete: 1 file could not be fully reviewed. Findings from completed review steps are included; see review info for details.

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
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 206b397 and 2d99079.

Files selected for processing: 5
  • src/backend_task/identity/register_dpns_name.rs
  • src/model/spend_limit.rs
  • src/ui/identity/add_new_identity_screen/mod.rs
  • src/ui/wallets/send_screen.rs
  • src/wallet_backend/payments.rs
Files not fully reviewed because their changes were unavailable: 1
  • src/wallet_backend/payments.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@thepastaclaw

thepastaclaw commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Final review complete — no blockers (commit 2d99079) · triage: critical · Phase 2 only (no Phase 1 for this repository)

@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 PR improves builder-derived Max calculations, but two in-scope funds-safety issues remain. Core Max can be rejected by a stale display-only balance before reaching the live pooled builder, and the asset-lock input-cap preflight is separated from the real build, allowing concurrent wallet changes to invalidate the cap check. Two additional non-blocking findings identify misleading user-facing error messages. CI checks for this head are green.

🔴 2 blocking | 🟡 2 suggestion(s)

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

🔴 Blocking: Do not reject the live Core Max using the stale display balance
src/ui/wallets/send_screen.rs:1253-1261

The Core Max value is now supplied by the live upstream pooled_max_sendable quote at lines 3072-3080, but send_core_to_core() still rejects the amount against get_core_balance(), which reads the display-only wallet snapshot. That snapshot can lag the wallet state used by the pooled quote, including being zero before the first snapshot update or temporarily stale during recomputation. The UI can therefore offer a positive live Max, but clicking Send immediately returns the old insufficient-balance error without reaching WalletBackend::send_payment and its pooled builder. The backend builder should be authoritative for this route; retain the snapshot for display and ordinary informational checks, but do not use it to reject an amount accepted by the live quote.

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); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate change to wallet funds movement and coin selection across Core sends, asset locks, shielding, and username-registration payments, including transaction-building and fee enforcement in functions such as src/wallet_backend/payments.rs and src/backend_task/identity/register_dpns_name.rs.
  • 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/ui/wallets/send_screen.rs`:
- [BLOCKING] src/ui/wallets/send_screen.rs:1253-1261: Do not reject the live Core Max using the stale display balance
  The Core Max value is now supplied by the live upstream `pooled_max_sendable` quote at lines 3072-3080, but `send_core_to_core()` still rejects the amount against `get_core_balance()`, which reads the display-only wallet snapshot. That snapshot can lag the wallet state used by the pooled quote, including being zero before the first snapshot update or temporarily stale during recomputation. The UI can therefore offer a positive live Max, but clicking Send immediately returns the old insufficient-balance error without reaching `WalletBackend::send_payment` and its pooled builder. The backend builder should be authoritative for this route; retain the snapshot for display and ordinary informational checks, but do not use it to reject an amount accepted by the live quote.

In `src/wallet_backend/payments.rs`:
- [BLOCKING] src/wallet_backend/payments.rs:708-728: Make the asset-lock input-cap check atomic with the real build
  `ensure_asset_lock_amount_within_input_cap` holds the wallet-manager write lock only through the unsigned dry run and explicitly drops it at line 725. The callers then open the secret session and invoke the real upstream asset-lock builder, for example at lines 933-990. A concurrent spend, reservation change, or wallet sync can alter the selectable UTXO set in that gap: an amount that fit within the cap during the dry run may require more than the protocol's allowed number of inputs during the real build. The pinned upstream exact-amount asset-lock builder enforces the standard transaction limit but not the protocol asset-lock cap, so the resulting oversized lock can be broadcast and dropped by Core while its inputs remain reserved. Enforce the cap inside the same serialized build operation, or add an upstream builder primitive that makes the cap authoritative, and cover the preflight/build interleaving with a regression test.

In `src/backend_task/error.rs`:
- [SUGGESTION] src/backend_task/error.rs:453-456: Do not display gross Platform balance as the maximum shieldable amount
  The upstream `available` field used here is not the planner's maximum shieldable amount. When usable candidates exist, it is `usable_balance_credits`, which still includes the fee reserve; the actual maximum is `max_shieldable_credits` after subtracting that reserve. When no usable candidate exists, `available` is the entire account balance even though the maximum is zero. The current message can therefore tell the user that an amount is shieldable when the planner will reject it. Use operation-neutral guidance or carry and display the planner's actual maximum instead.
- [SUGGESTION] src/backend_task/error.rs:437-442: Use operation-neutral wording for asset-lock input-limit errors
  `AssetLockTooManyInputs` is emitted by the shared cap guard used by identity registration, identity top-up, Platform-address funding, shielding, and direct asset-lock paths. Its message describes every failure as a transfer to Platform and calls the transaction a deposit, which is incorrect for several of those operations and gives the user the wrong explanation. Keep this shared variant operation-neutral, or introduce operation-specific variants before displaying it.

Comment thread src/wallet_backend/payments.rs Resolved
Comment thread src/backend_task/error.rs Resolved
Comment thread src/backend_task/error.rs Resolved
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Non-inline finding (send_core_to_core rejecting against the display snapshot): fixed in b767c89 + 08c7e29. send_core_to_core() no longer checks the amount against the display-only snapshot. The pooled dry run in WalletBackend::send_payment (ensure_core_payment_builds) is the only affordability check, and it refuses a real shortfall with a typed InsufficientFunds before any prompt; that message now states both amounts in DASH. Tests: core_send_is_not_refused_by_the_display_balance, insufficient_funds_message_states_amounts_in_dash.

🤖 Co-authored by Claudius the Magnificent AI Agent

@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 complete PR diff correctly implements the reviewed Max, shielding, asset-lock, and DPNS fee changes. The remaining non-atomic Exact asset-lock input-cap gap is accurately documented and tracked by dashpay/platform#5513; no new in-scope issues were found. Clippy and policy checks passed, while the Test Suite was still running in the supplied CI snapshot.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(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); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: 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 large and intricate diff changes wallet payment construction, coin selection, asset-lock funding, shielding limits, and pre-signing fee validation in src/wallet_backend/payments.rs and related backend tasks, directly affecting funds movement and transaction acceptance.
  • Phase 1 reviewers: not run (disabled for this repository)
  • 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 xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, 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 the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@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.

CI failed after approval — commit e025d91

The standing review approved this commit; this follow-up moves the verdict to COMMENT: checks that failed after the review look related to this change.

Failing checks:

Why they look related: The failing test is send_screen::routes_core_wallet_to_core_address, and the PR substantially changes Core send routing and wallet payment construction in src/ui/wallets/send_screen.rs and src/wallet_backend/payments.rs. Its failure reports that the offline Core wallet has no spendable snapshot balance, indicating a plausible regression in the changed send behavior or its test fixtures.

Nothing was re-reviewed: the findings of the standing review are unchanged. The next push gets a full review; a re-run that passes does not restore the approval.

Review provenance

Source: CI-check lane gpt-6.1-sol (agent: triage); no reviewer or verifier lanes ran for this follow-up

  • Verdict moved because CI failed on this commit after the review; failure logs read: 1 GitHub Actions job(s)

@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)

One blocking stale-cache issue remains in Platform-to-shielded Max handling. The selected Platform address snapshot is not refreshed when live balances change, so Max can remain higher than the current planner limit and fail during the actual shield operation. CI checks for this head are successful.

🔴 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 is a large, intricate diff that directly changes funds movement and coin-selection behavior in wallet payment, asset-lock, shielding, and username-registration flows, including transaction finalization and fee enforcement in src/wallet_backend/payments.rs and related 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/ui/wallets/send_screen.rs`:
- [BLOCKING] src/ui/wallets/send_screen.rs:896-900: Invalidate Platform shielding Max when live balances change
  The spend-limit revision is calculated from the balances captured in `selected_source`, but that vector is only rebuilt when the user selects the Platform source. Live `platform_address_info` is updated both by explicit balance fetches and by `PlatformAddressSyncPushed`; the latter is applied by `AppState` without being delivered to this screen, and `refresh_form_inputs` only clears the address-input signature. After a balance decreases, the cached planner quote can therefore remain higher than the wallet's current `shielded_shield_preflight` maximum. Max then offers an amount that the shield operation rejects after opening the wallet session, violating the PR's goal that Max match what the builder accepts. Derive the revision from the current wallet Platform-address snapshot or rebuild/invalidate the selected source whenever Platform balances are refreshed.

Comment thread src/ui/wallets/send_screen.rs Resolved

@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 PR improves builder-derived Max values and username fee validation, but two blocking issues remain. Core Max does not account for UTXOs reserved by another in-flight build, and the new regression tests commit deterministic wallet seeds and a plaintext password. The username pagination and user-story documentation issues are non-blocking; CI Test Suite and Clippy checks are still in progress.

🔴 2 blocking | 🟡 3 suggestion(s)

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

🟡 Suggestion: Update user-story acceptance criteria for dynamic username fees and builder-quoted Max
docs/user-stories.md:852-855

DPN-001 still documents only the fixed base community vote fee and omits the separate name-admission reserve, although the implementation now quotes the current crowded-contest fund, rejects full contests, and checks the reserve. SND-014 still says Core Max is the balance minus an estimated fee, while this PR changes it to an upstream pooled-builder quote that accounts for account pools, fees, and input limits. Update the acceptance criteria to describe the shipped behavior.

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); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate change that directly modifies wallet payment construction, coin selection, asset-lock funding, shielding, and transaction fee handling in src/wallet_backend/payments.rs and related backend tasks, all of which affect funds movement.
  • 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/payments.rs`:
- [BLOCKING] src/wallet_backend/payments.rs:661-669: Invalidate Core Max when wallet reservations change
  The Core Max quote calls upstream `pooled_max_sendable`, whose pinned implementation explicitly does not model UTXOs reserved by another in-flight build. In contrast, `ensure_core_payment_builds` and `finalize_transaction` use reservation-aware selection. The UI keys this quote to the snapshot generation at `send_screen.rs:901-905`, but a reservation can be created or released without advancing that generation, so a previously quoted Max can remain available after another operation reserves its inputs. The subsequent real build can then fail for insufficient unreserved funds even though the UI offered Max as buildable. Add a reservation-aware quote or a reservation revision that invalidates the cached quote.
- [BLOCKING] src/wallet_backend/payments.rs:1952-1963: Do not commit deterministic wallet seeds and test passwords
  The new tests embed deterministic 64-byte HD seed material through `[seed_byte; 64]`, register those bytes as wallets, and repeat the pattern at lines 2217-2226 and 2352-2364. The cap-race test also commits the plaintext password `cap-race-password` at line 2190 and stores it in the protected seed fixture at lines 2232-2234. Repository policy forbids committing recovery seeds or passwords in source and tests, except for the separately documented historical migration fixture. Generate test credentials at runtime through test support or use a secret-free test seam instead.

In `src/backend_task/identity/dpns_usernames.rs`:
- [SUGGESTION] src/backend_task/identity/dpns_usernames.rs:141-152: Avoid contender pagination when the protocol uses a fixed contest fund
  When `username_contest_max_contenders` returns `None`, the pinned Platform implementation states that every contender pays the base fund and `required_vote_resolution_fund_to_join` does not vary with the contender count. This code still performs proved contender pagination up to the configured limit and propagates any pagination failure as an availability-check failure. Return the fixed base fund immediately on those protocol versions; only count contenders when the active protocol both varies the fund and enforces a contest cap.

In `src/ui/wallets/send_screen.rs`:
- [SUGGESTION] src/ui/wallets/send_screen.rs:3118-3125: Do not expose zero shield capacity as a usable Max amount
  When the shield planner reports `can_shield == false`, `spend_limit_credits` returns `Some(0)`, and this branch passes that value to `AmountInput`. The Max button then fills the field with zero, while `validated_send_route` rejects zero amounts. The associated capacity error also tells the user to use Max even though no positive amount is available. Treat a zero quote as no available Max and use zero-capacity guidance instead.

In `docs/user-stories.md`:
- [SUGGESTION] docs/user-stories.md:852-855: Update user-story acceptance criteria for dynamic username fees and builder-quoted Max
  DPN-001 still documents only the fixed base community vote fee and omits the separate name-admission reserve, although the implementation now quotes the current crowded-contest fund, rejects full contests, and checks the reserve. SND-014 still says Core Max is the balance minus an estimated fee, while this PR changes it to an upstream pooled-builder quote that accounts for account pools, fees, and input limits. Update the acceptance criteria to describe the shipped behavior.

Comment thread src/wallet_backend/payments.rs Resolved
Comment thread src/wallet_backend/payments.rs Resolved
Comment thread src/ui/wallets/send_screen.rs Resolved
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Docs finding (non-inline) addressed in 0321c6d: docs/user-stories.md DPN-001 now describes the live fund to join a username vote (0.2 DASH before protocol 14; 0.1 DASH from 14, doubling at 250 requests and every 50 more), the full-vote refusal, the name-admission reserve and the re-quote on Pay. SND-014 now describes Core Max as the pooled send build's own quote (pooled transparent accounts, inputs held by another send left out, fee and input cap included), checked by the same build rather than the displayed balance.

🤖 Co-authored by Claudius the Magnificent AI Agent

@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 PR improves builder-derived fee and Max calculations, but three blocking freshness races remain: Core Max and asset-lock Max can outlive local UTXO reservations, and Platform-to-shielded sending still validates against a stale source-selection balance list. Clippy and Test Suite checks were still in progress in the supplied CI snapshot, with no failed code check reported.

🔴 3 blocking

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

🔴 Blocking: Use live Platform balances for the shield send preflight
src/ui/wallets/send_screen.rs:2194-2203

The shielding Max quote is keyed from the wallet's live Platform balances, but this preflight still sums the addresses vector captured when the Platform source was selected. A sync or balance update can increase an existing balance or add an address while the form remains open; the planner then returns a valid larger Max, but clicking Send rejects it locally against the stale total and never reaches the backend planner. Read the current Platform-address snapshot for this guard or remove the gross-balance check and let the planner remain authoritative.

let total_available: u64 = self
    .get_platform_addresses()
    .into_iter()
    .map(|(_, _, balance)| balance)
    .sum();

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

1 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: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.1-sol (effort low) — This is a large, intricate change that directly modifies wallet payment construction, coin selection, asset-lock funding, shielding, and username-registration fee handling in files such as src/wallet_backend/payments.rs and src/backend_task/identity/register_dpns_name.rs.
  • 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 — 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/ui/wallets/send_screen.rs`:
- [BLOCKING] src/ui/wallets/send_screen.rs:901-905: Invalidate Core Max when wallet reservations change
  The Core Max cache is keyed by the wallet snapshot generation, but creating or releasing a reservation for another in-flight build does not advance that generation. The quote is reservation-aware when created, yet a later reservation can remove inputs that the quote relied on; pressing Send then reaches the reservation-aware dry run and rejects the previously offered Max as unaffordable. Track reservation ownership in the quote revision or perform an authoritative reservation-aware check immediately before accepting the amount.
- [BLOCKING] src/ui/wallets/send_screen.rs:2194-2203: Use live Platform balances for the shield send preflight
  The shielding Max quote is keyed from the wallet's live Platform balances, but this preflight still sums the `addresses` vector captured when the Platform source was selected. A sync or balance update can increase an existing balance or add an address while the form remains open; the planner then returns a valid larger Max, but clicking Send rejects it locally against the stale total and never reaches the backend planner. Read the current Platform-address snapshot for this guard or remove the gross-balance check and let the planner remain authoritative.

In `src/wallet_backend/payments.rs`:
- [BLOCKING] src/wallet_backend/payments.rs:732-796: Invalidate asset-lock Max when wallet reservations change
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4366962036)
  The asset-lock Max quote is validated against the published asset-lock input composition, but local reservations created by another in-flight build are not included in that cache key unless a new wallet snapshot is published. A quote made before another Core payment or asset lock reserves its inputs can therefore remain available as Max. The later cap guard treats insufficient-funds results as acceptable because the exact builder is responsible for reporting shortfalls, so the upstream exact-amount build can fail after the wallet has been unlocked. Include reservation state in the quote revision or perform a reservation-aware buildability check immediately before entering the secret/build path.

Comment thread src/ui/wallets/send_screen.rs Resolved
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Addressed the two remaining freshness findings (not shown inline).

  • Asset-lock Max (bc24a48, eccd0c0, fe00d8b): the same per-wallet reserving-operation revision is stamped into the asset-lock input composition every quote must match. It advances on entry, at the hand-off to the upstream build and on exit, so a quote made before another build reserves or releases inputs is withdrawn and re-quoted. The cap guard no longer waves a shortfall through: its reservation-aware dry run refuses it with a typed InsufficientFunds before the wallet is unlocked, and again right before the build. Tests: a_reserving_operation_invalidates_both_max_quotes, an_unaffordable_asset_lock_is_refused_before_unlocking.

  • Platform→Shielded preflight (bd20358): the send form no longer checks the amount against the balances captured at source selection. shield_from_balance asks the shield planner before opening the secret session, so an amount above its maximum is refused with the typed capacity error (stating the maximum, or that nothing can be shielded) before any prompt. Tests: shield_from_platform_send_is_not_refused_by_the_captured_balances, a_shield_above_the_planner_maximum_is_refused_before_unlocking.

🤖 Co-authored by Claudius the Magnificent AI Agent

@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 current head fixes the previously reported Core, shielding, DPNS, messaging, and secret-fixture issues, but asset-lock Max quotes can still become stale after the upstream build takes reservations. Core Max is also conservative for accepted P2SH destinations because the quote always prices a synthetic P2PKH output. Test Suite and Clippy checks were still in progress in the supplied CI snapshot.

🔴 1 blocking | 🟡 1 suggestion(s)

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

🔴 Blocking: Asset-lock operations do not invalidate Max quotes after reservations are taken
src/wallet_backend/identity_ops.rs:811-817

The revision is advanced at spend.mark() immediately before the upstream asset-lock call, but it is not advanced again when that call actually acquires reservations. For fund_from_asset_lock, upstream first validates recipients and only later enters resolve_funding_with_is_timeout_fallback, where the Core inputs are selected and reserved; the same hand-off pattern is used by identity registration, identity top-up, create_asset_lock_proof, and shielding from an asset lock. A concurrent Max request can therefore start after spend.mark(), obtain the wallet-manager lock and quote against the new revision before the asset-lock build reserves its inputs. That quote remains current while those inputs are unavailable because the next revision change is only the guard drop after the operation completes, potentially after broadcast and proof finality. The UI can consequently offer a Max value that the subsequent builder rejects. The revision must be advanced or otherwise made invalid for the entire reservation hand-off, or the quote must be prevented from completing while a reserving operation is between its hand-off and reservation acquisition.

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); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 6: 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 is a large, intricate change that directly modifies wallet payment construction, coin selection, asset-lock funding, shielding, fee calculation, and signing-related preflight paths in files including src/wallet_backend/payments.rs and src/backend_task/wallet/mod.rs, all of which govern funds movement.
  • Phase 1 reviewers: not run (disabled for this repository)
  • 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 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, gpt-6.1-sol — general (completed, effort xhigh); agent phase2-reviewer, gpt-6.1-sol — 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/wallet_backend/identity_ops.rs`:
- [BLOCKING] src/wallet_backend/identity_ops.rs:811-817: Asset-lock operations do not invalidate Max quotes after reservations are taken
  The revision is advanced at `spend.mark()` immediately before the upstream asset-lock call, but it is not advanced again when that call actually acquires reservations. For `fund_from_asset_lock`, upstream first validates recipients and only later enters `resolve_funding_with_is_timeout_fallback`, where the Core inputs are selected and reserved; the same hand-off pattern is used by identity registration, identity top-up, `create_asset_lock_proof`, and shielding from an asset lock. A concurrent Max request can therefore start after `spend.mark()`, obtain the wallet-manager lock and quote against the new revision before the asset-lock build reserves its inputs. That quote remains current while those inputs are unavailable because the next revision change is only the guard drop after the operation completes, potentially after broadcast and proof finality. The UI can consequently offer a Max value that the subsequent builder rejects. The revision must be advanced or otherwise made invalid for the entire reservation hand-off, or the quote must be prevented from completing while a reserving operation is between its hand-off and reservation acquisition.

In `src/wallet_backend/payments.rs`:
- [SUGGESTION] src/wallet_backend/payments.rs:1225-1232: Quote Core Max against the actual destination script
  The reservation-aware Core Max search always builds a synthetic P2PKH recipient. The UI accepts both P2PKH and P2SH Core addresses, and the real `core_payment_builder` prices the concrete destination script. A P2SH output has a smaller output script than P2PKH, so the quoted Max is lower than the amount the real build can accept for a P2SH destination. Because the spend-limit cache key contains only the wallet, operation kind, and revision—not the destination—the same conservative quote can also survive a change between Core destination addresses. Pass the validated destination/output shape into the quote and cache key, or explicitly use and test a documented conservative bound for all supported Core address kinds.

Comment thread src/wallet_backend/payments.rs Resolved
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator Author

Re the non-inline finding on identity_ops.rs:811-817 (asset-lock Max between hand-off and reservation): agreed that hand-off marks left a window, because upstream reserves inputs at an instant DET cannot observe. Fixed in 1605450 + 551b652 by withholding Max for the whole span instead. While any operation that can reserve a wallet's Core inputs is open (send, direct asset lock, identity registration and top-up, Platform-address funding, shielding from an asset lock), neither Core send Max nor asset-lock Max is quoted: both return a typed SpendInProgress outcome immediately, with no dry run and nothing cached as current. The forms offer no Max and say the available amount is shown again when the transaction finishes. An explicit amount is still accepted: it gets the network-fee minimum check locally, then the backend's reservation-aware dry run and the build decide. When the operation closes, the wallet's revision moves and the forms quote afresh; a quote that started just before an operation opened carries the earlier revision and is discarded. There is no timer. Tests: no_max_is_quoted_while_a_reserving_operation_is_in_flight, core_send_offers_no_max_while_another_transaction_is_in_progress, asset_lock_balance_cache_offers_nothing_while_another_transaction_is_in_progress, an_explicit_asset_lock_amount_is_sent_while_another_transaction_is_in_progress.

🤖 Co-authored by Claudius the Magnificent AI Agent

@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 PR substantially aligns Max and fee calculations with the upstream builders and resolves the prior quote, reservation, balance, contest, wording, and fixture findings. One blocking correctness issue remains: after a successful Platform-to-shielded operation, the cached Platform-address balances used for the next Max quote are not refreshed, so Max can remain stale and the next shield can be rejected by the upstream planner. Clippy and Test Suite checks were still in progress at the captured head.

🔴 1 blocking | 🟡 1 suggestion(s)

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

🔴 Blocking: Refresh Platform balances after a successful Platform-to-shielded operation
src/backend_task/shielded/mod.rs:144-160

The successful ShieldFromBalance path refreshes only the shielded balance snapshot. The send form keys SpendLimitKind::ShieldFromPlatform to live_platform_balances_revision(), which hashes the cached per-address balances in wallet.platform_address_info; neither this task nor the upstream shield operation updates that cache after the source balance is consumed. Until the next Platform-address sync, the revision can remain unchanged and the cached Max quote can still be offered. A subsequent Max shield can then reach the upstream planner with a stale amount and be rejected. After confirmed success, refresh the authoritative Platform-address state and its DET snapshot, or invalidate/withhold Max until that refresh completes; the refresh must be best-effort so it cannot turn a completed shield into a retryable failure.

source: gpt-6.1-sol (phase2-reviewer: general, rust-quality)

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.1-sol (agent: phase2-reviewer, role: general); reviewer 4: 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 is a large, intricate change that directly modifies wallet coin selection, transaction construction, fee calculation, asset locking, shielding, and username-registration payments in src/wallet_backend/payments.rs and related backend task code, all of which affect funds movement.
  • Phase 1 reviewers: not run (disabled for this repository)
  • 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 xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, 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/shielded/mod.rs`:
- [BLOCKING] src/backend_task/shielded/mod.rs:144-160: Refresh Platform balances after a successful Platform-to-shielded operation
  The successful `ShieldFromBalance` path refreshes only the shielded balance snapshot. The send form keys `SpendLimitKind::ShieldFromPlatform` to `live_platform_balances_revision()`, which hashes the cached per-address balances in `wallet.platform_address_info`; neither this task nor the upstream shield operation updates that cache after the source balance is consumed. Until the next Platform-address sync, the revision can remain unchanged and the cached Max quote can still be offered. A subsequent Max shield can then reach the upstream planner with a stale amount and be rejected. After confirmed success, refresh the authoritative Platform-address state and its DET snapshot, or invalidate/withhold Max until that refresh completes; the refresh must be best-effort so it cannot turn a completed shield into a retryable failure.

In `src/wallet_backend/payments.rs`:
- [SUGGESTION] src/wallet_backend/payments.rs:1284-1296: Preserve typed insufficient-funds errors when pooled finalization reports no UTXOs
  `map_core_finalize_error` maps `CorePooledInsufficientFunds` to the actionable `TaskError::InsufficientFunds` only when both `available` and `required` are present. The pinned upstream finalizer emits the same variant with `available: Some(0)` and `required: None` for `NoUtxosAvailable`, so a normal finalization race can fall through to the generic `WalletBackend` error. Add a typed insufficient-funds variant that does not require both figures, or map the missing-value form to an equivalent actionable error instead of losing the classification.
Out-of-scope follow-up suggestions (3)

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.

  • Make the asset-lock input-cap check atomic with the real build — The cap guard and the upstream exact-amount asset-lock build still use separate wallet-manager lock acquisitions, so a concurrent spend or sync can change input selection between the final guard and the build. The DET limitation is explicitly tracked by dashpay/platform#5513, and the current PR adds the closest available second check before the upstream call.
    • Follow-up: Resolve dashpay/platform#5513 so exact-amount asset-lock builds enforce the input cap inside the same serialized operation.
  • Avoid synchronous asset-lock observation from wallet event callbacks — SnapshotStore::recompute performs an unbounded asset-lock input observation at lines 925-933, and EventBridge::on_wallet_event calls it directly. For wallets with many UTXOs this can consume substantial CPU in the synchronous callback and delay subsequent wallet events. Move the observation off the callback path or replace it with an incremental bounded publication mechanism.
    • Follow-up: Track as a separate wallet-event performance follow-up.
  • Do not hold the wallet-manager write lock while waiting for spawn_blocking capacity — The asset-lock and Core quote paths acquire the wallet-manager write guard before enqueueing spawn_blocking work. If Tokio's blocking pool is saturated, the queued task can retain the wallet-manager lock while waiting for a worker, and the probe deadline starts only after the closure begins. This can delay unrelated wallet-manager operations beyond the intended probe timeout.
    • Follow-up: Refactor the quote probes so blocking-pool queueing does not occur while holding the wallet-manager write guard.

Comment thread src/wallet_backend/payments.rs Resolved
@lklimek
lklimek marked this pull request as draft October 26, 2026 20:07
@lklimek
lklimek marked this pull request as draft October 26, 2026 20:07
lklimek and others added 11 commits October 26, 2026 21:42
…ername

DPNS contract v3 picks the first preorder of a name, and Platform admits
the name document only while the balance also holds the chooseFirst scan
budget (0.001 DASH) on top of the fee. The registration guard and the
confirm step now ask for it, read from the platform version and only when
the contract declares chooseFirst, so a low balance is turned away before
the preorder is paid for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 8c16867)
…nput cap

The asset-lock Max probe priced BIP-44 account 0 alone while the real
build pools BIP-44, BIP-32 and DashPay-receiving funds, and it stopped
only at the 500-input standard-transaction limit although Dash Core
relays at most 100 asset-lock inputs. The probe and its composition key
now cover the pooled accounts, a dry run above the protocol's
max_asset_lock_transaction_inputs counts as unbuildable, and every
exact-amount asset lock is refused with a typed error before building
when it would need more inputs than that.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 953de07)
The Max for shielding from Platform addresses was the balance minus a
one-fee headroom, while the upstream planner orders addresses, drops
inputs below the minimum, caps their count and keeps twice the fee on
its fee-paying input. A Max could therefore name an amount the planner
refuses. The send screen now asks the backend for the planner's
preflight quote (a new spend-limit query with a small per-screen cache)
and offers nothing until it arrives; the fee hint uses the planner's
reserve, and a shield above the planner's capacity surfaces as a typed
error instead of the generic wallet failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1675025)
…x upstream

Core sends were built from BIP-44 account 0 alone while their Max came
from UI arithmetic over the whole-wallet snapshot, so funds in BIP-32 or
DashPay receiving accounts could not be sent and Max could name an
amount no build reaches. Payments now go through platform-wallet's
atomic finalize_transaction with SEND_FUNDING_SOURCES (CoinJoin
excluded, change back to BIP-44) and broadcast_finalized_transaction,
and Max is upstream's pooled_max_sendable through the spend-limit query.
A dry run of the same pooled build runs before signing so shortfalls and
too-many-inputs refusals stay typed and never prompt for a passphrase.
The UI-side Max helpers are removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 5073008)
From protocol 14 a contest's fund doubles once it holds 250 requests and
again for every 50 more, and a request stating less is turned away after
its preorder was already paid for. The availability check now quotes
the fund to join through the SDK's paged contender count, the review
and consent show that amount, and the backend re-quotes it before any
document is sent and refuses a stale approval as changed terms. The
generic contested document cap now uses its contest's own base fund,
the moderation fund for a moderation election.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit bac64a7)
From protocol 14 a contest accepts at most max_contenders_per_contest
requests and turns any further one away after its preorder was paid.
DET counts the vote's requests in proved pages, reports a full vote in
the live availability check, and refuses registration before anything
is sent with a dedicated UsernameContestFull error. The cap comes from
the platform version's limit table and applies only where the network's
create validation enforces it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 4c31933)
…dable

The send form refused a Core payment whenever it exceeded the display-only
balance snapshot, even though Max now comes from the live pooled quote. A
lagging or not-yet-populated snapshot could reject the very amount Max had
just offered. The backend's pooled dry run already refuses a real shortfall
with a typed error before any prompt, so the form no longer second-guesses it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
(cherry picked from commit b767c89)
`AssetLockTooManyInputs` comes from the shared cap guard that identity
registration, identity top-up, Platform-address funding, shielding and
direct asset locks all go through, yet its message called every refusal a
transfer to Platform and the transaction a deposit. It now names no single
operation, only the input counts and how to fix it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
(cherry picked from commit af79e7d)
…city

Upstream's capacity refusal reports the usable balance with the fee reserve
still in it, or the whole account balance when no address can keep the
reserve back, and the banner presented that figure as the most the user
could shield. Shielding from Platform now intercepts the refusal, takes a
fresh plan and states its `max_shieldable_credits` (zero when nothing can
be shielded). Without a plan the refusal keeps the generic envelope rather
than guessing a number.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
(cherry picked from commit 907b0cb)
The input-cap guard ran once, before the secret session, and then released
the wallet-manager lock. The wallet could change while the user typed the
password, so an amount that fit the cap could reach the upstream exact-amount
builder needing more inputs than an asset lock may carry. Upstream would then
build and broadcast a lock Dash Core drops, with its inputs left reserved.

Every asset-lock path (direct locks, identity registration and top-up,
Platform-address funding, shielding) now runs the guard a second time
inside the session, immediately before the upstream call. The pre-session
check stays, so a doomed lock still never prompts. True atomicity needs
upstream: it takes the wallet-manager lock itself and builds and broadcasts
in one call, and its cap check covers only drain builds. That gap is
recorded as a TODO at the guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
(cherry picked from commit f4e302b)
With the send form no longer pre-checking the display balance, the pooled
build's `InsufficientFunds` is the message a user sees for an unaffordable
Core send. It quoted raw duff counts; it now shows both amounts in Dash and
offers a smaller amount as well as adding funds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ujJpB9DBhvtbjhYB3aG9Q
(cherry picked from commit 08c7e29)
@github-actions github-actions Bot removed the waiting-self-review Waiting for the author to post /self-reviewed label Nov 4, 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)

Core Max still offers relayable amounts below the form's hard-coded minimum, so clicking Max can leave Send disabled. The reservation-expiry cache issue remains a non-blocking upstream follow-up without linked tracking; the live DPNS balance check and final destination-dust guard are fixed. Static verification only: Clippy now passes, while Test Suite remains pending.

🔴 1 blocking | 🟡 1 suggestion(s)

1 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 large, intricate changes in src/wallet_backend/payments.rs directly alter funds movement and coin selection by pooling funding sources, finalizing Core sends, and enforcing asset-lock input limits.
  • 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/ui/wallets/send_screen.rs`:
- [BLOCKING] src/ui/wallets/send_screen.rs:3158-3159: Align the Core amount minimum with the builder-quoted Max
  This branch offers every positive Core quote, but `min_output_amount()` still requires 5,460 duffs for Core-to-Core sends. The backend now publishes relayable quotes down to the destination's dust threshold, which is 546 duffs for P2PKH. For example, a single spendable 5,000-duff P2PKH coin can quote a Max of 4,808 duffs with a 192-duff fee. Clicking Max fills that value, but `AmountInput::validate_amount()` rejects it against the higher minimum; the component response clears `self.amount`, leaving Send disabled. This contradicts the new builder-quoted Max contract even though the UI minimum predates the PR. Derive the Core minimum and quote eligibility from one shared model policy using the upstream destination rules, and add a UI regression for a positive, relayable Max below 5,460 duffs.

In `src/wallet_backend/mod.rs`:
- [SUGGESTION] src/wallet_backend/mod.rs:2925-2928: Invalidate Core Max when wallet reservations change
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4466881202)
  The upstream-owned signal is the appropriate fix: both the pinned and current key-wallet implementations keep `ReservationSet` private and expose no reservation-expiry revision for DET to consume. However, expiry still changes what the builder can spend without changing this quote key. With otherwise unchanged spendable coins, a residual reservation swept after 24 blocks leaves `SpendLimitCache` retaining its reduced Max or `Unavailable` result; the unavailable branch also has no Retry control. This only under-offers and remains non-blocking. Link a follow-up covering the key-wallet/platform-wallet expiry signal and its DET consumer before recording the deferral as tracked; the supplied PR discussion currently links none. No local reservation mirror is needed.

Comment thread src/ui/wallets/send_screen.rs Resolved
The send form required a fixed 5,460 duffs for a Core payment while the
backend quotes any relayable Max down to the destination's dust
threshold, so a Max like 4,808 duffs filled an amount the field refused
and left Send disabled. CoreDestinationScript::dust_threshold_duffs
(upstream's dust rule) is now the one minimum for both the form and the
backend's Max guard.

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.

@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 Core dust-policy fix and the earlier fee, live-balance, and active-operation reservation fixes are confirmed. One blocking mismatch remains: a positive Platform-to-Shielded Max below 500,000 credits is offered but rejected by the amount field; passive Core reservation expiry also remains an untracked, non-blocking follow-up. This was a static verification only; Clippy and Test Suite were still pending in the current CI checks.

🔴 1 blocking | 🟡 1 suggestion(s)

1 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 large, intricate changes in src/wallet_backend/payments.rs directly alter pooled coin selection, transaction finalization and broadcasting, and asset-lock input limits, meeting the critical funds-movement bar.
  • 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/ui/wallets/send_screen.rs`:
- [BLOCKING] src/ui/wallets/send_screen.rs:3201-3202: Accept small positive Platform shielding Max quotes in the amount field
  This branch offers every positive planner quote, but min_output_amount() applies the transparent Platform-address output minimum of 500,000 credits to Platform-to-Shielded sends. At the pinned upstream revision, an address holding the shield reserve plus 100,000 credits produces a Max of 100,000 credits: the planner accepts that positive claim, the execution path adds the fee to input 0 separately, and ShieldTransitionV0::validate_structure requires a positive shield amount rather than the transparent-output minimum. Clicking Max therefore fills an amount that AmountInput::validate_amount() rejects, clearing self.amount and leaving Send disabled. Define the operation-specific minimum in the shared model policy using the upstream shield rules, and add a UI regression that clicks Max for a positive quote below 500,000 credits. This is separate from the fixed zero-capacity case.

In `src/wallet_backend/mod.rs`:
- [SUGGESTION] src/wallet_backend/mod.rs:2925-2928: Invalidate Core Max when wallet reservations change
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4466881202)
  The key combines pooled coin composition and DET spend activity, neither of which changes when an otherwise unchanged coin becomes selectable after a residual reservation expires. Both the pinned and supplied default key-wallet sources keep ReservationSet private and expire entries after 24 blocks; SpendLimitCache retains a loaded or unavailable result for the unchanged key, and unavailable results offer no Retry control. Your upstream-ownership explanation is correct: DET should consume an expiry/revision notification from key-wallet/platform-wallet rather than duplicate reservation bookkeeping. This safely under-offers and can be deferred, but the supplied discussion and PR description do not link a tracker covering that upstream signal and DET's consumption of it. Link that follow-up so the limitation is a tracked deferral.

Comment thread src/ui/wallets/send_screen.rs Resolved
…nt field

The form held Platform-to-Shielded sends to the 500,000-credit minimum
of a transparent Platform-address output, so a smaller planner quote
filled an amount the field refused. Upstream's shield transition and
planner only require a positive amount. SpendLimitKind::min_amount_credits
is now the one minimum for every backend-quoted Max: the Core payment's
dust threshold, or one credit for a shield from Platform.

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.

@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 current head fixes the previously reported amount-minimum, live username-balance, and fee-multiplier defects, but introduces a received-deposit validation bypass while the wallet is busy. Three non-blocking suggestions remain concerning reservation-expiry recovery and quote-path performance. Verification was static only: no builds or tests were run; Test Suite and Clippy remain pending, and the Platform pin guard passed.

🔴 1 blocking | 🟡 3 suggestion(s)

1 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.1-sol (agent: phase2-reviewer, role: general); reviewer 4: 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 large, intricate changes in src/wallet_backend/payments.rs directly alter pooled coin selection, transaction finalization and broadcasting, and asset-lock input limits, meeting the critical funds-movement bar.
  • Phase 1 reviewers: not run (disabled for this repository)
  • 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 xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, 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/ui/identity/add_new_identity_screen/mod.rs`:
- [BLOCKING] src/ui/identity/add_new_identity_screen/mod.rs:1127-1142: Preserve the deposit-address limit when the wallet is busy
  This branch handles both UseWalletBalance and ReceiveDeposit, but the busy exception removes the deposit-address limit as well as the unavailable builder ceiling. current_validation_ceiling_duffs() returns None before intersecting the quote with funding_address_balance_duffs, and asset_lock_amount_refusal(..., None, ...) checks only the network minimum. The receive-deposit renderer explicitly keeps the field editable while busy and clears its maximum. Consequently, a user with a 0.1 DASH deposit and additional wallet funds can enter 0.2 DASH and dispatch it while another operation is in progress. FundWithWallet carries no deposit-address restriction, so the pooled backend can fund the request from unrelated wallet funds. This also contradicts the received-deposit boundary documented in SND-017. Preserve the known deposit-address ceiling independently of the optional builder quote, using the shared model amount policy even while Max is withheld. Add a busy ReceiveDeposit regression with an explicit amount above the deposit balance; the existing deposit-bound regression covers only a loaded quote.

In `src/wallet_backend/payments.rs`:
- [SUGGESTION] src/wallet_backend/payments.rs:1370-1375: Reuse a pooled funding snapshot across Core Max probes
  Every candidate in largest_core_payment_at_most reaches this call and clones all resolved ManagedCoreFundsAccount values again. At the pinned key-wallet revision these clones copy the address pools, UTXO maps, transaction bookkeeping, and spent-output collections; only the reservation set is shared. Reservation-aware narrowing can therefore repeat a full funding-state copy dozens of times while holding the wallet-manager write lock, consuming the five-second search budget on historical state unrelated to selection and delaying other wallet work. Prepare scratch funding accounts once per quote and reuse them across candidates, with a fixed change address and the existing owner-guarded reservation release so probe reuse does not advance the scratch change pool.

In `src/ui/wallets/send_screen.rs`:
- [SUGGESTION] src/ui/wallets/send_screen.rs:963-971: Avoid rebuilding formatted address lists for each quote-cache lookup
  spend_limit_target calls this helper during status rendering, Max rendering, and request scheduling, so an unchanged Platform-to-Shielded form repeats the work several times per frame. get_platform_addresses takes the wallet read lock, Bech32m-encodes every tracked Platform address, allocates a string-keyed deduplication map, and sorts the result; this helper then allocates another vector just to hash the addresses and balances. These repeated encodings and allocations run on the egui thread even when the cached quote is valid. Maintain a balance revision alongside wallet updates, or compute the canonicalized fingerprint once per frame and share it across quote lookups, preserving live-balance invalidation.

In `src/wallet_backend/mod.rs`:
- [SUGGESTION] src/wallet_backend/mod.rs:2925-2928: Invalidate Core Max when wallet reservations change
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4466881202)
  The upstream ownership constraint is confirmed: key-wallet's ReservationSet and its height-based expiry observation remain crate-private at both the pinned rust-dashcore revision and current dev tip. Nevertheless, this key contains only pooled-coin state and DET spend activity, neither of which necessarily changes when a residual reservation expires after 24 blocks. SpendLimitCache retains loaded and unavailable answers for that unchanged revision, and the unavailable state has no inline Retry control, so a reduced or unavailable Max can persist after the coins become selectable again. An explicit recheck could reuse the existing reservation-aware backend without mirroring reservations. If recovery remains deferred to an upstream revision/expiry API, link a tracking issue covering the owning key-wallet/platform-wallet API and its DET consumer; the supplied thread and PR description explain the limitation but provide no tracking reference.

Comment thread src/wallet_backend/payments.rs Resolved
Comment thread src/ui/wallets/send_screen.rs Resolved
…llet is busy

Withholding Max while another transaction is in progress also dropped
the deposit address bound, so a received-deposit registration could be
dispatched above the deposit and funded from other wallet coins. Only
the wallet-wide ceiling now waits for the quote; the deposit balance
still bounds the amount.

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 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)

At the assigned head, the received-deposit regression is fixed, but the new quote probes still omit platform-wallet's persistent pending-spend fences and can offer a Max that the real finalizer rejects. Four nonblocking concerns remain around repeated quote work, reservation-expiry invalidation, and discarded builder diagnostics. Clippy passed; Test Suite failed with disk-exhaustion errors, so it does not establish a passing test gate. No local builds or tests were run.

🔴 1 blocking | 🟡 4 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); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: 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 large, intricate changes in src/wallet_backend/payments.rs directly alter pooled coin selection, transaction finalization, and broadcasting for funds movement, meeting both critical-tier requirements.
  • Phase 1 reviewers: not run (disabled for this repository)
  • 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 xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, 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/payments.rs`:
- [BLOCKING] src/wallet_backend/payments.rs:1380-1386: Quote through platform-wallet's full spending policy, including pending-spend fences
  This dry run proves key-wallet buildability, but not acceptance by the real platform-wallet finalizer. At the pinned Platform revision, `CoreWallet::finalize_transaction_with_options` additionally checks `info.generation.in_broadcast_conflict(&unsigned)` and returns `InputMidBroadcast` for fenced inputs (`packages/rs-platform-wallet/src/wallet/core/transaction.rs:733-755`). An ambiguous or cancelled broadcast retains those fences until an observed spend; they do not expire with key-wallet's 24-block reservations. After a reservation expires, a fresh quote can therefore build successfully against a still-fenced coin and publish Max, while the actual send rejects it after opening the secret session. The operation-lifetime guard has already closed and cannot represent this pending-spend state. Asset-lock probes omit the same policy, which upstream's real asset-lock builder also enforces. Expose and consume a read-only quote/admissibility operation from platform-wallet, where reservations and fences are owned, rather than duplicating another part of its spending policy in DET. Add a regression comparing a fresh quote with real finalization after an unobserved dispatch outlives its key-wallet reservation.
- [SUGGESTION] src/wallet_backend/payments.rs:1400-1402: Preserve unexpected builder errors during the Core Max search
  The `.ok()` conversion makes every builder failure look like an amount that is too high. This discards unexpected failures such as `BuilderError::NoChangeAddress`, not just funding or input-count rejections. If no candidate succeeds, `core_send_search_outcome()` reports `HeldByPendingTransaction`; the screen then caches that unavailable result without a Retry control, and the original diagnostic is lost. The asset-lock search already distinguishes expected rejection outcomes from unexpected errors. Return a source-preserving `Result` here, narrow only on known funding/input-limit variants, and propagate other failures so the quote enters the retryable failed state. Add coverage that an unexpected builder error is not relabelled as a reservation shortfall.
- [SUGGESTION] src/wallet_backend/payments.rs:1370-1375: Reuse a pooled funding snapshot across Core Max probes
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4467732955)
  Every candidate clones the resolved funding accounts again under the wallet-manager write lock. The pinned `ManagedCoreFundsAccount` derives `Clone` over address-pool, transaction, UTXO, and spent-output state; only its reservation set is shared. Even an unnarrowed quote performs the proof build and a separate all-coins drain, while reservation narrowing can repeat the deep copy many more times. The five-second deadline is checked between candidates, so it does not bound an individual clone/build or the subsequent drain. Prefer a reusable quote/funding-snapshot primitive in platform-wallet; any interim scratch-account reuse must preserve owner-guarded reservation release and avoid advancing its change pool. Please link the proposed performance follow-up.

In `src/ui/wallets/send_screen.rs`:
- [SUGGESTION] src/ui/wallets/send_screen.rs:963-971: Avoid rebuilding formatted address lists for each quote-cache lookup
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4467732963)
  `spend_limit_target()` is reached by status rendering, Max rendering, and request scheduling, including frames with a valid cached quote. Each Platform-shield lookup calls `get_platform_addresses()`, which holds the wallet read lock while encoding addresses and constructing a string-keyed deduplication map, then sorts and allocates the result; this helper allocates another vector before hashing it. Backend quote caching does not avoid this recurring egui-thread work. Maintain a balance revision with wallet updates, or compute and share one fingerprint per frame while preserving live-balance invalidation. The proposed performance follow-up has no linked tracker in the supplied discussion; please link one if this remains deferred.

In `src/wallet_backend/mod.rs`:
- [SUGGESTION] src/wallet_backend/mod.rs:2925-2928: Invalidate Core Max when wallet reservations change
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4466881202)
  The quote revision hashes pooled outpoints, values, spendability, and DET operation activity, but none changes solely because key-wallet sweeps an aged reservation. When an abandoned, unfenced reservation expires with otherwise unchanged coins, `SpendLimitCache::ensure_requested()` retains the reduced quote or `HeldByPendingTransaction` outcome until another invalidation; unavailable outcomes offer no Retry control. Consume an authoritative reservation/admissibility revision or expiry notification from key-wallet/platform-wallet rather than maintaining a DET reservation mirror. That signal must also respect platform-wallet's longer-lived pending-spend fences: reservation expiry alone does not make an ambiguously broadcast input safe to spend. This remains a nonblocking under-offering case, but the proposed upstream-dependent deferral needs a linked tracking issue.

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

Dismissed by maintainer decision: the remaining blocker (Max quote vs. platform-wallet's broadcast fence) is rejected as an edge case with no double-spend risk — #1107 (comment); the suggestion moves to #1112.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review

No review for 2d990793 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

@thepastaclaw review

No review for 2d990793 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 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 Nov 5, 2026
@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 the ready-for-human Bots have reported, the author has self-reviewed, and the build is green: this needs a human. label Nov 5, 2026
@Claudius-Maginificent Claudius-Maginificent added the priority: high High priority — address soon label Nov 5, 2026
@lklimek

lklimek commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

@thepastaclaw please re-review this pr

@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 head 2d99079 against the base and relevant pinned/current upstream sources; the prior affordability, dust, amount-minimum, and live-balance defects are addressed. Six non-blocking findings remain concerning quote admissibility, reservation-expiry invalidation, unexpected builder errors, and avoidable cloning/allocation. This was static verification only: current Test Suite, Clippy, and Platform pin guard checks pass; PR Hygiene remains pending.

🟡 6 suggestion(s)

5 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.1-sol (agent: phase2-reviewer, role: general); reviewer 4: 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 diff changes funds movement and coin selection in src/wallet_backend/payments.rs, including pooled funding sources, transaction finalization, send limits, and asset-lock input enforcement.
  • Phase 1 reviewers: not run (disabled for this repository)
  • 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 xhigh); agent phase2-reviewer, gpt-6.1-sol — rust-quality (completed, effort xhigh); agent phase2-reviewer, 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/snapshot.rs`:
- [SUGGESTION] src/wallet_backend/snapshot.rs:983-987: Avoid eagerly deep-cloning the funding pool on every snapshot event
  `AssetLockFundingPool::from_wallet` clones every resolved funding account before `try_asset_lock_final_input_state` attempts its observation try-lock. At the pinned key-wallet revision, these clones copy address pools, transaction bookkeeping, UTXO maps, and spent-output collections; reservation state is shared. On contention, all those copies are discarded. On success, `observe_asset_lock_inputs_locked` clones each managed account again for its scratch builder. This adds a full-pool copy to ordinary EventBridge snapshot recomputation while the wallet-manager read guard is held, even when no Max query is running. Acquire the observation try-lock before preparing scratch state and pass borrowed pooled accounts so observation needs only its existing per-account scratch clone.

In `src/wallet_backend/payments.rs`:
- [SUGGESTION] src/wallet_backend/payments.rs:1380-1386: Quote through platform-wallet's full spending policy, including pending-spend fences
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4468128348)
  This dry run establishes key-wallet buildability, but the real platform-wallet finalizer additionally checks `info.generation.in_broadcast_conflict(&unsigned)` and can reject the same inputs with `InputMidBroadcast`. That distinction exists in both the pinned and current upstream implementations, including the real asset-lock build path. After a retained reservation expires, a quote can therefore succeed while finalization refuses it after secret access. The finalizer prevents a conflicting broadcast, so this is not a funds-safety blocker. Also, the reservation clock can advance during historical catch-up; the scenario does not necessarily require waiting for 24 newly mined blocks. Track a read-only quote/admissibility API in dashpay/platform and consume it here, rather than adding another DET mirror of private spending policy. The Known limitations entry currently has no tracking link for this API gap.
- [SUGGESTION] src/wallet_backend/payments.rs:1401-1402: Preserve unexpected builder errors during the Core Max search
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4468128360)
  Calling `.ok()` turns every `BuilderError` into an unaffordable candidate, including failures unrelated to funding or input limits. If no probe succeeds, the outcome becomes `HeldByPendingTransaction`, which is cached without the failed-state Retry control, and the original diagnostic is discarded. The scope comment on #1112 explicitly tracks the repair, but this error-classification defect is introduced by this PR's new search and remains present on this head. Return a source-preserving result, narrow only on expected funding/input-limit failures, and propagate unexpected errors into the retryable quote-failure state. This remains non-blocking because the conversion can suppress Max but cannot publish an unproven amount.
- [SUGGESTION] src/wallet_backend/payments.rs:1370-1375: Reuse a pooled funding snapshot across Core Max probes
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4467732955)
  Every candidate reconstructs and clones the pooled funding accounts while the wallet-manager write lock is held. Those derived clones copy historical account state as well as UTXOs, so reservation-aware narrowing can repeat a full-pool copy many times. The deadline preserves conservative results, but it is checked between candidates and cannot interrupt a clone or build; the subsequent `pooled_spendable_coins` drain also runs under the same lock after the search. Prepare reusable scratch funding accounts once per quote, with a fixed change address and owner-guarded reservation release, to avoid repeatedly copying unchanged history. The proposed performance follow-up currently has no tracking link.

In `src/wallet_backend/mod.rs`:
- [SUGGESTION] src/wallet_backend/mod.rs:2925-2928: Invalidate Core Max when wallet reservations change
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4466881202)
  The quote revision combines the pooled coin fingerprint with DET spend activity, but neither changes when a residual key-wallet reservation reaches its 24-block TTL while the coins remain otherwise unchanged. `SpendLimitCache::ensure_requested` retains loaded and unavailable results for the same revision, so a reduced Max or `HeldByPendingTransaction` can survive after the reservation stops restricting selection. The reservation set remains private in both pinned and current key-wallet, so an upstream reservation revision/expiry signal is the appropriate solution, not another DET reservation mirror. This only under-offers and is non-blocking; link an upstream issue and the DET follow-up, or provide an explicit quote-retry escape hatch.

In `src/ui/wallets/send_screen.rs`:
- [SUGGESTION] src/ui/wallets/send_screen.rs:963-971: Avoid rebuilding formatted address lists for each quote-cache lookup
  (existing thread: https://github.com/dashpay/dash-evo-tool/pull/1107#discussion_r4467732963)
  Live-balance invalidation is correct, but every shield quote lookup obtains its revision by rebuilding the display address list. `get_platform_addresses` holds the wallet read lock while Bech32m-encoding addresses, building a string-keyed deduplication map, and sorting; this helper then allocates another vector solely for hashing. Status rendering, Max rendering, and request scheduling repeat that work on the egui thread even when balances and the cached quote are unchanged. Maintain a revision with wallet updates or compute a canonical fingerprint once per frame and share it across lookups, preserving the existing freshness behavior. The proposed performance follow-up currently has no tracking link.

Comment thread src/wallet_backend/snapshot.rs Resolved
@github-actions

github-actions Bot commented Nov 5, 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 Nov 5, 2026
@lklimek
lklimek enabled auto-merge (squash) November 5, 2026 13:21
@lklimek
lklimek merged commit 32f8ede into v1.0-dev Nov 5, 2026
24 of 26 checks passed
@lklimek
lklimek deleted the feat/wallet-max-send-limits branch November 5, 2026 13:23
@Claudius-Maginificent Claudius-Maginificent added priority: medium Medium priority and removed priority: high High priority — address soon labels Nov 5, 2026
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: medium Medium priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants