Repository navigation
feat(platform-wallet): store and commit a record in one backend step - #5955
Conversation
`WalletPersister::store_durably` stored a record and flushed it in two backend calls, and worked out from the wallet's flush ledger whether the flush had covered the store. Anything that drains the wallet's buffer can run between the two calls, and a drain the wallet did not make (a commit the host calls on the backend) is not in the ledger at all. `PlatformWalletPersistence` gains `store_and_commit`, attested by `offers_store_and_commit` (default `false`): stage a changeset behind what is buffered for the wallet and commit that buffer as one step no other drain can come between, with an answer for exactly what was staged. `StoreAndCommitError` keeps the two failures apart: `NotStaged` (refused, nothing buffered or written) and `NotCommitted` (buffered still after a transient failure, dropped after any other). `SqlitePersister` implements it in both flush modes with the one connection guard an immediate-mode `store` already held across its merge and its flush. `flush`, `commit_writes` and `delete_wallet` take the same connection, so they are unchanged. `WalletPersister::store_durably` uses the step where the backend offers it and maps `NotStaged` to `NotDurable::Store` and `NotCommitted` to `NotDurable::Flush`. The step is counted in the flush ledger as the flush it contains, so `flush_durably` and the stored markers see its failures. A backend that does not attest the step takes the code path it took before, unchanged. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 42 minutes. View limit 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. |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
🔍 Review in progress (commit cc61f1a) · live progress |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
The atomic SQLite operation and connection serialization are well structured, but three in-scope correctness issues remain. The ledger misclassifies fatal atomic commits on SQLite Immediate mode, poisoned connections can discard existing buffered state while reporting NotStaged, and several durability-critical wallet paths still use the old store-then-flush race. CI has no reported code failures; wallet tests and Kotlin checks are still pending.
🔴 3 blocking | 🟡 1 suggestion(s)
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Route all pre-action durable records through the atomic persistence path
packages/rs-platform-wallet/src/wallet/identity/network/payments.rs:1566-1570
This payment-address reservation still calls store() and flush() separately, so it retains the Manual-mode race that this PR is intended to eliminate: another flush, host commit_writes(), or wallet drain can take and fatally drop the reservation between the two calls, after which this method's flush succeeds over an empty buffer and returns an address as if its reservation were durable. The same bypass exists in prepared_payment.rs:733-739, the funded invitation record at invitation.rs:214-220, both durable asset-lock record paths in asset_lock/build.rs:1482-1492 and 1507-1512, and the private-contact marker path in private_contact_requests.rs:700-706. These records gate broadcasts, dispatch, address exposure, or restart-sensitive recovery, so the wallet must use WalletPersister::store_durably() (and classify its NotDurable result) for each of these paths when the backend offers the atomic step.
self.persister
.store_durably(changeset)
.map_err(|error| self.persister.classify_not_durable(error))?;
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality); gpt-6.1-sol (phase2-reviewer: general, architecture-layering, rust-quality, security-auditor)
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); 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:
normalbygpt-6.1-sol(effort low) — This is a large and intricate Rust persistence and concurrency change affecting wallet durability guarantees, but it does not directly change consensus, funds movement, cryptography, key handling, network deserialization, or a storage migration. - 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) - Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
- Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort high); 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/changeset/flush_ledger.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/changeset/flush_ledger.rs:130-134: Atomic commits can drop buffered state without recording a loss
`store_commits_inline()` describes ordinary `store()` behavior, but it does not describe whether `store_and_commit()` can drain and discard buffered state. SQLite advertises this flag as true in Immediate mode, while `stage_and_commit()` still merges into the shared buffer and `handle_flush_error()` restores that buffer on transient failures and drops it on fatal failures. If a prior store failed transiently and restored data, a later atomic commit can fatally fail and drop both changesets, but this code enters `InFlight` with `buffers = false`, so only `failed` is incremented and `lost` remains unchanged. Other handles can then trust `flush_durably()` or stored markers even though their buffered records were discarded. The ledger needs operation-specific buffer-loss semantics, such as a separate capability/outcome for `store_and_commit`, rather than reusing `store_commits_inline()`.
In `packages/rs-platform-wallet-storage/src/sqlite/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1137-1141: Do not report NotStaged after discarding the existing buffer
`stage_and_commit()` maps any failure from `self.conn()` to `StoreAndCommitError::NotStaged`, but `conn()` calls `self.buffer.discard_all()` when the connection mutex is poisoned before returning `LockPoisoned`. A wallet can therefore have unrelated pending changesets, receive `NotStaged`, and nevertheless lose those changesets. This violates the new `NotStaged` contract that the pre-existing buffer is unchanged and prevents `FlushLedger` from recording the loss. The operation must acquire the connection non-destructively for this path, or return an outcome that explicitly reports the buffer loss instead of mapping it to `NotStaged`.
In `packages/rs-platform-wallet/src/wallet/identity/network/payments.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/identity/network/payments.rs:1566-1570: Route all pre-action durable records through the atomic persistence path
This payment-address reservation still calls `store()` and `flush()` separately, so it retains the Manual-mode race that this PR is intended to eliminate: another flush, host `commit_writes()`, or wallet drain can take and fatally drop the reservation between the two calls, after which this method's flush succeeds over an empty buffer and returns an address as if its reservation were durable. The same bypass exists in `prepared_payment.rs:733-739`, the funded invitation record at `invitation.rs:214-220`, both durable asset-lock record paths in `asset_lock/build.rs:1482-1492` and `1507-1512`, and the private-contact marker path in `private_contact_requests.rs:700-706`. These records gate broadcasts, dispatch, address exposure, or restart-sensitive recovery, so the wallet must use `WalletPersister::store_durably()` (and classify its `NotDurable` result) for each of these paths when the backend offers the atomic step.
In `packages/rs-platform-wallet/src/changeset/traits.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/changeset/traits.rs:185-196: Preserve PersistenceError as the standard error source
The new public `StoreAndCommitError` variants format their `PersistenceError` fields but do not mark them as sources. Consequently, callers using `std::error::Error::source()` cannot traverse to the typed persistence error or its backend cause, unlike the existing `PlatformWalletError::PersisterStore` and `PersisterFlush` variants. Mark both tuple fields with `#[source]` so the new API preserves the backend error chain.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…count it Three changes from review of the atomic store and commit. A store committed in one step that fails for good is counted as lost in the flush ledger on every backend. It was counted as lost only where `store_commits_inline()` is false, but that attestation describes `store`: SQLite in immediate mode keeps a changeset whose commit failed transiently and commits it with the next one, so a step that fails for good there can drop more than its own changeset. `SqlitePersister` reports a poisoned lock inside the step as `NotCommitted(LockPoisoned)` and no longer as `NotStaged`. Finding the connection poisoned discards every buffered changeset, so the buffer is not as it was, which `NotStaged` promises, and the ledger has to count the loss. Both `StoreAndCommitError` variants mark their `PersistenceError` as the error's source, with a message of their own, as `PersisterStore` and `PersisterFlush` do. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Your move: thepastaclaw left review threads unresolved; resolve them. |
|
On the review finding that has no thread ("Route all pre-action durable records through the atomic persistence path"): not done in this PR, on purpose. The call sites it names ( Two of the listed sites are left as they are by #5923 too: the drain row in The other three findings are fixed in 2ae8617 and answered on their threads. 🤖 Addressed by Claude Code |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The atomic persistence path correctly separates staging and commit outcomes, but three current-head correctness issues remain. SQLite advertises the capability without coordinating drains across processes, poisoned-connection recovery drops buffers for every wallet while only notifying the active wallet's ledger, and transient NotStaged results are incorrectly narrowed to fatal store failures. The wallet test, Swift schema, and Kotlin checks were still in progress; no completed code check was failing in the supplied CI snapshot.
🔴 2 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: Preserve retryability for transient NotStaged results
packages/rs-platform-wallet/src/wallet/persister.rs:835-837
Every StoreAndCommitError::NotStaged result is converted to NotDurable::Store and then passed through classify_store_failure, which narrows transient errors to fatal unless the backend separately attests store_transient_is_reissuable. That attestation describes ordinary store() reissuability, but a NotStaged atomic result guarantees that the incoming changeset never entered the buffer and nothing was written, so retrying it is inherently safe regardless of the ordinary-store policy. This unnecessarily turns a recoverable preflight or read failure from a backend offering the atomic operation into PersisterStore(Fatal). Preserve the transient classification for atomic-step NotStaged outcomes, or introduce a distinct classification path that bypasses the ordinary store reissue gate.
source: gpt-6.1-sol (phase2-reviewer: general)
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:
normalbygpt-6.1-sol(effort low) — This is a substantial cross-cutting Rust persistence and wallet-state change involving atomic storage semantics and concurrency, but it does not itself modify consensus, cryptography, key handling, funds movement, coin selection, or a storage migration. - 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) - Code unchanged since the last final review (
988b62c7): 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 high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort high); 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-storage/src/sqlite/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1487-1492: Do not attest atomic persistence without cross-process drain ordering
SQLite returns `true` for `offers_store_and_commit`, but the ordering guarantee is enforced only by the instance-local `self.conn` mutex. The storage crate explicitly supports cross-process peers, and its open-path registry is process-local, so another process can hold an older changeset in its own buffer, take it from that buffer in `flush_inner`, and begin its transaction after this atomic step has committed. SQLite serializes the transactions but does not identify the stale in-memory changeset as stale; the later drain can therefore write older state over the state just attested by `store_and_commit`. The capability must either acquire a database-native ordering/generation guard before every participating drain removes its buffer, reject stale drains using a persistent generation check, or remain unattested until cross-process drain ordering is guaranteed.
- [BLOCKING] packages/rs-platform-wallet-storage/src/sqlite/persister.rs:1144-1146: Record losses for every wallet when a poisoned connection clears the global buffer
`stage_and_commit` maps a poisoned `conn()` result to `NotCommitted`, so the current wallet's `FlushLedger::store_and_commit` records a loss. However, `conn()` calls `self.buffer.discard_all()` when the connection mutex is poisoned, and that buffer contains pending changesets for every wallet handled by the persister. The other wallets' ledgers are not notified, even though their buffered records have been discarded; their durability checks and stored-marker decisions can consequently continue treating those records as present until another operation happens to update each ledger. The backend needs a backend-wide loss notification for all affected wallet IDs, or must avoid globally discarding other wallets' buffers on this path.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them. |
…ryable A changeset `store_and_commit` refused before it was staged was reported like a plain store's failure: a transient one was narrowed to fatal unless the backend attests `store_transient_is_reissuable`. That attestation speaks for `store`. The step's `NotStaged` says by itself that nothing of the changeset was staged or written, which is all a retry needs, so `classify_not_durable` now keeps the backend's kind for it (`PlatformWalletError::from_unstaged_store_failure`). A plain store's transient failure on a backend without the step is narrowed as before. Docs only, from the same review: the step's contract is about one backend instance and its buffer, and orders nothing against another process that has the same database open; and a poisoned connection's discard is every wallet's, which the step reports for its own wallet while every later operation of the others fails. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The atomic persistence operation is otherwise correctly source-preserving and ledger-counted. One in-scope blocking durability issue remains: flush_durably returns before consulting the ledger for inline backends, so a failed atomic step can leave buffered or lost records while another handle is told they are durable. Rust workspace tests and Kotlin checks are still in progress, with no failed code check reported.
🔴 1 blocking
1 finding(s) not shown inline (the lines are not part of this PR's diff)
🔴 Blocking: Do not bypass durability checks for inline backends that offer the atomic step
packages/rs-platform-wallet/src/wallet/persister.rs:895-897
flush_durably() returns Ok(()) whenever store_commits_inline() is true, before checking in_flight, failed, or lost. That flag describes ordinary store() behavior, but SQLite's atomic store_and_commit() can restore its changeset after a transient commit failure or drop buffered state after a fatal failure. During or after such a step, another handle's flush_durably() therefore skips the ledger and reports success even though the record is still buffered or was discarded. Keep the inline fast path only for backends that do not offer store_and_commit; atomic-capable inline backends must run the ledger-aware path.
if self.store_commits_inline() && !self.inner.offers_store_and_commit() {
return Ok(());
}
source: gpt-6.1-sol (phase2-reviewer: rust-quality)
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:
normalbygpt-6.1-sol(effort low) — This is a large and intricate Rust persistence and concurrency change affecting wallet durability semantics, but it does not directly modify consensus, funds movement, cryptography, key handling, network deserialization, or storage migrations. - 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) - Fresh verifier:
gpt-6.1-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort high); 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/persister.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/persister.rs:895-897: Do not bypass durability checks for inline backends that offer the atomic step
`flush_durably()` returns `Ok(())` whenever `store_commits_inline()` is true, before checking `in_flight`, `failed`, or `lost`. That flag describes ordinary `store()` behavior, but SQLite's atomic `store_and_commit()` can restore its changeset after a transient commit failure or drop buffered state after a fatal failure. During or after such a step, another handle's `flush_durably()` therefore skips the ledger and reports success even though the record is still buffered or was discarded. Keep the inline fast path only for backends that do not offer `store_and_commit`; atomic-capable inline backends must run the ledger-aware path.
|
Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix. |
…eft buffered `flush_durably` answered `Ok` at once for every backend whose store is the commit, on the reasoning that such a backend buffers nothing. A backend that commits a store in one step keeps a changeset whose commit failed transiently, by that step's contract, whatever its `store` does, and SQLite in immediate mode is one. So a record reported as still buffered was answered for as durable with no flush made, and so was one a later failure had dropped. `flush_durably` now answers at once only for a backend that keeps no buffer (`keeps_a_buffer`: the store is the commit and the step is not offered). Any other is flushed and its ledger read. `FlushLedger::flush` counts a flush that fails for good as lost on a backend that keeps a buffer, where it never did on one whose store is the commit. The Swift and Kotlin hosts do not offer the step, so they are answered for and counted as before. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
On the blocking finding of the review of
Four tests, each shown to fail with its fix removed: One limit stays, and the description states it: a drain the wallet does not make through its ledger is not counted. That is a host's 🤖 Addressed by Claude Code |
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review — Final validation — Phase 1 + Phase 2
The exact head implements the atomic persistence path coherently across the wallet trait, flush ledger, wallet persister, and SQLite backend, and the previously identified defects are resolved or explicitly tracked. No new in-scope correctness, security, layering, or Rust-quality findings remain; the Rust workspace tests and PastaClaw review were still in progress in the supplied CI snapshot, with no failed code checks reported.
🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)
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); 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:
normalbygpt-6.1-sol(effort low) — This is a large, intricate Rust storage and wallet-persistence change affecting durability guarantees and concurrent flush behavior, but it does not itself modify consensus, cryptography, key handling, funds movement, or storage migrations. - 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) - 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 high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— architecture-layering (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— rust-quality (completed, effort high); agentphase2-reviewer,gpt-6.1-sol— security-auditor (completed, effort high); 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 |
#5923 merged into v5.1-dev and edits the functions this branch edits. The conflicts were in `store_durably`, in the docs of `flush_durably`, `classify_not_durable`, `NotDurable::Flush` and the flush ledger, and in the persistence trait, where both sides add methods. Resolved by keeping both: a backend that offers the atomic step is asked for it first, and any other backend runs #5923's code unchanged. Beyond the resolution, so that the two meet: - `withdraw_durably`, which #5923 added, takes the step too where it is offered. That nothing writes the record after its withdrawal is the step's contract there. - `losses_of` reads the backend's `buffered_writes_dropped` for every backend that keeps a buffer (`keeps_a_buffer`), where #5923 left it out for one whose store is the commit. SQLite in immediate mode is such a backend and still holds a changeset whose commit failed transiently, so a plain store that fails for good there drops it, which only the backend counts. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
Basic explanation
What this does: The wallet saves its records through a storage backend in two calls:
storeputs a record in a waiting area (the buffer), andflushwrites the buffer to disk. Before the wallet acts on a record being on disk (pays for a private contact request it must find again after a restart, publishes a wallet whose old backfill record must be gone), it has to know that this record was written. With two calls it cannot know that directly: something else can empty the buffer in between and lose the record, and the wallet's ownflushthen succeeds over an empty buffer. Until now the wallet worked the answer out from outside: it counted the flushes around the two calls and asked the backend how often it had dropped its buffer. This PR adds one backend operation,store_and_commit, that does both in a single step nothing else can come between, and that says exactly what happened to the record it was given. The SQLite backend implements it, and the wallet uses it wherever a backend offers it.Value: On the SQLite backend, "this record is on disk" becomes something the backend states, not something the wallet concludes from counters. The counters on
v5.1-dev(#5923) are safe, but all they can do is refuse: whenever another flush of the same wallet ran or returned while a record was being made durable, or the host committed in between, the wallet reports the record as not durable and the caller starts over, even when the record was written. With the step nothing can come between the store and its commit, so those cases succeed, and every failure says where the record is (never written, or still buffered for a later flush). Hosts that write at the store (the Swift and Kotlin apps) are not touched.Risks: Low to medium. No consensus code. Behaviour changes only for a backend that offers the step, which today is SQLite alone:
PersisterFlush, with the backend's own kind) where it was reported as a failed store (PersisterStore, a transient one narrowed to fatal). The new report is the accurate one, since after a transient failure the record is still buffered and the next write for that wallet commits it. Every caller treats either as "not durable" and does not go on.flush_durably, made before the journal record of a private payment is discharged) now flushes and reads the flush ledger, where it answeredOkat once. Immediate mode can hold a record whose commit failed transiently, so the old answer could be given while that record was in the buffer only. The check takes the connection for one short flush, and in a database opened read-only for recovery it now answers "not durable", as it already did in manual mode.buffered_writes_dropped), which fix(platform-wallet): trust a stored record only when no other flush dropped it #5923 read in manual mode only. A write that fails for good in immediate mode, a plainstoreincluded, therefore counts as a loss for every handle of that wallet: from then on they do not discharge a private payment's journal record on the strength of what they track, and they store their markers again, until the wallet is loaded anew. That is what manual mode already does after a flush that fails for good. This one is my choice, made to close the gap described under "The step is counted in the flush ledger"; reverting it is one condition inlosses_of.storealready does.false, and the default implementation refuses every changeset.withdraw_durably(from fix(platform-wallet): trust a stored record only when no other flush dropped it #5923) takes the step too. ItsOkhas to mean that nothing writes the withdrawn record afterwards, and on a backend with the step that rests on the step's contract, where it rested on the wallet's counters.Issue being fixed or feature implemented
WalletPersister::store_durably(packages/rs-platform-wallet/src/wallet/persister.rs) answers "is this record on disk?" by inference. It reads the wallet's flush ledger (flushes in progress, failed, failed for good), callsstore, callsflush, and reads the ledger again. #5923 extended that over ten review rounds, each closing one interleaving with one more counter. The review's verdict there was that the cause is structural:PlatformWalletPersistencehas no per-wallet operation that binds a stored changeset to its durable result, so every counter closes one race and leaves another. It asked for an atomic primitive in the trait and inSqlitePersister, for the wallet to consume.This PR is that primitive. #5923 merged while this was in review.
v5.1-devis merged into this branch and the PR builds on it: the counters stay for a backend without the step, and the step is used where a backend offers it.What was done?
The trait:
offers_store_and_commitandstore_and_commitpackages/rs-platform-wallet/src/changeset/traits.rsgains two methods onPlatformWalletPersistenceand one error type:The contract, required of a backend that attests the step:
flush, no otherstore_and_commit, nothing the host can call on the backend. A drain that began earlier has finished by then.Okmeans the changeset is on disk.NotStagedmeans none of it is buffered or written and the buffer is as it was.NotCommittedmeans it is still buffered after a transient failure, and dropped after any other. A backend that lost its buffer while refusing a changeset (a poisoned lock) answersNotCommitted, neverNotStaged, because the buffer is not as it was.Both variants carry the backend's
PersistenceErroras theirsource(), likePlatformWalletError::PersisterStoreandPersisterFlushdo.Scope: one backend instance. The contract is about one backend instance and the buffer it keeps. It orders nothing against another instance over the same storage, such as another process with the same database open: that is a writer of its own with a buffer of its own, and what it writes later lands later, through the step or through
storeandflushalike. For SQLite the guard is the persister's own connection, and the crate's rule for two processes on one database is the one itsdelete_walletandrestore_fromdocs already give: callers serialize them.Why this shape. An attestation that defaults to
false, plus a method whose default refuses, is how this trait already adds abilities (store_commits_inline,store_transient_is_reissuable,stores_dashpay_backfill). Every existing backend compiles unchanged, and the wallet takes exactly the path it took before for it: the only new code such a backend reaches is the attestation answeringfalse. Two other shapes were considered and not taken:storeand thenflush. It would look like the step without being one.How a failed store is told from a failed commit
The two variants map one to one onto what call sites already report differently:
store_durablyanswerclassify_not_durableNotStaged(e)NotDurable::Store(e)PersisterStore, with the backend's own kind. A transient one stays transient: the answer itself says nothing was staged or written, so the changeset may be issued againNotCommitted(e)NotDurable::Flush(e)PersisterFlush, with the backend's own kindNotDurable::LostandNotDurable::OtherFlushUnsettledare never the answer on this path. Both stand for what could not be told from outside the backend.A plain
storethat fails transiently on a backend without the step is still narrowed to fatal unless the backend attestsstore_transient_is_reissuable. That attestation speaks forstore; the step'sNotStagedmakes the same promise by itself, for the changeset it was given.The step is counted in the flush ledger
FlushLedger::store_and_commit(packages/rs-platform-wallet/src/changeset/flush_ledger.rs) wraps the backend call asFlushLedger::flushwraps a flush: in progress from before the call until its outcome is recorded, failed when the commit fails, lost when it fails for good or the backend panics. A changeset refused before it was staged took nothing from the buffer and is not counted.A step that fails for good is counted as lost on every backend, one whose
storeis the commit included. "Thestoreis the commit" says that astorewhich answersOkis on disk. It does not say the buffer is empty: by the step's contract a changeset whose commit failed transiently stays buffered, and SQLite in immediate mode keeps it and commits it with the next write. So a backend that offers the step keeps a buffer whatever itsstoredoes (keeps_a_bufferinflush_ledger.rs), and on such a backend a flush that fails for good is counted as lost too, where it was counted as failed only. A backend whosestoreis the commit and that does not offer the step (the Swift and Kotlin hosts) is counted as before: its flush only notifies the host and is never a loss.Not counted in the ledger: a drain the wallet does not make through it. A host's
commit_writesis one. In immediate mode a plainstoreis another, since it commits whatever an earlier transient failure left in the buffer, or drops it when it fails for good. Only the backend can count those, and SQLite does: #5923'sbuffered_writes_droppedis added to the losses a handle compares. #5923 left that count out for a backend whosestoreis the commit, on the same "nothing is buffered there" reasoning. It is now read for every backend that keeps a buffer (losses_ofinwallet/persister.rsdecides bykeeps_a_buffer), so in immediate mode too.The caller of the step needs none of this for its own answer. It is counted for everyone else: a commit that fails for good drops the wallet's whole buffer, what other handles stored plainly included, so
flush_durablyand the stored private payment markers have to see it.flush_durablystays on the ledger, and no longer skips it in immediate modeflush_durablyhas no changeset of its own. It asks whether anything stored earlier, by any handle of the wallet id, was dropped since the handle was made. That is a question about the past, and a step that binds one changeset to one commit cannot answer it. It stays on the ledger for every backend that keeps a buffer, and sees a failed step there.One thing about it changes. It answered
Okat once for every backend whosestoreis the commit, on the reasoning that nothing is buffered there. That holds for the Swift and Kotlin hosts. It does not hold for SQLite in immediate mode, which is such a backend and still holds a changeset whose commit failed transiently. Since this PR reports that case as "still buffered, a later flush writes it",flush_durablyhas to be a flush that writes it, and has to see a later failure that dropped it. It now answers at once only for a backend that keeps no buffer (keeps_a_buffer: thestoreis the commit and the step is not offered). For SQLite in either mode it flushes and reads the ledger:Okonly after a flush that succeeded with no flush or step in progress, nothing lost since the handle was made (by the ledger's count or the backend's own), and no other flush or step failed or returned during the call.A host that applies a changeset in parts
The step requires all or nothing, so such a host cannot offer it, and nothing more can be said for it than before: a failed
storedoes not say how much of the changeset reached the disk.FFIPersister(packages/rs-platform-wallet-ffi/src/persistence.rs) is not changed and does not attest the step, because itsstorefans out to host callbacks (the asset lock callback runs before the shielded recipient sidecar) and some hosts attest capabilities withoutATOMIC_CHANGESETS. A call site has to keep treatingNotDurable::Storefrom a backend without the step as "may be partly written".What the step adds is the other half: for a backend that offers it, that doubt is gone, and the doubt that remains is tied to a backend property the code can ask about (
offers_store_and_commit). A host that commits at the store and rolls a failed round back whole could later offer itsstoreas the step, answering every failure asNotStaged. That needs nothing from this PR and is not done here.SQLite: the immediate-mode path, made available in manual mode
packages/rs-platform-wallet-storage/src/sqlite/persister.rs: an immediate-modestorealready held one connection guard across its buffer merge and its flush. That body is nowstage_and_commit, used by the immediate-modestore(same behaviour, one error as before) and by the newstore_and_commitin both flush modes.flush_inner(socommit_writesand the trait'sflush) anddelete_wallet_inneralready take the same connection and hold it across their take, write and restore, so they are not changed: holding it is what keeps them out.A poisoned lock is reported as
NotCommitted(LockPoisoned), not asNotStaged. Finding the connection poisoned discards every buffered changeset, so although the new changeset never reached the buffer, the buffer is not as it was, and the ledger has to count the loss.That discard is every wallet's, as on every other path that finds the connection poisoned, and the step reports it for its own wallet only. No other wallet can be told a record is on disk in the meantime: every later
store,flushandstore_and_commiton that persister fails withLockPoisoned, and each wallet's next flush or step counts the loss in its own ledger. A count that reaches every wallet's ledger at once isbuffered_writes_droppedin #5923, which counts this discard for all of them.The wallet uses it
WalletPersister::store_durablyandwithdraw_durablyask the backend for the step when it is offered, and otherwise run the code #5923 gave them, unchanged. The changeset is prepared the same way on both paths (an established contact's outbound-account marker is stripped on a backend that cannot keep it).withdraw_durablystores a record's removal, and itsOkhas to mean more than "the removal is on disk": nothing may write the record after it. Without the step it works that out by refusing whenever a flush was in progress or returned across the store. With the step there is nothing to work out. A drain that began earlier has finished before the removal is staged, and the commit writes whatever of the record is still buffered with the removal behind it, which is the contract's "one step" and "in order".Before and after
A commit the host makes on a manual-mode SQLite backend, between the wallet's store and its flush:
Another flush of the same wallet running during a durable store, manual mode:
A durable store whose commit fails transiently, immediate mode (the SQLite default):
Asking whether everything stored is on disk (
flush_durably) after that failure, immediate mode:Withdrawing a record (
withdraw_durably) while a flush that took it is in progress, manual mode:How this builds on #5923
#5923 is merged, and
v5.1-devis merged into this branch (a merge commit, no rebase). Its conflicts were in the docs ofstore_durably,flush_durablyand the ledger, and in the two bodies both PRs edit. What the two do together:store_durablyandwithdraw_durablytake the step first where the backend offers it. Otherwise they run fix(platform-wallet): trust a stored record only when no other flush dropped it #5923's code as it is: theFlushesSoFarcomparison,FlushLedger::returned, thein_flight,failedandlostreads, andbuffered_writes_dropped. None of it is removed, because a backend without the step needs each one.flush_durably, the stored private payment markers andbuffered_writes_lostask about the past, which no single commit answers. They stay on the ledger plusbuffered_writes_dropped. A step is counted in the ledger as the flush it contains, as returned too, so fix(platform-wallet): trust a stored record only when no other flush dropped it #5923's readers see it.store_commits_inline()alone and now decide bykeeps_a_buffer: the early return inflush_durably, andlosses_of, which left the backend's drop count out for a backend whosestoreis the commit.reserve_payment_addressinpayments.rs,DashPayView::store_durablyinprepared_payment.rs, the funded invitation record ininvitation.rs, the invitation funding index and the shielded recipient row and its removal inasset_lock/build.rs, the replaced backfill record inmanager/mod.rs, and the private payment marker inprivate_contact_requests.rs. The invitation site stores again onLostorOtherFlushUnsettled; the step never answers with either, so that retry is not taken on SQLite.How Has This Been Tested?
Twenty-five new tests. Each was run with its fix taken out and fails, and passes with it back. The wallet-crate ones were run that way again on the merged tree.
Wallet crate (
packages/rs-platform-wallet), seventeen:wallet::persistershould_commit_a_store_in_one_step_so_a_commit_by_the_host_cannot_drop_itstore_durablystores and flushes in two calls: answersOkwith nothing on diskwallet::persistershould_commit_a_store_in_one_step_so_a_flush_in_progress_cannot_write_an_older_state_lastOtherFlushUnsettledwallet::persistershould_commit_a_withdrawal_in_one_step_so_a_flush_in_progress_cannot_write_the_record_after_itwithdraw_durablystores and flushes in two calls: refused withOtherFlushUnsettled, nothing flushedwallet::persistershould_take_the_backends_answer_for_a_withdrawal_committed_in_one_stepwallet::persistershould_report_a_refused_changeset_as_a_failed_store_and_a_failed_commit_as_a_failed_flushwallet::persistershould_still_narrow_a_transient_store_failure_of_a_backend_without_the_stepwallet::persistershould_tell_the_wallet_ids_other_handles_of_a_commit_in_one_step_that_dropped_the_bufferwallet::persistershould_commit_a_contact_in_one_step_without_a_marker_the_backend_cannot_keepchangeset::flush_ledgershould_count_a_failed_commit_of_a_store_made_in_one_step_as_a_failed_flushstorebufferschangeset::flush_ledgershould_count_a_store_being_committed_in_one_step_as_a_flush_in_progresswallet::persistershould_flush_an_inline_backend_that_commits_in_one_step_before_calling_its_records_durableflush_durablyanswers at once for every backend whosestoreis the commit:Okwith the record in the buffer onlywallet::persistershould_report_the_loss_of_what_a_commit_in_one_step_left_buffered_on_an_inline_backendOkfor a record that was droppedwallet::persistershould_not_answer_for_an_inline_backend_while_a_commit_in_one_step_is_in_progressflush_durablyanswers at once for every backend whosestoreis the commit:Okwhile the step's outcome is not recordedchangeset::flush_ledgershould_count_a_flush_that_fails_for_good_as_lost_on_an_inline_backend_that_commits_in_one_stepstoreis the commitwallet::persistershould_read_the_drops_an_inline_backend_that_commits_in_one_step_reportsstoreis the commit:Okfor a record a plainstoredropped, and a stored marker is keptchangeset::traitsshould_not_offer_the_atomic_step_unless_the_backend_attests_ittruechangeset::traitsshould_keep_the_persistence_error_as_the_source_of_a_failed_atomic_stepStorage crate (
packages/rs-platform-wallet-storage), eight, intests/integration/sqlite_store_and_commit.rsandsqlite_recovery_mode_write_block.rs. The racing ones park the second actor between the step's merge and its commit with the crate's existingrelease_at_store_seam, so they do not depend on timing:should_tell_the_step_that_staged_a_changeset_when_it_is_dropped_and_not_a_commit_by_the_hostcommit_writestakes the changeset, eats the fatal failure, and the step answersOkshould_keep_a_flush_racing_the_step_from_taking_what_it_stagedflushof the wallet as the second actorshould_keep_a_changeset_buffered_for_a_later_commit_when_its_own_fails_transientlyshould_commit_what_was_buffered_before_the_changeset_with_it_and_in_that_ordershould_leave_the_buffer_as_it_was_when_a_changeset_is_refused_before_it_is_stagedshould_report_a_poisoned_connection_as_a_dropped_buffer_and_not_as_nothing_stagedNotStagedshould_offer_the_step_through_the_trait_in_both_flush_modesshould_refuse_a_store_and_commit_in_recovery_before_it_stages_anythingThe four
flush_durablytests run against a wallet-crate backend that behaves as SQLite does in immediate mode (thestoreis the commit, the step is offered, a transient failure keeps the buffer).flush_durablyis private to the wallet crate, so the storage crate cannot call it. What the SQLite side contributes, that an immediate-mode write which fails transiently leaves its changeset buffered and aflushthen writes it, is already pinned there bytc_p2_006_immediate_surfaces_flush_retryableinsqlite_buffer_semantics.rs; the storage crate's code is not changed by this fix, only its docs.One interleaving has no storage-level test, on purpose: a flush that took an older state and writes it after the step. On SQLite it cannot be produced with or without this PR, because
flush_inneralready holds the connection across its take, its write and its restore, so no test of it could fail. The wallet-level test above covers it against a backend whose plain flushes can do it, and the ordering test covers the half the step itself owns.Commands, all passing on the final tree (
cc61f1a538, which hasv5.1-devat4505fc5667merged in):wallet::asset_lockis in the filter since the merge: the one caller ofwithdraw_durablyis there.The last one finishes with two dead-code warnings, in
asset_lock/operation.rsandasset_lock/sync/tracking.rs, files this PR does not touch.Not run: the full workspace suite, the
platform-wallet-ffiand JNI test suites (those crates are not changed; clippy type-checks the FFI crate and its tests), a Swift or Kotlin build, anything against a live network.Breaking Changes
None for consensus. For API users:
PlatformWalletPersistencegains two methods with defaults, so no implementor has to change, andStoreAndCommitErroris a new public type. The reporting changes are the three immediate-mode SQLite cases under Risks.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
PR Hygiene ·
cc61f1a/skip-botsproceeds without the ones not yet reported/self-reviewedwallet-storage(packages/rs-platform-wallet-storage/README.md,packages/rs-platform-wallet-storage/src/sqlite/persister.rs,packages/rs-platform-wallet-storage/tests/integration/main.rsand 2 more) — lklimekrs-platform-wallet(packages/rs-platform-wallet/src/changeset/flush_ledger.rs,packages/rs-platform-wallet/src/changeset/mod.rs,packages/rs-platform-wallet/src/changeset/traits.rsand 3 more) — HashEngineering or ZocoLini or llbartekll or romchornyiWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.