-
Notifications
You must be signed in to change notification settings - Fork 123
feat(cln): add expose_private_channels config option #1758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
thesimplekid
merged 4 commits into
cashubtc:main
from
4xvgal:feat/cln-expose-private-channels
Mar 25, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7554685
feat(cln): add expose_private_channels config option for invoice crea…
4xvgal 80d7118
test: use early-exit loop(100 attempts) for expose_private_channels test
4xvgal 33ff5ef
test: checking channel exist and skip if true
4xvgal 09f8627
chore: fmt
thesimplekid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
crates/cdk-integration-tests/tests/test_expose_private_channels.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| //! Test for CLN expose_private_channels feature | ||
| //! | ||
| //! Verifies that when expose_private_channels is enabled, bolt11 invoices | ||
| //! include route hints for private (unannounced) channels. | ||
| //! | ||
| //! Topology: | ||
| //! CLN-1 has public channels (to LND-1, LND-2) and a private channel (to CLN-2). | ||
| //! With expose_private_channels=true, private channels become route hint | ||
| //! candidates. CLN selects among all candidates per invoice, so the private | ||
| //! channel may not appear in every invoice but must appear in at least one. | ||
| //! | ||
| //! Requires regtest environment with CLN nodes running. | ||
|
|
||
| use std::str::FromStr; | ||
|
|
||
| use anyhow::Result; | ||
| use cashu::Bolt11Invoice; | ||
| use cdk::nuts::CurrencyUnit; | ||
| use cdk_common::payment::{Bolt11IncomingPaymentOptions, IncomingPaymentOptions, MintPayment}; | ||
| use cdk_integration_tests::init_regtest::{ | ||
| create_cln_backend_with_options, generate_block, get_cln_dir, init_bitcoin_client, | ||
| }; | ||
| use cdk_integration_tests::ln_regtest::ln_client::{ClnClient, LightningClient}; | ||
|
|
||
| fn get_work_dir() -> std::path::PathBuf { | ||
| match std::env::var("CDK_ITESTS_DIR") { | ||
| Ok(dir) => std::path::PathBuf::from(dir), | ||
| Err(_) => panic!("CDK_ITESTS_DIR not set"), | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "multi_thread", worker_threads = 1)] | ||
| async fn test_expose_private_channels() -> Result<()> { | ||
| // Skip if not in regtest environment | ||
| if std::env::var("CDK_TEST_REGTEST").is_err() { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let work_dir = get_work_dir(); | ||
|
|
||
| // Connect to CLN-1 and CLN-2 | ||
| let cln_one_dir = get_cln_dir(&work_dir, "one"); | ||
| let cln_two_dir = get_cln_dir(&work_dir, "two"); | ||
|
|
||
| let cln_one = ClnClient::new(cln_one_dir, None).await?; | ||
| let cln_two = ClnClient::new(cln_two_dir, None).await?; | ||
|
|
||
| // Open a private channel from CLN-1 to CLN-2 | ||
| let cln_two_info = cln_two.get_connect_info().await?; | ||
| cln_one | ||
| .connect_peer( | ||
| cln_two_info.pubkey.clone(), | ||
| cln_two_info.address.clone(), | ||
| cln_two_info.port, | ||
| ) | ||
| .await | ||
| .ok(); // May already be connected | ||
|
|
||
| // Only open private channel if it doesn't already exist | ||
| if let Err(e) = cln_one | ||
| .open_private_channel(100_000, &cln_two_info.pubkey, Some(50_000)) | ||
| .await | ||
| { | ||
| println!("Private channel already exists or could not be opened: {e}"); | ||
| } else { | ||
| // Mine blocks to confirm the new channel | ||
| let bitcoin_client = init_bitcoin_client()?; | ||
| generate_block(&bitcoin_client)?; | ||
| } | ||
|
|
||
| // Wait for channels to be active | ||
| cln_one.wait_channels_active().await?; | ||
|
|
||
| // Create backend with expose_private_channels = true | ||
| let cln_backend = create_cln_backend_with_options(&cln_one, true).await?; | ||
|
|
||
| let max_attempts = 100; | ||
| let mut found = false; | ||
|
|
||
| for i in 0..max_attempts { | ||
| let amount = cdk_common::amount::Amount::new(10_000, CurrencyUnit::Msat); | ||
| let response = cln_backend | ||
| .create_incoming_payment_request(IncomingPaymentOptions::Bolt11( | ||
| Bolt11IncomingPaymentOptions { | ||
| amount, | ||
| description: Some(format!("test exposed {i}")), | ||
| unix_expiry: None, | ||
| }, | ||
| )) | ||
| .await?; | ||
|
|
||
| let invoice = Bolt11Invoice::from_str(&response.request)?; | ||
| let hints = invoice.route_hints(); | ||
|
|
||
| let has_private_channel_hint = hints.iter().any(|hint| { | ||
| hint.0 | ||
| .iter() | ||
| .any(|hop| hop.src_node_id.to_string() == cln_two_info.pubkey) | ||
| }); | ||
|
|
||
| println!( | ||
| "Invoice {i}: private_channel_hint={has_private_channel_hint}, total_hints={}", | ||
| hints.len() | ||
| ); | ||
|
|
||
| if has_private_channel_hint { | ||
| println!("Private channel hint found on attempt {i}"); | ||
| found = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| assert!( | ||
| found, | ||
| "None of {max_attempts} invoices included the private channel route hint. \ | ||
| expose_private_channels=true should make private channels route hint candidates." | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would another option be on the start up of the mint list the cln channels and then pass in the channel ides on the exposeprivatechannels field of the request? I'm not necessarily requesting we do that instead this is probably simpler just trying to understand the api.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be cleaner from a cdk<-> cln API perspective. however, fetching short cheannel ids only at start up wouldn't detect channels opened after launch.
The root cause is that cln-rpc doesn't expose the needed fields in its tyepd API yet. Once the upstream issue is resolved, we won't need the startup-based approach or the raw JSON workaround in this PR.
For now, I think it makes sense to go with json-raw approach and switch over when the typed API catches up.