Repository navigation
fix(swaps): remove swap records in wipe_all_databases (#197) - #199
Tyagiquamar wants to merge 54 commits into
Conversation
iroh reads network interfaces through Network.framework, so apps that link BitkitCore without it fail with undefined nw_* symbols.
# Conflicts: # bindings/ios/bitkitcore.swift
# Conflicts: # Cargo.lock # Cargo.toml # Package.swift # bindings/android/gradle.properties
# Conflicts: # Cargo.lock # Cargo.toml # Package.swift # bindings/android/gradle.properties
…bky-swaps-route # Conflicts: # bindings/ios/bitkitcore.swift # src/modules/paykit_route/router.rs # src/modules/paykit_route/types.rs
…bky-swaps-route # Conflicts: # Cargo.lock # Cargo.toml # Package.swift # bindings/android/gradle.properties
A listed claim no longer counts as published, a claim is told from a refund by the preimage in its witness, and a restored swap needs a Lightning payment the wallet sent for its hash that covers its lockup. Restore also skips finished swaps and other networks, refuses a second record for a hash, reads only a missing record as absent, keeps partial lists, asks swap-list-v1 providers at once, and reports known and incomplete ids.
…pubky-swaps-route # Conflicts: # Cargo.lock # Cargo.toml # Package.swift # bindings/android/gradle.properties
Quotes and contracts now come over paykit-cap on direct/1 and are checked by swap-common's CapClient: terms and commit hashes, signatures, the invoice blob and both parties. A reply must be signed by the provider's key or the capability signing key its published records delegate to (Capabilities §5); unsigned replies and providers without paykit-cap-v1 are refused. swap-common moves to f45e204, and restore uses its min_reverse_lockup_sat.
An unsent saved claim waits for the lockup's confirmations again after a reorganization, and a claim of a lockup the provider replaced is built again for the new outpoint.
# Conflicts: # Cargo.lock # Cargo.toml # Package.swift # bindings/android/gradle.properties
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
talosmachina
left a comment
There was a problem hiding this comment.
1 finding (1 P1). Adds pubky_swaps::store::wipe_all() and calls it from wipe_all_databases() so swap records and their saved preimages do not survive a wallet reset. Reviewed 3016158, full tier, against base feat/pubky-swaps-route (4f3e215).
What I checked, and 3 candidates I ruled out
Build: not run here. The head is on a fork, so I did not run it locally. This is a static review plus the PR's own CI.
Read in full: src/modules/pubky_swaps/store.rs, the pubky_swaps/mod.rs exports, wipe_all_databases and init_db in src/lib.rs
CI: paykit-route-tests fails compiling the lib test target with E0603: enum SwapDirection is private at store.rs:157 (finding below). The bindgen and usdt/wake jobs were still pending when I read it.
Ruled out
- Wipe racing a concurrent
save/advance_swap: a reset is not run while swaps advance, andsavetakes the sameLOCK. The trigger is not reachable in practice. - Partial wipe on error: if the swap wipe fails after activity and blocktank were wiped, the result is a partial wipe. That is the same shape as the existing two steps, which already fail one after the other, so it is not new here.
- Wipe before
init_db:dir()returns the "not initialized" error, andwipe_all_databasesalready fails earlier on the same condition.
Merge confidence: 1/5, CI fails on the change itself: the lib test target does not compile.
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use swap_common::messages::{SwapDirection, SwapScript}; |
There was a problem hiding this comment.
Import
SwapDirection from the crate root, it is private in messages
swap_common::messages only uses SwapDirection privately (messages.rs:16, use crate::swap::{NetworkSpec, SwapDirection, SwapState};). Because of that, this import fails with E0603 and the whole bitkitcore lib test target stops compiling. That breaks every cargo test --lib run, including paykit-route-tests on this PR, not only the new tests. The sibling modules import it from the root (client.rs:28, cap.rs:169).
| use swap_common::messages::{SwapDirection, SwapScript}; | |
| use swap_common::messages::SwapScript; | |
| use swap_common::SwapDirection; |
Verified by: the paykit-route-tests job on this head, error[E0603]: enum SwapDirection is private --> src/modules/pubky_swaps/store.rs:157:33.
|
Retargeted to |
Summary
Fixes #197. Follow-up to #182 (Pubky Swaps routes).
Ensure that
wipe_all_databases()removespubky_swapsrecords from disk alongside existing activity and Blocktank database wiping, so that swap records and preimages do not survive a wallet reset.Root Cause & Problem
pubky_swapswrites each swap's persistent record tocore/pubky_swaps/*.json. These records contain the swap contract, destination address, amounts, and before broadcast, the saved claim whose witness carries the preimage.Previously,
wipe_all_databases()only wiped theactivity_dbandblocktank_dbinstances. During an in-app wallet wipe, LDK storage was wiped by the app reset and SQLite databases were wiped bywipe_all_databases(), but the swap records incore/pubky_swaps/were left untouched on disk. Consequently, swap history and saved preimages survived a wallet reset.Technical Solution
src/modules/pubky_swaps/store.rs, implementpub(crate) fn wipe_all() -> Result<(), PubkySwapError>:LOCK).pubky_swapsdirectory (dir()).src/modules/pubky_swaps/mod.rs, exportwipe_allfromstore.src/lib.rs, callmodules::pubky_swaps::wipe_all()withinwipe_all_databases(). If wiping fails, it returns a descriptiveDbError::InitializationError.test_store_wipe_allinsrc/modules/pubky_swaps/store.rsto verify thatwipe_all()clears all persisted swap records and that new records can be created after wiping.test_wipe_all_databases_removes_swap_recordsinsrc/lib.rsto verify end-to-end that callingwipe_all_databases()removes swap records from disk.Test Plan
cargo fmt --checkpasses with zero formatting issues.test_store_wipe_allinsrc/modules/pubky_swaps/store.rs.test_wipe_all_databases_removes_swap_recordsinsrc/lib.rs.