Skip to content

silent payments: integrate SPDK scanning and wallet IPC - #47

Closed
pzafonte wants to merge 4 commits into
kernel-node:masterfrom
pzafonte:silent-payments
Closed

silent payments: integrate SPDK scanning and wallet IPC#47
pzafonte wants to merge 4 commits into
kernel-node:masterfrom
pzafonte:silent-payments

Conversation

@pzafonte

@pzafonte pzafonte commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Integrate BIP-352 silent payment scanning into kernel-node using the silentpayments crate from SPDK.

  • Add crates/wallet as a workspace member with a silentpayments submodule that wraps SPDK's cryptographic primitives
  • Scan each accepted block for payments using kernel undo data to recover prevout scripts
  • Track received UTXOs and balance in an in-memory wallet
  • Expose import_keys, balance, and history over a dedicated Cap'n Proto Unix socket (wallet.sock)
  • Handle headers-first block announcements

Comment thread src/silentpayments/mod.rs Outdated
Comment thread src/silentpayments/mod.rs Outdated
Comment thread src/silentpayments/mod.rs Outdated
Comment thread src/silentpayments/mod.rs Outdated

#[test]
#[allow(clippy::type_complexity)]
fn bip352_official_receiving_vectors() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the word "official" can be dropped here. There is only one reference BIP

Comment thread src/silentpayments/mod.rs Outdated
Comment thread src/silentpayments/mod.rs Outdated
Comment thread src/silentpayments/mod.rs Outdated
Comment thread src/silentpayments/mod.rs Outdated
std::fs::remove_file(&path).ok();
}

fn hex_decode(s: &str) -> Vec<u8> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this function in favor of the hex crate re-exported from bitcoin.

Comment thread src/silentpayments/mod.rs Outdated
@rustaceanrob

Copy link
Copy Markdown
Contributor

7bde2e0 includes a new file that isn't actually linked to the project. It should otherwise not compile. Let's start by separating the commits such that each commit compiles, and the silentpayments module is included in lib at each step. I will continue code review in the meantime.

Comment thread src/silentpayments/mod.rs Outdated
@yancyribbens

Copy link
Copy Markdown
Contributor

I notice there is also bip 352 on crates.io. Any reason to prefer re-writing it instead of importing the existing crate, forking the existing crate, or forking and add a PR back to existing crate? If the existing bip352 crate is too unusable, maybe make a new crate for BIP 352?

@rustaceanrob

Copy link
Copy Markdown
Contributor

Any reason to prefer re-writing it instead of importing the existing crate, forking the existing crate, or forking and add a PR back to existing crate?

I would prefer to not have a dependency that is bitcoin-related that we don't directly manage the release cycle of or is not well-reviewed and widely used (i.e. BDK). Reviewing a copy-paste of that crate into here would be essentially the same amount of review. While I agree it's not great to have a complete re-write, I think we should go ahead and do it here, and once BDK has support for silent payments, we do a drop-in replacement.

@yancyribbens

Copy link
Copy Markdown
Contributor

I would prefer to not have a dependency that is bitcoin-related that we don't directly manage the release cycle of or is not well-reviewed and widely used (i.e. BDK). Reviewing a copy-paste of that crate into here would be essentially the same amount of review. While I agree it's not great to have a complete re-write, I think we should go ahead and do it here, and once BDK has support for silent payments, we do a drop-in replacement.

I'm not arguing against any or those points. However, I do think it would make sense for this to be contained within it's own crate.

@pzafonte

Copy link
Copy Markdown
Contributor Author

Addressed all the feedback thus far in 7e03e6d

Should we extract this into its own crate in this PR?

@yancyribbens

Copy link
Copy Markdown
Contributor

Should we extract this into its own crate in this PR?

I think so.

@rustaceanrob

rustaceanrob commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

I recommend something like crates/wallet/silentpayments.mod so we can keep both what we want in crates and what makes up a wallet flexible. I'll code review the first commit now, but I think it should be created in the first commit.

@yancyribbens

Copy link
Copy Markdown
Contributor

There is also an entire "dev kit" for silent payments in Rust: https://github.com/cygnet3/spdk. I noticed this is being added to to electrs which is a mature project.

@rustaceanrob

Copy link
Copy Markdown
Contributor

Oh interesting...

I trust both the lead dev and the electrs guys. We should probably look into this.

@rustaceanrob

rustaceanrob commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

I reviewed SPDK and have some thoughts about path forward. The examples look intuitive and easy to integrate. Although there are some drawbacks, in that the crate brings in quite a few dependencies, I have more faith in them (electrs) maintaining the crate than bringing in custom SP logic here.

@pzafonte I think we should repurpose this PR to integrate SPDK, however there is a blocker before you can get started. I was overly optimistic on the timeline for bitcoin = 0.33 and the new rust-bitcoin crates. Some of the crates here depend on what is essentially a random commit in rust-bitcoin. You'll have to give me until about end-of-week to revert or add a branch to those crates to use bitcoin = 0.32.8. Once that is ready, we can get started with integrating SPDK.

@rustaceanrob

Copy link
Copy Markdown
Contributor

#48 is merged so bitcoin is now compatible with SPDK

@pzafonte

Copy link
Copy Markdown
Contributor Author

#48 is merged so bitcoin is now compatible with SPDK

Great! I'll get started on this soon.

Introduce crates/wallet as a workspace member containing a
silentpayments submodule. The module wraps the silentpayments crate
to provide scan_block, which takes kernel undo data (InputData) and
returns found payments, and SilentPaymentWallet, which tracks owned
UTXOs and history in memory.

The crate is structured with pub mod silentpayments so other wallet
backends can be added alongside it without restructuring.
Add wallet.capnp defining import_keys, get_balance, and get_history
methods. Implement WalletIpcInterface and WalletState, which share the
SilentPaymentWallet between the block-scanning thread and the IPC
server via Arc<Mutex<>>. The wallet socket is kept separate from
node.sock so wallet commands do not block node commands.
Wire scan_kernel_block into the block processing loop so each accepted
block is scanned for payments to the imported keys. Read kernel undo
data to recover prevout scripts and call wallet::silentpayments::scan_block.
The scan is a no-op until keys are imported, so nodes without a wallet
configured are unaffected.

Start a dedicated wallet.sock listener alongside the existing node.sock
so the IPC server and block-processing thread can share WalletState safely.

Peers send a headers message rather than inv to announce new blocks to
nodes that previously sent getheaders. Handle this in AwaitingInv so
the node continues to receive new blocks.
Add import-keys, balance, and history subcommands under a wallet
subcommand group. Each connects to wallet.sock rather than node.sock
so wallet operations are independent of node RPC.
@pzafonte
pzafonte force-pushed the silent-payments branch from a69aab9 to e8ec66d Compare May 1, 2026 00:44
@pzafonte pzafonte changed the title silent payments: add BIP-352 receiver-side scanning and wallet silent payments: integrate SPDK scanning and wallet IPC May 1, 2026
@pzafonte

pzafonte commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

Rewrote using SPDK and rebased on #49
Everything updated in 96408a7, a149e9a, 42910cc, e8ec66d

@yancyribbens

Copy link
Copy Markdown
Contributor

Rewrote using SPDK and rebased on #49

Don't be afraid to open a new PR. This one is pretty scratched up with review comments that no longer apply.

@pzafonte pzafonte closed this May 2, 2026
@pzafonte

pzafonte commented May 2, 2026

Copy link
Copy Markdown
Contributor Author

Opened fresh PR in #50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants