Skip to content

Onchain bdk#1870

Open
thesimplekid wants to merge 23 commits into
cashubtc:mainfrom
thesimplekid:onchain_bdk
Open

Onchain bdk#1870
thesimplekid wants to merge 23 commits into
cashubtc:mainfrom
thesimplekid:onchain_bdk

Conversation

@thesimplekid
Copy link
Copy Markdown
Collaborator

@thesimplekid thesimplekid commented Apr 9, 2026

Description


closes: #1803

Notes to the reviewers


Suggested CHANGELOG Updates

CHANGED

ADDED

REMOVED

FIXED


Checklist

@github-project-automation github-project-automation Bot moved this to Backlog in CDK Apr 9, 2026
@thesimplekid thesimplekid force-pushed the onchain_bdk branch 2 times, most recently from ca08cae to bdc06cf Compare April 10, 2026 08:14
@thesimplekid thesimplekid added this to the 0.17.0 milestone Apr 10, 2026
@thesimplekid thesimplekid force-pushed the onchain_bdk branch 4 times, most recently from 3a49397 to caf4bec Compare April 17, 2026 14:40
@thesimplekid thesimplekid added the stacked hold PR is based on top of another PR, so should be merged in sequence. See comments for details. label Apr 17, 2026
@thesimplekid thesimplekid force-pushed the onchain_bdk branch 2 times, most recently from 73b5d6f to 514296e Compare April 22, 2026 14:27
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 74.85349% with 1888 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.29%. Comparing base (8ce06b1) to head (2244072).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
crates/cdk-bdk/src/send/service.rs 53.50% 351 Missing ⚠️
crates/cdk-bdk/src/chain/bitcoin_rpc.rs 19.04% 187 Missing ⚠️
...k-integration-tests/src/bin/start_regtest_mints.rs 0.00% 171 Missing ⚠️
crates/cdk-bdk/src/recovery.rs 71.97% 146 Missing ⚠️
crates/cdk-bdk/src/receive/service.rs 5.73% 115 Missing ⚠️
crates/cdk-bdk/src/chain/esplora.rs 58.41% 84 Missing ⚠️
crates/cdk-mintd/src/lib.rs 0.00% 79 Missing ⚠️
crates/cdk-common/src/melt.rs 42.22% 78 Missing ⚠️
crates/cdk-bdk/src/send/batch_transaction/mod.rs 76.32% 58 Missing ⚠️
crates/cdk-mintd/src/env_vars/bdk.rs 50.00% 57 Missing ⚠️
... and 47 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1870      +/-   ##
==========================================
+ Coverage   65.16%   66.29%   +1.12%     
==========================================
  Files         330      353      +23     
  Lines       56742    64375    +7633     
==========================================
+ Hits        36976    42675    +5699     
- Misses      19766    21700    +1934     

☔ View full report in Codecov by Sentry.
📢 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.

@thesimplekid thesimplekid removed the stacked hold PR is based on top of another PR, so should be merged in sequence. See comments for details. label Apr 24, 2026
@thesimplekid thesimplekid marked this pull request as ready for review April 24, 2026 12:43
@thesimplekid thesimplekid force-pushed the onchain_bdk branch 2 times, most recently from 19c59db to 6a656d2 Compare April 24, 2026 16:24
@TheMhv
Copy link
Copy Markdown
Contributor

TheMhv commented Apr 26, 2026

I tried to run regtest mode on this branch and i got an error:

Error: BDK mnemonic must be set

---
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.29s
     Running `target/debug/cdk-mintd`
2026-04-26T12:58:39.941164Z  INFO cdk_mintd: Logging initialized: console (DEBUG+) and file at /tmp/nix-shell.DM34mL/tmp.SPEjHWfVg9/cln_mint/logs/cdk-mintd.log (DEBUG+)
2026-04-26T12:58:39.941239Z  INFO cdk_mintd: Initializing database...
2026-04-26T12:58:39.941257Z  INFO cdk_mintd: Using database engine: Sqlite
2026-04-26T12:58:39.941268Z  INFO cdk_mintd: SQLite database path: /tmp/nix-shell.DM34mL/tmp.SPEjHWfVg9/cln_mint/cdk-mintd.sqlite
2026-04-26T12:58:39.942863Z  INFO cdk_mintd: SQLite database initialized successfully
2026-04-26T12:58:39.942882Z  INFO cdk_mintd: Database initialized successfully
2026-04-26T12:58:39.943013Z DEBUG cdk_mintd: Ln backend: Cln
2026-04-26T12:58:39.943435Z  INFO cdk_mintd: Shutting down logging worker thread
2026-04-26T12:58:40.044644Z  INFO cdk_mintd: Mintd shutdown
Error: BDK mnemonic must be set

