Repository navigation
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
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. |
|
🕓 Review not started yet because this PR is a draft.
Commit 6057fa6. Normal review starts when eligible; priority review starts as soon as a slot is available. |
thepastaclaw
left a comment
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Verified the supplied findings against head 6e00e2e. Three blocking issues remain: active finality waits ignore funding conflicts, FFI restoration accepts inconsistent operation evidence, and the new revision-aware Swift tests use transaction bytes that Rust rejects. Current CI checks pass, including Kotlin tests and Swift schema coverage, but provide no Swift runtime validation; this verification was static and ran no builds or tests.
🔴 3 blocking | 🟡 4 suggestion(s)
Review provenance
Source: reviewer 1: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: architecture-layering); reviewer 3: 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); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)
- Triage:
criticalbygpt-6.1-sol(effort low) — This is a large, intricate change that modifies wallet funds movement and coin-selection behavior through asset-lock funding/drain recovery, while also introducing SQLite and cross-language persistence 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(lane 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— 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 each finding against the current code and only fix it if needed.
In `packages/rs-platform-wallet/src/wallet/asset_lock/sync/reconstruction.rs`:
- [BLOCKING] packages/rs-platform-wallet/src/wallet/asset_lock/sync/reconstruction.rs:428-434: Make active proof waits observe the funding conflict
A sweep now retains this lock as Conflicted, but an already-running proof wait never examines that state. After Platform rejects an InstantSend proof, fund_from_asset_lock.rs calls upgrade_to_chain_lock_proof with the caller's wait policy; the drain FFI passes None. The pinned key-wallet allows a chainlocked winner to sweep an InstantSend-locked loser and removes the losing transaction records. If that happens after wait_for_chain_lock starts, its loop continues checking transaction records and the mined-height locator indefinitely, even after the conflict is durable. The drain consequently retains shield_guard and blocks subsequent shield-class operations. Make the shared proof-wait paths stop on committed conflict evidence, without publishing an uncommitted conflict as a durable outcome, and cover a sweep arriving after the wait has started.
In `packages/rs-platform-wallet-ffi/src/persistence.rs`:
- [BLOCKING] packages/rs-platform-wallet-ffi/src/persistence.rs:6345-6350: Validate restored operation evidence in the wallet owner
The revision loader checks only the upper bound, and the surrounding restore path never validates the relationship between status, revision, and operation ID after reconstructing both sidecars. A successful UUID callback returning found=false followed by a revision callback returning 1 therefore accepts a Conflicted or recovered row with no UUID. Swift's loader permits the same combination, whereas SQLite's decode_row explicitly rejects it. After reopening, wallet_drain_operation_status_inner searches by UUID and misses this evidence, allowing NotSent; begin_wallet_drain also excludes the unbound row from its pending-operation gate and can build replacement funding for the original UUID. Conflicted rows at revision zero are accepted as well. Add a wallet-owned recovery-metadata invariant and invoke it after complete reconstruction in both restore paths. Invalid combinations must fail the entire load rather than become absent operation history.
In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/AssetLockOperationPersistenceTests.swift`:
- [BLOCKING] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/AssetLockOperationPersistenceTests.swift:34-38: Use Rust-decodable transaction fixtures in the revision-aware Swift tests
The new revisionAware calls enter asset_lock_operation_persistence_action through withOperationFFI, and Rust consensus-decodes both snapshots through build_unused_asset_locks. The shared snapshot fixture supplies [3, 0, 0, 0, 0, 0, 0, 0, 0, 0]. In the pinned rust-dashcore decoder, its empty input vector selects witness decoding and the following zero produces UnsupportedSegwitFlag(0). The FFI action therefore returns 0 and persistAssetLocks returns false at this assertion and the corresponding assertion in testV4OperationBindingMigratesWithLegacyRevisionAndSurvivesReopen. The stale-snapshot assertion also passes for the wrong reason, before revision acceptance runs. Replace the placeholder with consensus-encoded transaction bytes shared by the predecessor and incoming snapshots; do not weaken the production decoder.
In `packages/rs-platform-wallet-storage/src/sqlite/schema/asset_locks.rs`:
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/schema/asset_locks.rs:240-253: Share the conflict projection with the wallet's live sweep path
The replay adapter independently decides whether a swept lock is removed or retained, changes its status to Conflicted, clears its proof, and advances its operation revision. The live remove_tracked_asset_locks_for_swept path implements the same wallet-state decisions separately. They currently agree, but a lifecycle change can update live handling without updating restart repair. Extract a pure swept-lock projection into rs-platform-wallet and call it from both paths, leaving row selection and transactional writes in platform-wallet-storage.
- [SUGGESTION] packages/rs-platform-wallet-storage/src/sqlite/schema/asset_locks.rs:235-240: Filter sweep candidates before decoding lifecycle blobs
remove_swept now calls load_unconsumed for the whole wallet and only then filters by the swept transaction IDs. That helper reads and decodes every selected lifecycle blob, transaction, and proof, including unrelated locks and UUID-bound terminal tombstones. The previous implementation inspected outpoints before selecting matching losers. On a wallet with substantial retained history, repairing a small sweep therefore performs unnecessary full-history decoding inside the repair transaction. Select candidate outpoints first and decode only matching rows before applying the wallet-owned projection.
In `packages/rs-platform-wallet/src/changeset/changeset.rs`:
- [SUGGESTION] packages/rs-platform-wallet/src/changeset/changeset.rs:1625-1632: Compare CAS redeliveries without cloning complete snapshots
The exact-redelivery branch clones both AssetLockEntry values solely to clear expected_operation_revision before comparing them. Each clone duplicates the transaction and optional proof even though this operation only needs borrowed equality checks. SQLite persistence and the FFI owner check both reach this branch when a committed CAS is redelivered. Use a borrowed comparison helper or borrowed field tuple that excludes the precondition, preserving equality over every other field without allocating two complete snapshots.
In `packages/rs-platform-wallet-ffi/src/asset_lock_operation_persistence.rs`:
- [SUGGESTION] packages/rs-platform-wallet-ffi/src/asset_lock_operation_persistence.rs:89-97: Retain diagnostics for malformed FFI operation snapshots
Both decode failures discard their PersistenceError and return the same 0 used for an ordinary policy rejection. The host can only report a rejected persistence round, with no diagnostic distinguishing malformed transaction/proof bytes from a stale CAS. Preserve the stable return-code contract, but emit contextual tracing for unexpected incoming or predecessor decoding failures. Keep normal CAS rejection quiet; it is an expected outcome rather than a decoding fault.
| if entry.operation_id.is_some() { | ||
| entry.status = AssetLockStatus::Conflicted; | ||
| entry.proof = None; | ||
| let mut snapshot = AssetLockEntry::from(&*entry); | ||
| snapshot.advance_operation_revision(); | ||
| entry.operation_revision = snapshot.operation_revision; | ||
| cs.asset_locks.insert(out_point, snapshot); |
There was a problem hiding this comment.
🔴 Blocking: Make active proof waits observe the funding conflict
A sweep now retains this lock as Conflicted, but an already-running proof wait never examines that state. After Platform rejects an InstantSend proof, fund_from_asset_lock.rs calls upgrade_to_chain_lock_proof with the caller's wait policy; the drain FFI passes None. The pinned key-wallet allows a chainlocked winner to sweep an InstantSend-locked loser and removes the losing transaction records. If that happens after wait_for_chain_lock starts, its loop continues checking transaction records and the mined-height locator indefinitely, even after the conflict is durable. The drain consequently retains shield_guard and blocks subsequent shield-class operations. Make the shared proof-wait paths stop on committed conflict evidence, without publishing an uncommitted conflict as a durable outcome, and cover a sweep arriving after the wait has started.
source: gpt-6.1-sol (phase2-reviewer: general)
| if revision > MAX_ASSET_LOCK_OPERATION_REVISION { | ||
| return Err(PersistenceError::backend( | ||
| "asset-lock operation revision out of range", | ||
| )); | ||
| } | ||
| lock.operation_revision = revision; |
There was a problem hiding this comment.
🔴 Blocking: Validate restored operation evidence in the wallet owner
The revision loader checks only the upper bound, and the surrounding restore path never validates the relationship between status, revision, and operation ID after reconstructing both sidecars. A successful UUID callback returning found=false followed by a revision callback returning 1 therefore accepts a Conflicted or recovered row with no UUID. Swift's loader permits the same combination, whereas SQLite's decode_row explicitly rejects it. After reopening, wallet_drain_operation_status_inner searches by UUID and misses this evidence, allowing NotSent; begin_wallet_drain also excludes the unbound row from its pending-operation gate and can build replacement funding for the original UUID. Conflicted rows at revision zero are accepted as well. Add a wallet-owned recovery-metadata invariant and invoke it after complete reconstruction in both restore paths. Invalid combinations must fail the entire load rather than become absent operation history.
source: gpt-6.1-sol (phase2-reviewer: general, architecture-layering, ffi-engineer, rust-quality, security-auditor)
| var conflict = snapshot(status: 7, operationId: operationId) | ||
| conflict.operationRevision = 1 | ||
| conflict.expectedOperationRevision = 0 | ||
| handler.beginChangeset(walletId: walletId) | ||
| XCTAssertTrue(handler.persistAssetLocks(walletId: walletId, upserts: [conflict], removed: [], revisionAware: true)) |
There was a problem hiding this comment.
🔴 Blocking: Use Rust-decodable transaction fixtures in the revision-aware Swift tests
The new revisionAware calls enter asset_lock_operation_persistence_action through withOperationFFI, and Rust consensus-decodes both snapshots through build_unused_asset_locks. The shared snapshot fixture supplies [3, 0, 0, 0, 0, 0, 0, 0, 0, 0]. In the pinned rust-dashcore decoder, its empty input vector selects witness decoding and the following zero produces UnsupportedSegwitFlag(0). The FFI action therefore returns 0 and persistAssetLocks returns false at this assertion and the corresponding assertion in testV4OperationBindingMigratesWithLegacyRevisionAndSurvivesReopen. The stale-snapshot assertion also passes for the wrong reason, before revision acceptance runs. Replace the placeholder with consensus-encoded transaction bytes shared by the predecessor and incoming snapshots; do not weaken the production decoder.
source: gpt-6.1-sol (phase2-reviewer: ffi-engineer)
| if !txids.contains(&lock.out_point.txid) | ||
| || lock.status.is_consumed() | ||
| || lock.status == AssetLockStatus::Conflicted | ||
| { | ||
| continue; | ||
| } | ||
| if lock.operation_id.is_some() { | ||
| lock.status = AssetLockStatus::Conflicted; | ||
| lock.proof = None; | ||
| let mut entry = AssetLockEntry::from(&lock); | ||
| entry.advance_operation_revision(); | ||
| changes.asset_locks.insert(lock.out_point, entry); | ||
| } else { | ||
| changes.removed.insert(lock.out_point); |
There was a problem hiding this comment.
🟡 Suggestion: Share the conflict projection with the wallet's live sweep path
The replay adapter independently decides whether a swept lock is removed or retained, changes its status to Conflicted, clears its proof, and advances its operation revision. The live remove_tracked_asset_locks_for_swept path implements the same wallet-state decisions separately. They currently agree, but a lifecycle change can update live handling without updating restart repair. Extract a pure swept-lock projection into rs-platform-wallet and call it from both paths, leaving row selection and transactional writes in platform-wallet-storage.
source: gpt-6.1-sol (phase2-reviewer: architecture-layering)
| if self.expected_operation_revision.is_some() | ||
| && self.operation_revision == previous.operation_revision | ||
| { | ||
| let mut incoming = self.clone(); | ||
| incoming.expected_operation_revision = None; | ||
| let mut stored = previous.clone(); | ||
| stored.expected_operation_revision = None; | ||
| return incoming == stored; |
There was a problem hiding this comment.
🟡 Suggestion: Compare CAS redeliveries without cloning complete snapshots
The exact-redelivery branch clones both AssetLockEntry values solely to clear expected_operation_revision before comparing them. Each clone duplicates the transaction and optional proof even though this operation only needs borrowed equality checks. SQLite persistence and the FFI owner check both reach this branch when a committed CAS is redelivered. Use a borrowed comparison helper or borrowed field tuple that excludes the precondition, preserving equality over every other field without allocating two complete snapshots.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
| let mut changes = AssetLockChangeSet::default(); | ||
| for mut lock in load_unconsumed(tx, wallet_id, &LoadCtx::strict())? | ||
| .into_values() | ||
| .flat_map(BTreeMap::into_values) | ||
| { | ||
| let mut stmt = tx.prepare_cached( | ||
| "SELECT length(outpoint), outpoint FROM asset_locks WHERE wallet_id = ?1 AND status != 'consumed'", | ||
| )?; | ||
| let mut rows = stmt.query(params![wallet_id.as_slice()])?; | ||
| while let Some(row) = rows.next()? { | ||
| blob::check_size(row.get(0)?)?; | ||
| let bytes: Vec<u8> = row.get(1)?; | ||
| let outpoint = blob::decode_outpoint(&bytes)?; | ||
| if txids.contains(&outpoint.txid) { | ||
| changes.removed.insert(outpoint); | ||
| } | ||
| if !txids.contains(&lock.out_point.txid) |
There was a problem hiding this comment.
🟡 Suggestion: Filter sweep candidates before decoding lifecycle blobs
remove_swept now calls load_unconsumed for the whole wallet and only then filters by the swept transaction IDs. That helper reads and decodes every selected lifecycle blob, transaction, and proof, including unrelated locks and UUID-bound terminal tombstones. The previous implementation inspected outpoints before selecting matching losers. On a wallet with substantial retained history, repairing a small sweep therefore performs unnecessary full-history decoding inside the repair transaction. Select candidate outpoints first and decode only matching rows before applying the wallet-owned projection.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
| let Some(incoming) = incoming.as_ref() else { | ||
| return 0; | ||
| }; | ||
| let Ok(incoming) = incoming.decode() else { | ||
| return 0; | ||
| }; | ||
| let previous = match previous.as_ref().map(|entry| entry.decode()).transpose() { | ||
| Ok(previous) => previous, | ||
| Err(_) => return 0, |
There was a problem hiding this comment.
🟡 Suggestion: Retain diagnostics for malformed FFI operation snapshots
Both decode failures discard their PersistenceError and return the same 0 used for an ordinary policy rejection. The host can only report a rejected persistence round, with no diagnostic distinguishing malformed transaction/proof bytes from a stale CAS. Preserve the stable return-code contract, but emit contextual tracing for unexpected incoming or predecessor decoding failures. Keep normal CAS rejection quiet; it is an expected outcome rather than a decoding fault.
source: muse-spark-1.3-contributor (phase1-reviewer: general, rust-quality)
|
Merge-order note: #5762 lands in
|
…Lite Preserve the final PR scope, including merge resolutions, on the updated native stack. Co-Authored-By: Codex <[email protected]>
…conflicts Preserve the final PR scope, including merge resolutions, on the updated native stack. Co-Authored-By: Codex <[email protected]>
…sion loss Co-Authored-By: Codex <[email protected]>
25c63bd to
fcb8881
Compare
…flicts Keep the recipient bound to the outpoint while funding is conflicted and reuse the binding when authenticated Core finality restores the funding. Fence stale snapshots and removals across wallet state, SQLite and SwiftData while preserving the legacy callback format. Co-Authored-By: Codex <[email protected]>
Basic explanation
What this does: A wallet remembers an interrupted drain operation and its intended shielded recipient when the funding transaction loses a conflict. Restarting or retrying preserves the original funding output and recipient.
Value: A conflicted funding output stays non-actionable. It can resume after authenticated recovery of that same output, paying the recorded recipient and refusing a different address.
Risks: This changes local wallet persistence and host bindings. SwiftData migration/restart and Swift runtime validation require macOS CI.
Issue being fixed or feature implemented
Stacked on #5210 (
feat/sqlite-wallet-restore). Funding-conflict cleanup discarded the metadata needed to distinguish an interrupted operation from a new one. It could also discard a shielded recipient even when the lock had no operation UUID. This addresses T3 from #5210's merge TODO.What was done?
Conflicted, clear actionable proofs, and reactivate only after authenticated recovery of the original funding output. Mempool sightings leave the conflict intact.Builtrows remain removable.How Has This Been Tested?
platform-wallet,platform-wallet-storageandplatform-wallet-ffiwith CI flags (--locked --all-targets --all-features -- --no-deps -D warnings). Rust formatting and diff checks pass.Breaking Changes
Rust asset-lock structs gain revision fields and enums gain
Conflicted. The new operation carrier and removal predicate require corresponding Rust/Swift bindings. Existing legacy asset-lock rows use their existing layout. Hosts need ordered persistence callbacks for durable operation recovery.Core accounting issue dashpay/rust-dashcore#1213 and general history repair remain outside scope.
🤖 Co-authored by Claudius the Magnificent AI Agent