Skip to content

fix(create_sp_tx): propagate errors instead of panicking - #388

Merged
vadim-anfv merged 2 commits into
bitcoindevkit:masterfrom
bvotteler:fix/handlers-create-sp-tx
Nov 17, 2026
Merged

vadim-anfv merged 2 commits into
bitcoindevkit:masterfrom
bvotteler:fix/handlers-create-sp-tx

Conversation

@bvotteler

@bvotteler bvotteler commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes #380.

Propagate an error rather than panic when derive_sp returns an error inside create_sp_tx.

This is done by:

Expand: output before & after

Output before:

$ target/debug/bdk-cli wallet --wallet wsh_wallet create_sp_tx \
  --to-sp sprt1qqtnxgt7kn0fpr7fl0u0ndjj35f499y8t9hgmpkp8n2rmkr2gpjzyxqe3qp5n5apt0c5fas9xwy7002l0zqsuhrv7y9clz8yvhnmvut83lypguwer:20000
thread 'main' (3008870) panicked at src/handlers/offline.rs:508:76:
will fix later: MissingInputsForSharedSecretDerivation
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

(For output with backtrace, see issue description for #380)

Output after:

$ target/debug/bdk-cli wallet --wallet wsh_wallet create_sp_tx \
  --to-sp sprt1qqtnxgt7kn0fpr7fl0u0ndjj35f499y8t9hgmpkp8n2rmkr2gpjzyxqe3qp5n5apt0c5fas9xwy7002l0zqsuhrv7y9clz8yvhnmvut83lypguwer:20000
Error: Cannot create silent payment transaction: No available inputs for shared secret derivation

Notes to the reviewers

  • I wasn't readily able to come up with a test setup to hit the other branches (SinglePubKey::XOnly and DescriptorSecretKey::XPrv), either.
    The propagation method will do the same, either way. Therefore, I didn't try too hard to fabricate those scenarios. Happy to address that if preferred.
  • I added tests to tests/integration/online.rs despite the handler being in src/handlers/offline.rs, simply because that is where the currently existing silent payment tests live.
    Happy to move the test to tests/integrtion/offline if that is preferable.

Checklists

All Submissions:

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

Bugfixes:

  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@codecov

codecov Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.78%. Comparing base (e2811c0) to head (19a12c1).
⚠️ Report is 13 commits behind head on master.

Files with missing lines Patch % Lines
src/handlers/offline.rs 54.54% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #388      +/-   ##
==========================================
+ Coverage   59.63%   59.78%   +0.14%     
==========================================
  Files          25       25              
  Lines        4544     4550       +6     
==========================================
+ Hits         2710     2720      +10     
+ Misses       1834     1830       -4     
Flag Coverage Δ
rust 59.78% <54.54%> (+0.14%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you @bvotteler for working on this fix.

I have left some comments

Comment thread src/handlers/offline.rs Resolved
Comment thread src/handlers/offline.rs Resolved
@tvpeter

tvpeter commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Also, please fix the PR title, it does not follow the Conventional Commit style.

@bvotteler bvotteler changed the title Fix/handlers create sp tx fix(handlers): in create_sp_tx, propagate error instead of panic Nov 13, 2026
@bvotteler
bvotteler force-pushed the fix/handlers-create-sp-tx branch 2 times, most recently from f4b737b to 386b61e Compare November 13, 2026 14:11
@bvotteler bvotteler changed the title fix(handlers): in create_sp_tx, propagate error instead of panic fix(handlers): propagate errors instead of panic in create_sp_tx Nov 13, 2026
@bvotteler
bvotteler requested a review from tvpeter November 16, 2026 10:52
@tvpeter tvpeter changed the title fix(handlers): propagate errors instead of panic in create_sp_tx fix(create_sp_tx): propagate errors instead of panicking Nov 16, 2026

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ACK 386b61e

@tvpeter

tvpeter commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

Please rebase and ensure all CI tests are passing.

Remove .expect() and unimplemented!() calls
and replace them with errors. Wrap errors
from derive_sp(). Return generic errors for
the remaining cases.
Expect an error message to be propagated from
derive_sp, wrapped with explanation that it occurred
during silent payment transaction creation.
@bvotteler
bvotteler force-pushed the fix/handlers-create-sp-tx branch from 386b61e to 19a12c1 Compare November 16, 2026 19:52
@bvotteler

Copy link
Copy Markdown
Contributor Author

Please rebase and ensure all CI tests are passing.

Rebased and force pushed.
CI jobs build-test, clippy and fmt passed locally (tested with act).

I didn't try to run the Codecov job locally: Validation happens after upload it seems.
Even so, I suspect the missing edge cases (as discussed here) might cause it to fall short of the 80% mark for the patch.

@emma31-dev emma31-dev left a comment

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.

ACK 19a12c1

@vadim-anfv vadim-anfv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ACK 19a12c1

CI jobs build-test, clippy and fmt passed locally (tested with act).

Good. If you wish, just pre-push covers most of it without Docker.

@tvpeter the rebase changed the head, so your ACK is on the old commit.
Could you re-ACK?

@tvpeter tvpeter left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

reACK 19a12c1

@vadim-anfv
vadim-anfv merged commit 1c8026e into bitcoindevkit:master Nov 17, 2026
9 of 10 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in BDK-CLI Nov 17, 2026
@bvotteler
bvotteler deleted the fix/handlers-create-sp-tx branch November 17, 2026 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

create_sp_tx panics on derivation failure instead of returning an error

4 participants