Stack backtrace:
   0: anyhow::error::<impl anyhow::Error>::msg
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/backtrace.rs:10:14
   1: anyhow::__private::format_err
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/anyhow-1.0.102/src/lib.rs:687:13
   2: <cdk_mintd::config::Bdk as cdk_mintd::setup::OnchainBackendSetup>::setup::{{closure}}
             at ./crates/cdk-mintd/src/setup.rs:520:21
   3: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/core/src/future/future.rs:133:9
   4: cdk_mintd::configure_onchain_backend::{{closure}}
             at ./crates/cdk-mintd/src/lib.rs:716:22
   5: cdk_mintd::configure_mint_builder::{{closure}}
             at ./crates/cdk-mintd/src/lib.rs:410:88
   6: cdk_mintd::run_mintd_with_shutdown::{{closure}}
             at ./crates/cdk-mintd/src/lib.rs:1535:91
   7: cdk_mintd::run_mintd::{{closure}}
             at ./crates/cdk-mintd/src/lib.rs:1480:6
   8: cdk_mintd::main::{{closure}}
             at ./crates/cdk-mintd/src/main.rs:35:10
   9: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/core/src/future/future.rs:133:9
  10: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/park.rs:284:71
  11: tokio::task::coop::with_budget
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/task/coop/mod.rs:167:5
  12: tokio::task::coop::budget
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/task/coop/mod.rs:133:5
  13: tokio::runtime::park::CachedParkThread::block_on
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/park.rs:284:31
  14: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/context/blocking.rs:66:14
  15: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/scheduler/multi_thread/mod.rs:92:22
  16: tokio::runtime::context::runtime::enter_runtime
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/context/runtime.rs:65:16
  17: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/scheduler/multi_thread/mod.rs:91:9
  18: tokio::runtime::runtime::Runtime::block_on_inner
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/runtime.rs:373:50
  19: tokio::runtime::runtime::Runtime::block_on
             at /home/themhv/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.52.1/src/runtime/runtime.rs:343:18
  20: cdk_mintd::main
             at ./crates/cdk-mintd/src/main.rs:16:8
  21: core::ops::function::FnOnce::call_once
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/core/src/ops/function.rs:250:5
  22: std::sys::backtrace::__rust_begin_short_backtrace
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/sys/backtrace.rs:166:18
  23: std::rt::lang_start::{{closure}}
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/rt.rs:206:18
  24: <&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe as core::ops::function::FnOnce<()>>::call_once
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/core/src/ops/function.rs:287:21
  25: std::panicking::catch_unwind::do_call::<&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe, i32>
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/panicking.rs:581:40
  26: std::panicking::catch_unwind::<i32, &dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe>
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/panicking.rs:544:19
  27: std::panic::catch_unwind::<&dyn core::ops::function::Fn<(), Output = i32> + core::marker::Sync + core::panic::unwind_safe::RefUnwindSafe, i32>
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/panic.rs:359:14
  28: std::rt::lang_start_internal::{closure#0}
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/rt.rs:175:24
  29: std::panicking::catch_unwind::do_call::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/panicking.rs:581:40
  30: std::panicking::catch_unwind::<isize, std::rt::lang_start_internal::{closure#0}>
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/panicking.rs:544:19
  31: std::panic::catch_unwind::<std::rt::lang_start_internal::{closure#0}, isize>
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/panic.rs:359:14
  32: std::rt::lang_start_internal
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/rt.rs:171:5
  33: std::rt::lang_start
             at /rustc/59807616e1fa2540724bfbac14d7976d7e4a3860/library/std/src/rt.rs:205:5
  34: main
  35: __libc_start_call_main
  36: __libc_start_main@@GLIBC_2.34
  37: _start

Copy link
Copy Markdown
Contributor

@TheMhv TheMhv left a comment

Choose a reason for hiding this comment

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

Need to add BDK mnemonic env var to run regtest mode

export CDK_MINTD_LOGGING_FILE_LEVEL="debug"
export RUST_BACKTRACE=1
export CDK_MINTD_DATABASE="$CDK_MINTD_DATABASE"
export CDK_MINTD_ONCHAIN_BACKEND="bdk"
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.

Suggested change
export CDK_MINTD_ONCHAIN_BACKEND="bdk"
export CDK_MINTD_BDK_MNEMONIC="eye survey guilt napkin crystal cup whisper salt luggage manage unveil loyal"
export CDK_MINTD_ONCHAIN_BACKEND="bdk"

export CDK_MINTD_LOGGING_FILE_LEVEL="debug"
export RUST_BACKTRACE=1
export CDK_MINTD_DATABASE="$CDK_MINTD_DATABASE"
export CDK_MINTD_ONCHAIN_BACKEND="bdk"
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.

Suggested change
export CDK_MINTD_ONCHAIN_BACKEND="bdk"
export CDK_MINTD_BDK_MNEMONIC="cattle gold bind busy sound reduce tone addict baby spend february strategy"
export CDK_MINTD_ONCHAIN_BACKEND="bdk"

export CDK_MINTD_MNEMONIC="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
export RUST_BACKTRACE=1
export CDK_MINTD_DATABASE="$CDK_MINTD_DATABASE"
export CDK_MINTD_ONCHAIN_BACKEND="bdk"
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.

Suggested change
export CDK_MINTD_ONCHAIN_BACKEND="bdk"
export CDK_MINTD_BDK_MNEMONIC="abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
export CDK_MINTD_ONCHAIN_BACKEND="bdk"

@github-project-automation github-project-automation Bot moved this from Backlog to In progress in CDK Apr 26, 2026
@TheMhv
Copy link
Copy Markdown
Contributor

TheMhv commented Apr 30, 2026

closes #1803

@thesimplekid thesimplekid force-pushed the onchain_bdk branch 2 times, most recently from 8b23986 to 78eff9f Compare May 7, 2026 15:42
@robwoodgate
Copy link
Copy Markdown
Contributor

robwoodgate commented May 7, 2026

Can we get a "fakeonchain" backend that credits amount_paid immediately (or after a fake "block delay") without needing real chain activity? Would make it possible to run CI integration tests, like we do for bolt11.

@robwoodgate
Copy link
Copy Markdown
Contributor

robwoodgate commented May 7, 2026

There might be an issue / race with the mutinynet test mint...?

Quote ID: 7c6dbf96-b28e-4b22-a234-98bbcd60cb24
Address: tb1qh35fjcnycd66tq9gp4zs8l8x0usaadl7fxc4wz was funded with 500 sats iin block 3082431; mint still reports amount_paid: 0 at block 3082459 (29 confs).

Possibly a race between quote creation and the address watcher subscribing?
A second quote made afterwards was paid ok.

@robwoodgate
Copy link
Copy Markdown
Contributor

robwoodgate commented May 7, 2026

Some inconsistencies I've found in my testing of onchain so far:

  • outpoint on the onchain melt quote response is omitted when there's no outpoint yet. Spec (NUT-XX L138) is <str | null>.

  • expiry on mint quote responses comes back as 0 when there's no expiry. Spec (NUT-XX L31, NUT-23 L32, NUT-25 L36) is <int | null>.

  • selected_estimated_blocks on the same melt quote response DOES come back as null correctly. Spec (NUT-XX L137) is <str | null>.

@thesimplekid
Copy link
Copy Markdown
Collaborator Author

thesimplekid commented May 7, 2026

There might be an issue / race with the mutinynet test mint...?

Quote ID: 7c6dbf96-b28e-4b22-a234-98bbcd60cb24 Address: tb1qh35fjcnycd66tq9gp4zs8l8x0usaadl7fxc4wz was funded with 500 sats iin block 3082431; mint still reports amount_paid: 0 at block 3082459 (29 confs).

Possibly a race between quote creation and the address watcher subscribing? A second quote made afterwards was paid ok.

This due to cdk-bdk ignoring utxo's less then 1000 sats by default to avoid dust attacks.

What is the issue is in the mint info shows this isn't shown correctly.

@robwoodgate
Copy link
Copy Markdown
Contributor

robwoodgate commented May 8, 2026

There might be an issue / race with the mutinynet test mint...?
Quote ID: 7c6dbf96-b28e-4b22-a234-98bbcd60cb24 Address: tb1qh35fjcnycd66tq9gp4zs8l8x0usaadl7fxc4wz was funded with 500 sats iin block 3082431; mint still reports amount_paid: 0 at block 3082459 (29 confs).
Possibly a race between quote creation and the address watcher subscribing? A second quote made afterwards was paid ok.

This due to cdk-bdk ignoring utxo's less then 1000 sats by default to avoid dust attacks.

What is is issue is we don't the mint info shows this correctly.

Ah that explains it... yes, the mintinfo is wrong in the test mint - it says min_amount: 1

Assuming Mint will error and reject a melt quote creation request outside the advertised min/max range (once corrected)?

@thesimplekid
Copy link
Copy Markdown
Collaborator Author

Assuming Mint will error and reject a melt quote creation request outside the advertised min/max range (once corrected)?

This is corrected on the test mint now. And yes melt quotes outside the limits will be rejected, mint quotes do not have an amount so we cannot.

- Pass optional onchain config through create_fake_wallet_settings()
- Add onchain: None field to Settings struct literals in regtest mint setup
Adds robust handling for failed send intents in cdk-bdk, including tombstone records and the ability to retry failed intents with the same quote ID. Enhances signed batch recovery to repair or safely abort when recovering pending members.
Introduces `BroadcastOutcome` and `BroadcastFailure` to the chain source interface to distinguish between transient network issues, deterministic rejections, and already-known transactions. Applies this classification to both esplora and bitcoin_rpc backends, improving the robustness of batch rebroadcasting and recovery.
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.

Add support for onchain payment method with bdk

3 participants