Skip to content

Commit 21cc5cf

Browse files
committed
fix: route swaps over private channels
1 parent 0d9762e commit 21cc5cf

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/routes.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2812,6 +2812,7 @@ pub(crate) async fn maker_execute(
28122812
let first_leg = get_route(
28132813
&unlocked_state.channel_manager,
28142814
&unlocked_state.router,
2815+
&state.static_state.ldk_data_dir,
28152816
unlocked_state.channel_manager.get_our_node_id(),
28162817
taker_pk,
28172818
if swap_info.is_to_btc() {
@@ -2829,6 +2830,7 @@ pub(crate) async fn maker_execute(
28292830
let second_leg = get_route(
28302831
&unlocked_state.channel_manager,
28312832
&unlocked_state.router,
2833+
&state.static_state.ldk_data_dir,
28322834
taker_pk,
28332835
unlocked_state.channel_manager.get_our_node_id(),
28342836
if swap_info.is_to_btc() || swap_info.is_asset_asset() {

src/utils.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,16 +405,35 @@ pub(crate) fn get_max_local_rgb_amount<'r>(
405405
max_balance
406406
}
407407

408+
#[allow(clippy::too_many_arguments)]
408409
pub(crate) fn get_route(
409410
channel_manager: &crate::ldk::ChannelManager,
410411
router: &crate::ldk::Router,
412+
ldk_data_dir_path: &Path,
411413
start: PublicKey,
412414
dest: PublicKey,
413415
final_value_msat: Option<u64>,
414416
rgb_payment: Option<(ContractId, u64)>,
415417
hints: Vec<RouteHint>,
416418
) -> Option<Route> {
417419
let inflight_htlcs = channel_manager.compute_inflight_htlcs();
420+
let usable_channels;
421+
let first_hops = if start == channel_manager.get_our_node_id() {
422+
usable_channels = channel_manager.list_usable_channels();
423+
let first_hops = usable_channels
424+
.iter()
425+
.filter(|channel| match rgb_payment {
426+
Some((contract_id, _)) => {
427+
get_rgb_channel_info_optional(&channel.channel_id, ldk_data_dir_path, false)
428+
.is_some_and(|(rgb_info, _)| rgb_info.contract_id == contract_id)
429+
}
430+
None => true,
431+
})
432+
.collect::<Vec<_>>();
433+
(!first_hops.is_empty()).then_some(first_hops)
434+
} else {
435+
None
436+
};
418437
let payment_params = PaymentParameters {
419438
payee: Payee::Clear {
420439
node_id: dest,
@@ -438,7 +457,7 @@ pub(crate) fn get_route(
438457
max_total_routing_fee_msat: None,
439458
rgb_payment,
440459
},
441-
None,
460+
first_hops.as_deref(),
442461
inflight_htlcs,
443462
);
444463

0 commit comments

Comments
 (0)