Repository navigation
fix(platform-wallet): trust a stored record only when no other flush dropped it - #5923
QuantumExplorer wants to merge 11 commits into
Conversation
…dropped it Five places store a record, flush it on a backend that does not commit a store inline, and then act as if the record were on disk: the address reservation a contact payment stores before its broadcast, the address `reserve_payment_address` hands out, the invitation funding index, the row of a funding that pays a shielded recipient, and the record of a funded invitation voucher. A flush that succeeds proves nothing by itself: another flush of the wallet's records may take what was buffered and fail for good, dropping it, and the site's own flush then succeeds over a buffer that no longer holds the record. A restart would then pay a contact's address twice, export an invitation's one-time key twice, lose the address a shielded funding pays, or lose track of a funded voucher. Each of them now goes through `WalletPersister::store_durably`, which answers for the record only when no other flush can have dropped it. The sites that have sent nothing yet abandon what they built, as they do for a failed flush. The voucher's record is stored once more first, as the voucher is already funded, and only then reported as not persisted, with no link. `NotDurable::Backend` is split into `Store` and `Flush`, so a site keeps reporting a failed store and a failed flush the way it did. Wallet drains, the consumption-unknown marker, the cleared private payment marker, the balance retry and the manager's backfill replace are left as they are: a drain runs only where a store is the commit, and a record lost at the others is repaired by a later sync or fails closed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tform-wallet-durable-store-sites The base now answers `NotDurable::OtherFlushUnsettled` where it answered `OtherFlushInFlight`, and counts transient flush failures too. The conflict in `persister.rs` keeps the base's ledger reads with this branch's `NotDurable::Store` and `NotDurable::Flush`, and the two sites that named the old variant name the new one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
The base branch now answers `NotDurable::OtherFlushUnsettled` when another flush of the wallet's records failed transiently while the call ran and put back what it had taken, as well as when one has not returned. Neither is a lost record: a later flush writes it. Two tests pin how the changed sites treat it. A prepared contact payment whose reservation another flush took and put back sends nothing and reports a flush to be tried again (`PersisterFlush` of kind `Transient`), not a discarded round. A funded invitation's record that another flush took and put back is stored once more, and the flush that follows writes it. The comments on both sites say what the answer covers now, and an unused import in the invitation tests goes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
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
|
|
✅ Final review complete — no blockers (commit c76073b) · triage: critical |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The PR improves several wallet durability gates and the new overtaken-flush handling is generally correct. One blocking lifecycle bug remains: the shielded-recipient failure path can leave a durable resumable Built row while releasing its funding inputs, allowing recovery to rebroadcast a transaction after the caller was told the build failed. The Kotlin SDK check failed during an external Gradle action download timeout before build execution and is unrelated to this Rust-only change.
🔴 1 blocking | 🟡 2 suggestion(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Failed recipient durability can leave a resumable Built lock
packages/rs-platform-wallet/src/wallet/asset_lock/build.rs:1527-1548
store_durably can return NotDurable::Lost or OtherFlushUnsettled even when this call's asset-lock row was committed: an overlapping flush may take the buffered row, fail or remain in progress, and the row's own flush can then complete after the buffer was emptied. This branch queues the removal with queue_asset_lock_changeset, which only calls plain store and does not flush it, then abandon_unsent_build releases the transaction inputs. If the process exits before another flush, the persisted row remains Built with no proof while its inputs are reusable. Recovery explicitly treats (AssetLockStatus::Built, None) as requiring a broadcast, so a later restart can send the supposedly abandoned transaction; a retry can independently build and send another transaction with different inputs. Make the removal durable before releasing the reservation, or retain the reservation and transition the persisted row to a non-resumable/tombstoned state when durable cleanup cannot be established.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, rust-quality, security-auditor)
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 large, intricate wallet diff changes payment broadcasting, address reservation, invitation funding, and one-time key handling, directly affecting funds movement and key safety. - 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 (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-platform-wallet/src/wallet/asset_lock/build.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/asset_lock/build.rs:1527-1548: Failed recipient durability can leave a resumable Built lock
`store_durably` can return `NotDurable::Lost` or `OtherFlushUnsettled` even when this call's asset-lock row was committed: an overlapping flush may take the buffered row, fail or remain in progress, and the row's own flush can then complete after the buffer was emptied. This branch queues the removal with `queue_asset_lock_changeset`, which only calls plain `store` and does not flush it, then `abandon_unsent_build` releases the transaction inputs. If the process exits before another flush, the persisted row remains `Built` with no proof while its inputs are reusable. Recovery explicitly treats `(AssetLockStatus::Built, None)` as requiring a broadcast, so a later restart can send the supposedly abandoned transaction; a retry can independently build and send another transaction with different inputs. Make the removal durable before releasing the reservation, or retain the reservation and transition the persisted row to a non-resumable/tombstoned state when durable cleanup cannot be established.
In `packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/invitation.rs:109-113: Retry a non-transient own-flush failure before abandoning the funded invitation record
`record_funded_invitation` retries when an overlapping flush reports `Lost` or `OtherFlushUnsettled`, but not when its own `store_durably` call returns a non-transient `NotDurable::Flush`. In both cases the funded voucher can remain absent from durable Sent-invitation records, making it unreclaimable after restart. The row is keyed by outpoint, so retrying the identical changeset is idempotent; a constraint or fatal backend error can fail again without creating a duplicate. Either retry once for non-transient flush failures or document why this backend failure is intentionally definitive while the overlapping-flush cases are retryable.
In `packages/rs-platform-wallet/src/wallet/identity/network/payments.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/wallet/identity/network/payments.rs:1571-1577: Preserve typed Fatal versus Transient classification for payment-address reservations
The new `store_durably` result distinguishes a dropped buffered round (`Lost`, fatal) from a round another flush still holds or restored (`OtherFlushUnsettled`, transient). This call site converts both, along with ordinary flush failures, into `PlatformWalletError::Persistence(String)`, so Rust callers cannot inspect the typed source or retry classification. The shared prepared-payment path preserves this information as `PersisterFlush`, and the reservation path should use the same typed mapping rather than erasing the distinction and relying on a wildcard arm.
…al before releasing its inputs A funding that pays a shielded recipient is abandoned when its row is not known to be on disk. The row may be there all the same: its own flush wrote it while another flush of the wallet's records failed or was in progress beside it. The removal of the row was only queued, so a process that ended before the next flush left a Built row behind, and the restart sent a funding that had been reported as not made. The removal now goes through WalletPersister::store_durably before the inputs are released. When it is not known to be on disk either, the error says a restart may still resume the lock. The inputs are released in both cases: nothing was sent, and the reservation does not outlast a restart. Also documents why record_funded_invitation stores the record again for a flush another one overtook, but not for a store or flush of its own that the backend failed. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tform-wallet-durable-store-sites Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The shared durability checks and invitation-record retry policy are implemented consistently, and the payment-address mapping preserves its existing public error contract. One blocking lifecycle issue remains: when compensating removal of an abandoned shielded-funding row is not durable, the code still releases the inputs while the persisted Built row may remain resumable, allowing a later retry or restart to create conflicting funding.
🔴 1 blocking
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 4: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 5: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 6: 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) — This is a large, intricate Rust wallet change that directly alters funds movement, payment-address and invitation key reservation durability, and persistence behavior in asset-lock and payment flows. - 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 (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-platform-wallet/src/wallet/asset_lock/build.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/asset_lock/build.rs:1540-1559: Failed recipient durability can leave a resumable Built lock
When the initial `store_durably` fails, the code correctly attempts a durable removal of the shielded-recipient row. However, it unconditionally calls `abandon_unsent_build` even when that removal returns an error. That helper releases the selected inputs and settles the broadcast fence as released, while the row can still remain durable and be loaded as `Built` after restart. The regression test at `should_say_a_restart_may_resume_a...` confirms this exact state and then confirms that a new funding can immediately use the released inputs. A subsequent restart can resume the old Built transaction while the retry has already spent those inputs or other funds, violating the invariant that a resumable row must not coexist with re-spendable inputs. If removal durability cannot be confirmed, retain the reservation and pending fence, or persist and enforce a non-resumable terminal state before releasing them.
…le its row may outlive its removal A funding that pays a shielded recipient is abandoned before its broadcast when its row is not known to be on disk, and the row's removal is then written before the inputs are released. Where that removal was not known to be on disk either, the inputs were released all the same and the call failed with a persistence error, while a restart could still find the row and send it: a caller told the funding failed builds it again, and the restart sends the first lock beside the second. The inputs now stay reserved and fenced there, and the call returns TransactionBroadcastUnconfirmed. They are still released where the row cannot outlive the call without its removal: the removal is on disk, the backend refused the row, or the row's own flush failed and the removal's did too, the two then being kept, written or dropped together. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…tform-wallet-durable-store-sites Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
… through the shared mapping `DashPayView::store_durably` wrote out how each `NotDurable` answer becomes a wallet error. The base branch now has that mapping as `WalletPersister::classify_not_durable`, so the view calls it and the mapping lives in one place. What a caller gets back is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The normal flush-ledger race is addressed, but the shielded-recipient cleanup still releases reserved inputs when a non-atomic persistence round may have partially written the Built row. The same safety gap exists when an initial flush fails after a concurrent flush commits the row; no failed code checks are reported, with only the review check still in progress.
🔴 1 blocking
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-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: muse-spark-1.3-contributor (agent: phase1-reviewer, role: rust-quality); reviewer 6: 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) — This is a large and intricate wallet change that alters payment preparation, address reservation, invitation funding, and asset-lock handling on a critical funds-movement and key-handling surface, particularly in prepared_payment.rs and asset_lock/build.rs. - 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 (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-platform-wallet/src/wallet/asset_lock/build.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/asset_lock/build.rs:1558-1571: Non-atomic recipient persistence failure can still release inputs for a resumable shielded lock
The release arms treat `(NotDurable::Store(_), Err(_))` and `(NotDurable::Flush(_), Err(NotDurable::Flush(_)))` as proof that no Built row can survive. That proof does not follow from these error types. The FFI persistence contract permits a backend to expose `ASSET_LOCK_SHIELDED_RECIPIENTS` without `ATOMIC_CHANGESETS`; its legacy store invokes the base asset-lock callback before the recipient sidecar callback, so a later callback failure can return `NotDurable::Store` after the Built row was already persisted. If removal then fails, `abandon_unsent_build` releases the inputs even though restart can load the row and resume it. Likewise, `store_durably` returns immediately on its own flush error before consulting the flush ledger, so a concurrent flush may commit the row while the initial call returns `NotDurable::Flush`; the matching failed-flush removal arm then releases the same inputs. Require an atomic/no-partial-write guarantee before using these release cases, or conservatively retain the reservation and pending-spend fence whenever removal durability is not confirmed. Add regression coverage for a partial store that persists the row before returning an error, followed by failed removal, and for a concurrent flush that commits the row before both calls report failure.
…only once its row's removal is on disk An abandoned shielded funding still handed its inputs back, with the removal of its row not known to be on disk, where the backend had refused the row, and where the row's own flush and the removal's had both failed. Neither proves the row is gone. A host that does not roll a failed round back may have written the row before a later part of the store failed (the FFI persister calls the asset-lock callback before the recipient sidecar's), a backend that keeps a failed store or flush for later writes the row then, and a flush that failed may have run beside another that wrote it. A restart that finds the row resumes and sends it. The inputs are now released only when the removal is known to be on disk. Every other failed gate keeps the reservation, leaves the fence pending and returns TransactionBroadcastUnconfirmed. should_abort_typed_amount_funding_when_the_recipient_cannot_be_made_durable pinned the hand-back for a backend that failed the removal too. It now fails the row's store or flush once and lets the removal through, which still hands the inputs back. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
A blocking concurrency race remains in the new shielded-row cleanup path: the flush ledger detects overlapping flushes only while they are in flight or when they fail, so a successful late flush can recreate a row after its removal and after inputs are released. The FFI built-observer documentation also omits the new durability-abort outcomes, where the row may be absent in-session despite a non-rejection error. No failed code checks are present in the CI snapshot; Kotlin passed, while the Rust review check was still queued.
🔴 1 blocking
Follow-up candidates (optional) (1)
New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.
🟡 Suggestion: Observer contract does not cover durability-abort outcomes
packages/rs-platform-wallet-ffi/src/asset_lock/built_callback.rs:20-27
The callback runs at line 1514 before the shielded recipient row is durably stored. If the initial store_durably fails and the removal returns Ok(()), abandon_unsent_build releases the inputs and no track_asset_lock call occurred; the FFI funding mapper reports this persistence failure as ErrorWalletOperation, not ErrorTransactionBroadcastRejected. If removal durability is also uncertain, the result is ErrorTransactionBroadcastUnconfirmed, but the row still is not tracked in memory during this call; only a restart may reload it. Therefore the statement that every non-rejection failure leaves the lock tracked and resumable in-session is false. Update the callback contract to describe these two durability-abort cases and the possibility of ErrorAssetLockNotTracked on an immediate resume.
/// Record the outpoint before returning (durably, if it has to survive a
/// restart): the lock's row is persisted immediately after the callback. The
/// result determines whether the row is available for resume:
/// `ErrorTransactionBroadcastRejected` (26) means a tracked row was removed;
/// other broadcast failures normally leave it tracked and resumable by this
/// outpoint (a resume may find it already consumed).
///
/// Shielded funding can abort before broadcast while making its recipient row
/// durable. If row removal succeeds, the row is gone and an in-session resume
/// may return `ErrorAssetLockNotTracked`; if removal is not confirmed, the
/// result is `ErrorTransactionBroadcastUnconfirmed` (20), and a restart may
/// recover the row even though this session has not tracked it. A persistence
/// abort whose removal succeeded may be reported as `ErrorWalletOperation` (6).
/// The row store and removal are best-effort, so after a restart a failed store
/// can leave no row for a broadcast lock, or a row of a removed one.
source: muse-spark-1.3-contributor (phase1-reviewer: general)
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 is a large, intricate wallet change that alters funds movement, address reservation, shielded funding, invitation recovery, and one-time key handling across multiple persistence and concurrency paths. - 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)
- Code unchanged since the last final review (
366ef664): 1 new suggestion(s) listed as follow-up candidates, not posted inline - 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 (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `packages/rs-platform-wallet/src/wallet/asset_lock/build.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/asset_lock/build.rs:1540-1564: A successful overlapping flush can recreate the row after its removal
The `Ok(())` arm treats `store_durably` for the removal as proof that the `Built` row is gone, but `store_durably` only checks `in_flight`, `failed`, and `lost`; `FlushLedger` records no successful-flush ordering or generation. A valid interleaving is: another flush takes the original row and pauses; the row's own durability call observes that overlap and fails; the removal is queued and its flush commits the tombstone; the first flush then successfully commits the old row and returns before the removal call reads the ledger. At that point there is no failure delta and no flush in progress, so this code releases the inputs even though the old row is durable again. After restart, the `Built` row can be resumed with inputs that the wallet has already made reusable. Serialize per-wallet flushes, or add an ordering/generation check that revalidates the removal after every earlier flush has settled, and add coverage for a late successful flush.
…tform-wallet-durable-store-sites Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…ush that may hold the row is in progress An abandoned shielded funding releases its inputs once the removal of its row is known to be on disk. That removal went through `store_durably`, which answers for the removal alone. A flush still in progress may have taken the row before the removal was stored, and nothing says a backend writes what that flush took before what a later one takes: it could write the row after the removal and return before the ledger was read, and a flush that succeeded is counted nowhere. The inputs were then released with the row on disk for a restart to resume. The removal now goes through `WalletPersister::withdraw_durably`, which also refuses to answer, and flushes nothing, while a flush is in progress once the removal is stored. With none in progress then, every flush that could hold the row alone has returned, and one that begins later takes the removal with whatever of the row is still buffered. The `AssetLockBuiltFn` comment said every failure but a rejection leaves the lock tracked and resumable in the session. A shielded funding abandoned before its broadcast is not tracked, and the comment now says so. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The final Rust persistence behavior is internally consistent and no remaining blocking correctness or security defects were identified. One in-scope public callback contract remains stale in the Swift and Kotlin SDKs: it does not describe the new pre-broadcast untracked outcome; no code checks are failing in the supplied CI snapshot, although the review check is still queued.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.
Follow-up candidates (optional) (1)
New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.
🟡 Suggestion: Mirror the new pre-broadcast untracked outcome in mobile callback contracts
packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/AssetLockBuiltCallback.swift:41-51
The Swift documentation still says that every callback failure other than transactionBroadcastRejected leaves the lock tracked and resumable. The Rust callback contract now has an exception: shielded funding can invoke the callback, fail to durably persist the recipient row, and abandon the funding before tracking or broadcasting it, producing the untracked outcome (ErrorAssetLockNotTracked, code 23) or an uncertain outcome (ErrorTransactionBroadcastUnconfirmed, code 20) when row removal cannot be confirmed. Kotlin's corresponding documentation at ManagedPlatformWallet.kt:907-914 likewise says the callback cannot stop funding and that the lock is still broadcast and submitted. A host following these contracts can persist a stale outpoint and offer a resume for a lock that was never broadcast, or assume funding occurred when the result is unconfirmed. Update both public contracts and outcome guidance to document the pre-broadcast untracked case and that code 20 is resumable after restart only if the row survived.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)
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: ffi-engineer); 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); reviewer 8: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 9: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 10: gpt-6.1-sol (agent: phase2-reviewer, role: ffi-engineer); reviewer 11: gpt-6.1-sol (agent: phase2-reviewer, role: rust-quality); reviewer 12: 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 large, intricate changes in wallet payment, invitation funding, asset locking, and shielded-fund persistence directly affect funds movement and one-time key handling, including concurrency and durability races. - 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
- Code unchanged since the last final review (
88b8cba5): 1 new suggestion(s) listed as follow-up candidates, not posted inline - 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— ffi-engineer (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— ffi-engineer (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.
Basic explanation
What this does: Before the wallet sends a payment to a contact, hands out a payment address, or funds an invitation, it writes a record to disk first (which address is taken, which key index was used, who a funding pays). On a storage backend that collects writes and commits them later ("flush"), the wallet asked for a flush and trusted it when it succeeded. That is not enough: another flush of the same wallet can pick up the waiting record first and fail, which throws the record away or leaves it waiting again, and the wallet's own flush then succeeds with nothing left to write. This PR makes five such places check that no other flush can have taken their record before they go on.
Value: A contact's payment address is not paid twice after a restart, an invitation's one-time key is not exported twice, a shielded funding does not lose the address it was meant to pay, and a funded invitation does not disappear from the list it can be reclaimed from.
Risks: Low. Wallet code only, no consensus change. The Swift and Kotlin hosts commit every write when it is stored, so for them only the case at the end of this paragraph changes. On a backend that commits at flush, a send, an address reservation or an invitation that overlaps another flush of the same wallet is now refused before anything is sent and has to be tried again. One case holds funds back, on every host: a shielded funding that is abandoned because its row could not be made durable, and whose row's removal then cannot be confirmed on disk either (the backend fails twice in a row), keeps its inputs reserved until the wallet restarts and is reported as an unknown outcome, where it used to hand the inputs back. Nothing here was run against a live network.
Issue being fixed or feature implemented
Follow-up to #5908, which added the per-wallet flush ledger and
WalletPersister::store_durablyand moved one site (the marker a private contact request stores before paying) onto it. This PR is stacked on that branch and goes through the other places that store a record, flush it, and then act as if it were on disk.The case, on a backend whose
storeonly buffers:Every site that flushes a wallet's records, and what was decided for it:
network/prepared_payment.rsDashPayView::store_durably: the address reservationsend_paymentandsend_prepared_paymentstore before the broadcastnetwork/payments.rsreserve_payment_addressasset_lock/build.rsinvitation funding index (the pool stored before the broadcast)asset_lock/build.rsrow of a funding that pays a shielded recipientnetwork/invitation.rsrecord of a funded voucherasset_lock/build.rsdrain funding indices, drain row, rejected drain removal;asset_lock/operation.rscomplete_wallet_drain,persist_drain_lock_snapshotrequire_wallet_drain_persistence), so nothing is buffered and the flush only notifies the hostasset_lock/sync/tracking.rsmark_asset_lock_consumption_unknownnetwork/private_contact_requests.rsstore_private_payment_marker(clearing the marker)state/managed_identity/sync.rsretry_pending_balancemanager/mod.rssettle_published_backfill(the manager's replacement of the host's backfill record)WalletPersister::store_durablyplatform_wallet.rsflush_persistDashPayView::store_durablyis shared, so the three other stores that go through it get the same check: an address found already paid on chain (prepare_payment,send_payment, and a refusedsend_prepared_payment) and the release of a reservation whose payment was not sent. A lost mark is found again from the transaction history at the next send, and a lost release reloads the address as reserved, which skips an index and reuses nothing.What was done?
wallet/persister.rs:WalletPersister::withdraw_durably, used for the abandoned shielded funding below;store_durablybehaves as before. The split ofNotDurable::BackendintoNotDurable::StoreandNotDurable::Flush, which lets a site keep reporting a failed store and a failed flush the way it did, started here and is now in the base branch (fix(platform-wallet): keep contact request holds consistent after an unconfirmed send #5908), together withWalletPersister::classify_not_durable.network/prepared_payment.rs:DashPayView::store_durablygoes throughWalletPersister::store_durablyand reports its answer throughWalletPersister::classify_not_durable, the mapping the base branch shares with the manager. A failed store is stillPersisterStore(throughclassify_store_failure) and a failed flush stillPersisterFlushwith the backend's kind. A record another flush dropped (NotDurable::Lost) isPersisterFlushof kindFatal, the buffered round discarded. Another flush that is still in progress, or that failed and put back what it took (NotDurable::OtherFlushUnsettled), isPersisterFlushof kindTransient: the round is still buffered and a later flush writes it. Both are returned before the broadcast, with the address and the inputs released as for any failed flush.network/payments.rs:reserve_payment_addressgoes throughWalletPersister::store_durably. A failed store is stillPersisterStore; everything else is stillPersistence("failed to flush payment-address reservation: ..."). The address stays used in memory and is not handed out.asset_lock/build.rs: the invitation funding index gate and the shielded recipient row go throughWalletPersister::store_durably, with their error texts unchanged (nothing is on the wire at either point). The invitation gate aborts as it did; what the shielded row's abort now does is the next item. The drain branch of the pool gate is written out on its own and does what it did.asset_lock/build.rs, the abandoned shielded funding: a row that is not known to be on disk may still be there (its own flush wrote it while another flush failed or was in progress beside it). The removal of the row was only queued, so a process that ended before the next flush left aBuiltrow, and the restart sent a funding that had been reported as not made. The removal now goes throughWalletPersister::withdraw_durably, before the inputs are released. That isstore_durablywith one more refusal: it does not answer, and flushes nothing, while a flush is in progress once the removal is stored. Such a flush may have taken the row without its removal and may write the row after the removal, and a flush that succeeded leaves nothing in the ledger to see. With the removal on disk the inputs are released and the call fails as before. Without it nothing proves the row is gone, however its own store or flush failed: a host that does not roll a failed round back may have written the row before a later part of the store failed, a backend that keeps a failed store or flush for later writes the row then, and a flush that failed may have run beside another that wrote it. The call then returnsTransactionBroadcastUnconfirmed(asset lock ... was not sent, but its row may be on disk and the removal of that row is not known to be, so a restart may still resume it; its inputs stay reserved) and the inputs stay reserved and fenced, as after a send whose outcome is unknown. Reported as a failure with the inputs released, the funding would be built again, and where the rebuild takes other inputs a restart would send the first lock beside the second. The inputs stay held until the wallet restarts: a restart that finds the row resumes it, one that does not finds the inputs free. That is fund safety chosen over availability, and it changes one case from before this PR: a backend that fails the row and then fails its removal too used to get the inputs back.should_abort_typed_amount_funding_when_the_recipient_cannot_be_made_durablenow fails the row's store or flush once and lets the removal through, which still hands the inputs back.rs-platform-wallet-ffi/src/asset_lock/built_callback.rs, comment only: theAssetLockBuiltFncontract said every failure but a rejection leaves the lock tracked and resumable in the session. A shielded funding abandoned before its broadcast is not tracked, and the comment now says so for both of its outcomes.network/invitation.rs: the funded voucher's record moves intorecord_funded_invitation, which usesWalletPersister::store_durably. When the answer is that another flush dropped the record, still holds it or put it back, the record is stored once more (the row is keyed by outpoint, so a second copy changes nothing, and the flush that follows writes what was put back). If that fails too, the error is the one a failed flush always gave, and no link is returned.On a backend that commits a store inline,
store_durablyreturns after the store, so these five sites no longer callflushthere. The Swift host registers no flush callback and the Kotlin host's is a no-op.How Has This Been Tested?
Seventeen new tests, most of them over a backend that buffers and whose next flush is overtaken by another one. Each was run with its fix reverted and fails there.
The other flush fails for good and drops the record:
should_send_nothing_when_another_flush_dropped_a_prepared_reservationshould_send_nothing_when_another_flush_dropped_a_send_s_reservationshould_not_hand_out_a_payment_address_whose_reservation_another_flush_droppedshould_abort_an_invitation_whose_funding_index_another_flush_droppedshould_not_send_a_shielded_funding_whose_recipient_row_another_flush_droppedshould_record_a_funded_invitation_again_when_another_flush_dropped_its_recordshould_report_a_funded_invitation_unrecorded_when_another_flush_dropped_it_twiceThe other flush fails transiently and puts the record back:
should_send_nothing_when_another_flush_took_a_prepared_reservation_and_put_it_backshould_record_a_funded_invitation_another_flush_took_and_put_backshould_leave_no_row_on_disk_for_a_shielded_funding_abandoned_after_its_row_was_writtenThe removal of an abandoned row cannot be confirmed either:
should_keep_the_inputs_of_an_abandoned_shielded_funding_whose_removal_is_not_durableshould_keep_the_inputs_of_an_abandoned_shielded_funding_whose_removal_was_refused(the row's own flush fails transiently, the backend refuses the removal, and a later flush writes the row alone)should_keep_the_inputs_of_an_abandoned_shielded_funding_whose_refused_store_wrote_its_row(a host that does not roll a failed round back: the store is refused with the row on disk, and so is the removal)should_keep_the_inputs_of_an_abandoned_shielded_funding_whose_row_another_flush_wrote(another flush writes the row, the row's own flush then fails, and so does the removal's)should_report_a_typed_amount_funding_as_unconfirmed_when_its_row_removal_fails_too(throughshielded_fund_from_asset_lock, for a store and for a flush that keep failing)should_keep_the_inputs_of_an_abandoned_shielded_funding_whose_row_a_flush_in_progress_took(a flush on another thread takes the row and stalls; let go, it writes the row behind the removal)should_not_answer_for_a_withdrawal_stored_while_another_flush_has_not_returned(wallet/persister.rs:withdraw_durablyrefuses wherestore_durablyanswers)Run locally:
cargo test -p platform-wallet --libfor the touched modules (wallet::identity::network::payments,prepared_payment,invitation,contact_requests,private_contact_requests,wallet::asset_lock,wallet::persister,manager), and the same pluswallet::shieldedwith--features shieldedcargo fmt --all -- --checkcargo clippy --package platform-wallet --package platform-wallet-ffi --all-targets --all-features --locked -- --no-deps -D warningscargo check --package platform-wallet --all-targets --locked(noshieldedfeature)The full workspace suite was not run, and nothing was run against a live network.
Breaking Changes
None. No consensus change.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code