Skip to content

Comments

Payjoin persistence#242

Draft
Mshehu5 wants to merge 8 commits intobitcoindevkit:masterfrom
Mshehu5:payjion_persistance
Draft

Payjoin persistence#242
Mshehu5 wants to merge 8 commits intobitcoindevkit:masterfrom
Mshehu5:payjion_persistance

Conversation

@Mshehu5
Copy link
Contributor

@Mshehu5 Mshehu5 commented Feb 16, 2026

Description

Open as draft cause #230 needs to be merged first
Address #149 also follow up to #200
This PR adds persistance to existing async payjoin integration
This introduces neccessary database model and tables also add commad for resume to allow interrupted sessions to be continued also a particular session either send or receive.
A history commad to view payjoin history and status has been added

Notes to the reviewers

Review for this PR can start at 8614e22

Step to review this include making a payjoin transaction

Run a receiver to get a BIP21 URI then pass it to the sender as seen in docs

bdk-cli/README.md

Lines 121 to 141 in b9cf2ac

To start a Payjoin session as the receiver with regtest RPC and example OHTTP relays:
```
cargo run --features rpc -- --network regtest wallet --wallet payjoin_wallet1 config --ext-descriptor "wpkh(tprv8ZgxMBicQKsPd2PoUEcGNDHPZmVWgtPYERAwMG6qHheX6LN4oaazp3qZU7mykiaAZga1ZB2SJJR6Mriyq8MocMs7QTe7toaabSwTWu5fRFz/84h/1h/0h/0/*)#8guqp7rn" --client-type rpc --database-type sqlite --url "127.0.0.1:18443"
cargo run --features rpc -- wallet --wallet payjoin_wallet1 sync
cargo run --features rpc -- wallet --wallet payjoin_wallet1 balance
cargo run --features rpc -- wallet --wallet payjoin_wallet1 receive_payjoin --amount 400000 --max_fee_rate 1000 --directory "https://payjo.in" --ohttp_relay "https://pj.bobspacebkk.com" --ohttp_relay "https://pj.benalleng.com"
```
To send a Payjoin with regtest RPC and example OHTTP relays:
```
cargo run --features rpc -- --network regtest wallet --wallet payjoin_wallet2 config --ext-descriptor "wpkh(tprv8ZgxMBicQKsPfBxswkATvZRQ9kDdRbJPtHYZaZCARL2myxcK7DqsqPhRo2G2rRVHFPbowq63BE6S4k2pUMYeF2fUMTT63Q7zhoXtKsM1FaS/84'/1'/0'/0/*)#qf5gnqrf" --client-type rpc --database-type sqlite --url "127.0.0.1:18443"
cargo run --features rpc -- wallet --wallet payjoin_wallet2 sync
cargo run --features rpc -- wallet --wallet payjoin_wallet2 balance
cargo run --features rpc -- wallet --wallet payjoin_wallet2 send_payjoin --ohttp_relay "https://pj.bobspacebkk.com" --ohttp_relay "https://pj.benalleng.com" --fee_rate 1 --uri "<URI>"
```

To test resumption, interrupt either side with Ctrl+C mid-session then run resume on that side to continue. A few scenarios worth covering: receiver resuming after interrupt and sender resuming after interrupt. Use history after each scenario to confirm the session state was persisted correctly.

docs for this can be seen in 7e4ffd1

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added docs for the new feature

Refactor KyotoClient to use a KyotoClientHandle struct instead of
Box<LightClient>. Previously, the Box<LightClient> was consumed
when destructured in sync_kyoto_client, preventing the function
from being called multiple times or borrowed. With the handle
pattern, sync_kyoto_client now takes &mut KyotoClientHandle,
allowing it to be borrowed and reused.

This also allows the node to be started at creation time in
new_blockchain_client rather than during sync, making the client
ready for use immediately after creation.

- Add KyotoClientHandle struct containing requester and
  update_subscriber
- Move node startup and logger spawning to new_blockchain_client
- Update sync_kyoto_client to accept &mut KyotoClientHandle
  instead of consuming Box<LightClient>
Update function signatures to accept &BlockchainClient instead of taking
ownership. This refactoring to allow the client to be Referenced across
multiple operations including repeated calls to sync_kyoto_client.

- Update handle_online_wallet_subcommand signature
- Update all PayjoinManager methods to use &BlockchainClient
- Fix parameter dereferencing in full_scan calls
- Update all call sites to pass references
Replace single sync-and-check with periodic polling loop.
This allows multiple sync operations since sync_wallet now accepts
a reference to BlockchainClient, enabling proper long-running
monitoring instead of a one-time check.
Replace Error::Generic with specific Payjoin error variants using #[from] derives for applicable places, enabling automatic conversion and eliminating verbose .map_err() calls.
- Create db.rs with Database, SenderPersister and ReceiverPersister
- Implement SessionPersister trait for both sender and receiver
- Add session ID management and query methods
- Add input deduplication tracking to prevent probing attacks
- Add timestamp formatting utilities
- Add database initialization in handlers
- Replace NoopSessionPersister with real persisters
- Implement session resumption for existing sessions
- Add input-seen-before tracking in receiver flow
- Remove verbose error wrapping (use ? operator)
- Implement resume_payjoins() to continue pending sessions
- Add history() to display all session states
- Add session status text helpers for UI display
- Support filtering by session ID
- Document resume and history commands
- Add sqlite dependecy for payjoin
@coveralls
Copy link

Pull Request Test Coverage Report for Build 22068931916

Details

  • 0 of 763 (0.0%) changed or added relevant lines in 5 files are covered.
  • 5 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-1.9%) to 8.848%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/error.rs 0 21 0.0%
src/utils.rs 0 22 0.0%
src/handlers.rs 0 50 0.0%
src/payjoin/db.rs 0 262 0.0%
src/payjoin/mod.rs 0 408 0.0%
Files with Coverage Reduction New Missed Lines %
src/utils.rs 1 0.0%
src/handlers.rs 2 12.81%
src/payjoin/mod.rs 2 0.0%
Totals Coverage Status
Change from base Build 21153868360: -1.9%
Covered Lines: 268
Relevant Lines: 3029

💛 - Coveralls

@notmandatory notmandatory moved this to In Progress in BDK-CLI Feb 18, 2026
@Mshehu5 Mshehu5 changed the title Payjoin persistance Payjoin persistence Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants