Repository navigation
fix(platform-wallet-storage): restore UTXOs into the account that derives them - #5780
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
| Layer / File(s) | Summary |
|---|---|
Update owner explanation and test packages/rs-platform-wallet-storage/src/sqlite/load_ctx.rs |
The explanation now describes routing an address to its deriving funds account, with the first funds account as a fallback. The logging test expectation matches the revised wording. |
Estimated code review effort: 1 (Trivial) | ~2 minutes
Change: Bug fix
Suggested reviewers: thepastaclaw
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
[
#5724] SQLite rehydration resolves UTXOs against funds-account pools and retains the fallback for unreached coins. The PR reports tests for a CoinJoin coin beyond the stored window, UTXO preservation, fallback, and replay without duplicate balance accounting. The focused diff was truncated; the PR summary and test description support the assessment.
Full details: Out of Scope Changes check
-
Explanation
[
#5724] Pool discovery, refill bounds, fallback handling, tests, and the orphaned-owner explanation support correct UTXO restoration. No unrelated change is identified in the available summary and diff.
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 100.00% which is sufficient. 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 1 functions across 1 files.
-
Finishing Touches
-
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.
|
✅ Final review complete — no blockers (commit db58864) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Script-based restoration fixes the main ownership problem, but discovery still misses a boundary CoinJoin coin without a stored owner, and the new sequencing can lose spent-address anchors or restore previously used addresses as available. These are confirmed against the reviewed head and pinned key-wallet source. Current CI checks pass; this was a static review, and the reported checks do not include a dedicated Rust storage test result.
🔴 2 blocking | 🟡 2 suggestion(s) | 💬 1 nitpick(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
💬 Nitpick: Update the orphaned-owner explanation for derivation-based placement
packages/rs-platform-wallet-storage/src/sqlite/load_ctx.rs:167-169
OrphanedUtxoOwner::explanation still says unavailable owners are routed to the first funds account. This PR instead attempts placement in the account deriving the address and uses the first account only as the last resort. Because this explanation is included in the warning's message field and exposed to callers, update it to describe derivation-based placement with first-account fallback.
source: muse-spark-1.3-contributor (phase1-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: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: platform-versioning); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 7: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The intricate changes to apply_persisted_core_state and its restoration helpers in packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs alter address derivation and UTXO ownership, directly determining which accounts can select and spend restored funds. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— platform-versioning (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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 `packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:447-455: Keep spent-address discovery and used-state restoration in the same fixed point
The initial marking rounds finish before this horizon walk, but the walk receives only unmatched live UTXOs, and the subsequent restore never revisits persisted spent addresses. With a fresh BIP44 external pool covering 0–29, an ownerless spent address at 30 and an ownerless unspent coin at 45, the initial rounds find neither address. The walk probes only 45, stops at horizon 30, and ultimately inserts the coin without deriving its address; selecting it then fails with the missing-derivation-path error in wallet/core/transaction.rs. Reversing the roles exposes the privacy regression: an unspent coin at 30 grows the pool through 60, but the spent address at 45 remains available because neither later pass marks it. The final membership check incorrectly treats that address as resolved, and key-wallet's next_unused can return it again. The base passed both addresses through the same derive-and-mark operation and handled both cases. Include persisted used addresses in bounded horizon discovery, then continue marking, refilling and UTXO matching until all phases are stable. Add regressions for both boundary-anchor arrangements and for a spent-address bridge to a deeper coin.
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:445-449: Run bounded ownership discovery beyond the fallback account
Grouping unmatched coins by fallback_account preserves the ownership failure for a lone coin on another account's discovery boundary. For example, start with BIP44 and CoinJoin accounts, CoinJoin generated through index 99, and a single CoinJoin coin at index 100 without a pool row. Even when its address is supplied in used_pool_addresses, the initial marking and upstream restore cannot reach it. This code then probes only BIP44 because the stored owner is absent; the second restore still cannot match it, and the final insertion parks it in BIP44. It cannot be spent there, and replaying its funding transaction can credit CoinJoin while leaving the misplaced copy counted. Index 100 is within the existing probe's inclusive CoinJoin horizon, so this is not an arbitrary deep-sparse address requiring an unbounded scan; it also matches the index ≥100 reproduction in #5724. Probe unmatched addresses against every candidate funding account before using stored-owner/first-account fallback, while retaining the existing derivation bounds. Add a regression with a lone ownerless CoinJoin coin at index 100, rather than relying on an earlier coin to extend CoinJoin.
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:635-637: Report refill-preflight refusals through the load policy
is_ok_and discards the typed ImpliedRefill failure, and an oversized refill also becomes only false. Both callers can consequently skip restoration without applying Strict policy or recording the refused pool in Recovery. The assertion that the extension helper already reported every refusal is not guaranteed: that helper visits only accounts receiving attributed addresses or fallback coins, while this check includes every funding and contact-external pool. For example, a caller of the public apply_persisted_core_state API can supply a contact pool with gap_limit = 0 and an ordinary shallow BIP44 coin; the preflight refuses the contact pool, but no extension call reports it, so Strict can return success and Recovery records no refill failure. Preserve the error and account/pool coordinates and route previously unreported refusals through LoadCtx without duplicating reports. Add tests through apply_persisted_core_state for both policies; the existing guard fixtures call the older extension helper directly and do not cover this path.
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:491-497: Avoid quadratic unresolved-address checks and repeated account-list allocations
Each unattributed used address performs a linear placed.contains lookup over the fallback UTXO addresses. With U historical used addresses and M unmatched coins, this adds O(U × M) address comparisons during startup. Addresses surviving that filter also call all_funding_accounts(), which allocates a new Vec on every iteration. Collect fallback addresses into a HashSet once and obtain the funding-account list once outside the filter. This preserves the diagnostic semantics while removing the quadratic membership scan and repeated allocations.
In `packages/rs-platform-wallet-storage/src/sqlite/load_ctx.rs`:
- [NITPICK] packages/rs-platform-wallet-storage/src/sqlite/load_ctx.rs:167-169: Update the orphaned-owner explanation for derivation-based placement
OrphanedUtxoOwner::explanation still says unavailable owners are routed to the first funds account. This PR instead attempts placement in the account deriving the address and uses the first account only as the last resort. Because this explanation is included in the warning's message field and exposed to callers, update it to describe derivation-based placement with first-account fallback.
Out-of-scope follow-up suggestions (1)
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.
- Complete the tracked DashPay contact-pool restoration fix — Contact-external pools remain excluded from persisted used-address marking and funding-owner lookup. Spent contact addresses can therefore reload as available, legitimate contact owners can be reported as orphaned, and unmatched contact coins can still fall into a funding account. These funding-only limitations predate this change and are explicitly tracked by #5548 and the linked #5549.
- Follow-up: Complete the existing follow-up PR #5549, retaining coverage for contact address reuse and for contact-owned coins staying outside the wallet's funding balance.
|
Nitpick, 🤖 Posted autonomously by Claude on behalf of pasta. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Verified head 23b484d against the source and pinned key-wallet implementation: four prior findings are fixed, but the combined used-address/UTXO restoration invariant remains incomplete for supported public-API inputs. A live-coin refill can expose a spent address after marking has stopped, leaving it available for reuse and preventing discovery of a reachable deeper coin. This was a static review; current reported CI checks pass, including Kotlin SDK build and tests, and no local builds or tests were run.
🔴 1 blocking
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: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The intricate changes in rehydrate.rs::apply_persisted_core_state and its discovery helpers change UTXO ownership and address derivation restoration, directly determining which coins each account can select and spend. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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 `packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:581: Keep spent-address discovery and used-state restoration in the same fixed point
(existing thread: https://github.com/dashpay/platform/pull/5780#discussion_r4481824844)
The added boundary and bridge regressions address the earlier examples, but an in-window live coin can still extend a pool after its last used-address marking pass. Start with BIP44 external indices 0–29, no stored owners, a live coin at 20, and only spent address 45 in `used_pool_addresses`. Because `wanted` contains only 45, the marking loop finds nothing and exits. The final nonempty `restore_utxos` then marks 20 and derives through 50, leaving 45 available rather than used. `outside_funds_pools` excludes 45 because it is now derived, so discovery and the second marking pass are skipped; Strict succeeds without an unresolved-address diagnostic, and the address remains eligible for reissuance. Adding another live coin at 70 also leaves that coin without a derivation path: discovery probes only index 51, whereas marking spent address 45 would refill through 75 and reach the coin. The SQLite loader's spent-and-unspent union masks this case, but the public API explicitly promises to union live UTXO addresses with supplied used-state and does not require callers to duplicate them. Include live addresses in this marking set so UTXO-driven growth and spent-address marking stabilize together, and add regressions with `used = {spent45}` and live coins at 20, then at 20 and 70.
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
All five prior findings are fixed at e4d0433, but Recovery still turns an unrelated pool's refill refusal into guessed ownership for coins whose scripts are already known. A non-blocking upstream follow-up remains for the combined restoration and checked-refill API. This was a static review: current visible CI checks pass, while the reported Rust test results were not independently reproduced.
🔴 1 blocking | 🟡 1 suggestion(s)
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The intricate changes to apply_persisted_core_state and address-pool discovery in packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs change UTXO ownership reconstruction and key-derivation matching, directly affecting coin selection and spendability. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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 `packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:628-632: Preserve known UTXO ownership when recovery cannot refill another pool
A refill refusal does not mean every coin's owner is unknown. Reuse `with_unrefillable_contact_pool` under Recovery, but supply an ownerless CoinJoin coin at index 50 instead of the existing test's shallow BIP44 coin. CoinJoin already contains that script, and this loop marks its address used. The unrelated contact pool's zero gap then makes `gap_refills_bounded` return false, so this return labels the CoinJoin coin unmatched and disables further restoration. The caller consequently inserts it into the first funding account, BIP44, at lines 495–498. That account cannot derive its key, and replaying the funding transaction can credit CoinJoin without removing the misplaced BIP44 copy—the ownership and double-counting failure this PR is intended to fix.
Keep refill failure distinct from ownership mismatch. Provide or use a placement path that preserves ownership established by already-derived scripts without growing refused pools, preferably in key-wallet so account precedence and duplicate removal remain authoritative there. Apply stored-owner/first-account fallback only to genuinely unmatched coins, and add a Recovery regression with an unaffected CoinJoin coin; the current recovery test misses this because its coin already belongs to the fallback account.
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:628-638: Track bounded, used-address-aware restoration in key-wallet
The adapter now coordinates a second restoration fixed point around key-wallet: it matches persisted used/live addresses against newly derived pool entries, invokes empty `restore_utxos` calls for refill side effects, inspects pool growth for convergence, and performs bounded discovery. The new whole-wallet preflight also relies on `ImpliedRefill` mirroring `AddressPool::maintain_gap_limit`'s private target arithmetic. Both the pinned and supplied default key-wallet revisions still accept only UTXOs in `restore_utxos`, compute refill targets with unchecked arithmetic, and expose no shared checked refill plan. These mechanisms therefore compensate for missing capabilities in dashpay/rust-dashcore rather than SQLite-specific behavior.
Track a focused upstream extension that accepts persisted used addresses alongside UTXOs, owns their combined restoration fixed point, and exposes checked refill planning or structured pool-specific failures. Keep SQL attribution, the storage allocation budget, and `LoadCtx` policy translation here. The linked rust-dashcore#1295 supplies coin placement, while Platform#5723 concerns pool persistence; neither covers these remaining capabilities. A linked upstream issue or follow-up PR satisfies this non-blocking ownership follow-up.
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The six prior code defects are fixed, and the remaining upstream API work is tracked in dashpay/rust-dashcore#1350. One ownership defect remains for overlapping receiving/contact pools at different depths: discovery can establish funds-account ownership without reconsidering a coin already placed in a contact account, leaving it excluded from the balance. Static verification covered the exact head; current GitHub checks pass, but no local builds or tests were run.
🔴 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: architecture-layering); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The intricate changes to apply_persisted_core_state and its discovery/refill helpers in rehydrate.rs alter UTXO ownership and address derivation, directly affecting key handling, spendability, and subsequent coin selection. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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 `packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:466-471: Reconsider already-matched coins after discovery grows funds pools
Discovery can change the authoritative owner of a coin that the first restoration already matched, but this second restoration submits only unmatched coins. With overlapping DashPay receiving and reverse-contact accounts, let the input receiving pool contain indices 0–9 while the contact pool already contains index 10, and restore an ownerless coin at index 10 with its address in the used set. The pinned key-wallet's `befriend_both_ways` fixture confirms that these accounts legitimately derive the same scripts. The first restoration places the coin in the contact account and returns no unmatched coins. Discovery then finds and marks index 10 in the receiving account, but `pending` is empty, so the second restoration never re-evaluates the coin. Upstream `restore_utxos` reassigns and removes copies only for supplied coins; its empty calls do not revisit existing account UTXOs. Consequently, the coin remains in the contact account and `update_balance` excludes it even though the receiving account now derives its script. This path requires neither a refill refusal nor Recovery policy.
After discovery grows the pools, resubmit the complete original unspent set so key-wallet can apply its authoritative precedence and duplicate removal again, or defer final placement until discovery finishes. Add a Strict regression with overlapping receiving/contact pools at different depths and assert that the receiving account ultimately holds the coin and the wallet balance includes it.
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
Static verification of the complete diff at 7c6a5e9 confirms that the seven prior code findings are fixed and the upstream API follow-up remains tracked. One non-blocking gap remains: contact-address marking can trigger a refill that bypasses the new allocation preflight. All currently listed CI checks pass, including Kotlin SDK build/tests; no local builds or tests were run, and the listed checks do not independently establish Rust storage-crate test results.
🟡 1 suggestion(s)
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 7: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — The intricate changes in rehydrate.rs::apply_persisted_core_state and its discovery/refill helpers change UTXO ownership and address/key derivation used to determine which account can select and spend restored funds. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh final gate: an independent Phase-2 review ran after iterative findings were reconciled
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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 `packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs`:
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs:651-655: Check contact-pool refill bounds after script-based marking
The checked marking rounds visit only funding accounts, but this final `restore_utxos` call also marks matching scripts in DashPay contact accounts and refills those pools. The preceding preflight therefore checks their old `highest_used`, not the value the refill will use. For example, a caller-supplied contact pool with `gap_limit = 1_000_000`, `highest_generated = Some(999_999)`, `highest_used = None`, and a matching coin at index 999,999 passes the preflight with zero implied generation. Pinned key-wallet then marks that index and derives another million addresses without consulting `MAX_REHYDRATION_GAP_REFILL` (250,000). This bypasses the allocation guard added here and can allocate hundreds of megabytes during load. Normal SQLite loading starts from default-gap skeletons, so this is non-blocking defensive hardening rather than a demonstrated normal-load failure. Include script-matched contact addresses and their pool growth in the checked fixed point, or make final placement refill-free after all permitted growth has been checked. Add Strict and Recovery regressions where marking the coin makes an initially acceptable contact pool exceed the refill budget; another preflight before this call would still inspect the pre-marking state.
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
…ives them Rehydration placed each stored UTXO through its pool-row owner and fell back to the first funds account. A CoinJoin coin past the stored pool window had no pool row, so it landed in BIP44, where it counted in the balance but could not be signed, and a rescan then counted it a second time in CoinJoin. Restore the UTXO set with ManagedWalletInfo::restore_utxos instead: mark the used addresses no row attributes in every funds account, grow each pool to its gap until nothing new matches, then place each coin by script. Coins no account derives within its gap get the old horizon walk, are restored by script once more after every walk, and only the rest go to their stored owner or the first funds account. Used addresses that no funds account derives keep the degraded-load count. The marking rounds look up each derived address once, and a restore that failed is not run again, so its failure is reported once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nds pool After the marking rounds, the horizon walk probed only unmatched coins, and only in their fallback account. That missed two cases: - A spent address past the pool. It could not bridge to a coin past it, which was then parked without its derivation path. In the reverse arrangement, a coin past the pool brought back a spent address past it as unused, so `next_unused` could hand it out again. - A lone coin past another account's pool, such as CoinJoin index 100. It was parked in BIP44, where it can't be signed for. Every address no funds pool holds, whether a coin's or a used one's, is now probed in every funds account. Each probe reaches one index past what the pool holds and a gap limit past each find, within the existing derivation ceiling. What a probe derives is marked, refilled and matched again until a pass derives nothing. Refill-preflight refusals now go through the load policy with their typed error and pool coordinates, once per pool. This covers pools no extension visits, such as a contact pool. The unresolved-address count uses one hash set over the fallback and used addresses instead of a linear scan per address. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r orphaned owners Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… discovery Used addresses whose pool row names a funds account went only to that account's extension, which probes one window from index 0. A deeper one behind a shallower address with no row came back unused once a later refill derived it, and could block the way to a coin past both. Every stored used address now joins the marking rounds and the discovery past the pools, whatever owner its row names. The owner's extension no longer reports addresses it cannot resolve: discovery may still resolve them, so the load counts what stays outside every funds pool once, at the end. Past each find the probe now reaches one index beyond the window the refill after it opens, which is where a repeated pass would look, so a single pass replaces the loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A funds pool past the refill cap is refused by its owner's extension and again by the pre-flight before the restore. Recovery must count it once, which only the refusal set they share guarantees. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nds account A wallet with no funds account has no pool to mark a used address in, and no earlier load counted one for it. Since every stored used address joined the discovery, such a wallet reported each as unresolved. Collect them only when a funds account exists. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ll derives The marking rounds looked only for the stored used addresses, then the final restore marked the live coins and refilled past them. A spent address that refill derived was never marked, and a deeper coin it led to stayed unreached. The public API takes a used set that need not hold the live coins' addresses, so the SQLite loader's union only masked it. The rounds now look for the coins' addresses too, so coin and spent address growth reach one fixed point before the final restore. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ixed point The rounds stopped once a round marked nothing, even when that round's refill had derived addresses no round had looked up. After discovery, which marks its finds without refilling, that is the first round of the second restore. Past the discovery ceiling those addresses are new, so the final restore matched a coin there, refilled past it and left a spent address unused, and a coin past that fell back to an account that cannot sign for it. The rounds now also continue while a refill grew a funds pool past what they looked up. A later round that marks nothing refills nothing, so this adds at most one round per call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ot run When a gap refill is refused (an unrefillable pool anywhere in the wallet) or a restore fails, restore_owned_utxos returned every coin unmatched, so the caller parked coins whose script an account already holds in their stored owner or the first funds account. A CoinJoin coin could land in BIP44, which cannot sign for it, and a later replay could credit CoinJoin next to that copy. Those exits now place the held coins with key-wallet's restore_utxos run against the same wallet without its accounts: no pool has a key source, so the refill skips every pool and nothing is derived, while the match by script, the account precedence, the used marking, the copy removal and take_in_output stay key-wallet's. Only the coins no account holds are returned for the fallback and counted unresolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…used refill After a refused or failed refill, place_held_coins matches coins only against the pools as far as the marking rounds grew them, so a coin a DashPay contact account already holds lands there, outside the balance. Say so at the helper and where the caller claims the wallet total is exact. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first restore can place a coin by script in a DashPay contact account when the funds account that shares the script (the receiving account of a friendship between two of the wallet's identities) has not derived it yet. Discovery then derives it in the funds account, but the second restore was offered only the unmatched coins, so the coin stayed in the contact account, outside the balance. This happens under Strict too. Discovery now looks for the address of every coin no funds pool holds, not only the unmatched ones, and when it derives anything the second restore is offered every coin. restore_utxos then moves such a coin to the first account holding its script and removes the contact copy; a coin already in its account is taken in again in its own place with its flags, so it is held and credited once. The fallback and the unresolved count still see only what the last restore left unmatched. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each of the four loads (Strict and Recovery, with and without the coin's address in the used set) gets its own test, so each fails on its own before the fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…uld run The final restore_utxos marks each coin's script in every pool holding it, DashPay contact pools included, then refills those pools. The marking rounds visited funds pools only and marked coins by their stored address, so a contact pool, or a funds pool holding a coin's script under another stored address, could be refilled from a mark no bound had seen: a pool whose gap limit is past MAX_REHYDRATION_GAP_REFILL would derive that many addresses. The rounds now also mark the address each coin's script pays, in the funds pools and in the contact pools, and look up what a contact pool's refill derives. Every refill therefore passes gap_refills_bounded first, and the final restore marks nothing new and derives nothing. Placement is unchanged: the rounds only mark. Unit tests use a smaller refill budget, so a test that crosses it stays cheap. The two-holder precedence test keeps its contact pool unrefillable by an out-of-range gap limit, since the coin's mark now makes a gap of 0 refillable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7c6a5e9 to
28fb7e8
Compare
|
/self-reviewed 28fb7e8 |
|
Waiting for bot review — coderabbitai 1 thread unresolved — resolve it · thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
changed base to v5.2-dev, v5.1-dev is feature-freeze. |
|
/skip-bots pastaclaw won't re-review on a base merge. |
|
@thepastaclaw review No review for |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The current implementation correctly performs bounded fixed-point restoration, preserves script-derived ownership during recovery, and re-evaluates all persisted UTXOs after discovery. No new in-scope defects were found, and the wallet test jobs succeeded; unrelated workspace jobs were skipped by package filtering.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: security-auditor); reviewer 6: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This large and intricate change modifiesapply_persisted_core_stateand UTXO rehydration/account assignment, directly affecting funds ownership, balance accounting, and key availability for spending. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer,muse-spark-1.3-contributor— rust-quality (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort xhigh); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort xhigh); agentphase2-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.
|
Bots are done — your move: post |
|
/self-reviewed db58864 |
|
Ready for review — |
|
Policy satisfied — this can merge. |
Merges develop and moves the platform pin to the current head of v5.2-dev, which adds dashpay/platform#5150 (wallet-level transaction history accounting) and dashpay/platform#5780 (restore UTXOs into the account that derives them). No Swift SDK source or SwiftData schema change in that range. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Takes the base's grovedb revision and dependency updates and keeps the rust-dashcore revision that carries the collateral lock. With that revision a coin's lock flag follows the wallet's lock set, so the restore test from #5780 locks its coin through the set. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Problem
A SQLite load puts each stored UTXO in the funds account its pool row names, and falls back to the first funds account (BIP44) when there is no row. A coin whose address lies past the stored pool window has no row. That is common for CoinJoin, which hands out addresses up to its gap of 100 past the last used one. On load such a coin lands in BIP44:
Fix
Fixes #5724. #5723 (the persister never writes the gap-extended rows) stays open, but the load no longer depends on those rows.
apply_persisted_core_statenow hands the UTXO set to key-wallet'sManagedWalletInfo::restore_utxos(dashpay/rust-dashcore#1295):A coin that no account derives within its gap gets the existing horizon walk. Once every walk is done, those coins are restored by script once more, and only the rest go to their stored owner, or else to the first funds account, as before. Used addresses that no funds account derives keep the
UnresolvedUtxoAddressdegraded-load count.The marking rounds look up each derived address once: the first round checks every address the pools hold, and each later round only the ones the previous refill derived.
A pre-flight bound check (
MAX_REHYDRATION_GAP_REFILL) runs before every refill, so a corrupt pool can't make the load run long or panic. The marking rounds also mark the address each coin's script pays, in the funds pools and in the DashPay contact pools, so every refill passes that check and the finalrestore_utxosmarks and derives nothing new. A restore that fails isn't run again, soRehydrationMaintainGapLimitcounts that failure once.apply_persisted_core_statekeeps its signature.Base
#5729 has merged (46c26cb), and this branch is rebased onto v5.1-dev. Its rust-dashcore pin (dashpay c9aeac0d) already contains dashpay/rust-dashcore#1295 (2ddafdfe3), which provides
restore_utxos. This branch carries no pin change of its own.Tests
New
tests::restore_ownedinrehydrate.rs:Fail-first: with the first eight of these tests on the rehydrate at #5729's earlier head (105aae2), 5 fail. That file differs at 70abc13 only by unused test imports, removed upstream and here. Three coins land in BIP44 instead of CoinJoin, the rescan test counts 400004000 duffs instead of 200002000, and the stale-owner coin stays in CoinJoin while BIP44 derives it. The three guard tests (every load the same, the unreached coin counted once, the stored-owner fallback) pass on both, as does the contact-coin guard.
The refill-budget regressions fail on 7c6a5e9, where the load succeeds after an unchecked contact-pool refill.
Locally on 28fb7e8 (rust-dashcore c9aeac0d):
cargo test -p platform-wallet-storage --lib rehydrate: 76 passed;cargo test -p platform-wallet-storage: 1045 passed, 0 failed, 3 ignored;cargo clippy -p platform-wallet-storage --all-targets -- -D warnings;cargo fmt --check.The same change on the dashwallet-desktop fork pin (rust-dashcore 626c91d1 plus dashpay/rust-dashcore#1112, dashpay/rust-dashcore#1105 and dashpay/rust-dashcore#1295, cherry-picked) passes the platform-wallet, platform-wallet-storage and platform-wallet-ffi nextest: 2976 of 2977. The one failure,
sqlite_restore_cross_process_exclusion, is a file-lock timing race under machine load (RestoreDestinationLocked); that restore path doesn't reachrehydrate.rs. Rerun alone at a load near 100, it passed once in three runs.Overlap with open PRs
None of these changes
route_to_funds_account. The ones touchingrehydrate.rs:#5220 (replay recorded history on load) doesn't touch
rehydrate.rs. The rescan-once tests replay stored transactions after the restore, which is the case a load-time replay would add.🤖 Generated with Claude Code
PR Hygiene ·
db58864wallet-storage(packages/rs-platform-wallet-storage/src/sqlite/load_ctx.rs,packages/rs-platform-wallet-storage/src/sqlite/rehydrate.rs) — approved by lklimekWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit