Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2812,6 +2812,7 @@ pub(crate) async fn maker_execute(
let first_leg = get_route(
&unlocked_state.channel_manager,
&unlocked_state.router,
&state.static_state.ldk_data_dir,
unlocked_state.channel_manager.get_our_node_id(),
taker_pk,
if swap_info.is_to_btc() {
Expand All @@ -2829,6 +2830,7 @@ pub(crate) async fn maker_execute(
let second_leg = get_route(
&unlocked_state.channel_manager,
&unlocked_state.router,
&state.static_state.ldk_data_dir,
taker_pk,
unlocked_state.channel_manager.get_our_node_id(),
if swap_info.is_to_btc() || swap_info.is_asset_asset() {
Expand Down
2 changes: 2 additions & 0 deletions src/test/drop_funding_signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ async fn drop_funding_signed() {
None,
None,
true,
true,
)
.await
.unwrap();
Expand Down Expand Up @@ -94,6 +95,7 @@ async fn drop_funding_signed() {
None,
None,
true,
true,
)
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/test/missing_acceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ async fn missing_acceptor() {
None,
None,
true,
true,
)
.await
.unwrap();
Expand Down
7 changes: 6 additions & 1 deletion src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,7 @@ async fn open_channel_with_retry(
None,
None,
true,
true,
)
.await;

Expand Down Expand Up @@ -1259,6 +1260,7 @@ async fn open_channel_funded_raw(
fee_proportional_millionths: Option<u32>,
temporary_channel_id: Option<&str>,
with_anchors: bool,
public: bool,
) -> Result<Channel, Response> {
open_channel_raw(
node_address,
Expand All @@ -1273,6 +1275,7 @@ async fn open_channel_funded_raw(
fee_proportional_millionths,
temporary_channel_id,
with_anchors,
public,
)
.await?;

Expand Down Expand Up @@ -1352,6 +1355,7 @@ async fn open_channel_raw(
fee_proportional_millionths: Option<u32>,
temporary_channel_id: Option<&str>,
with_anchors: bool,
public: bool,
) -> Result<OpenChannelResponse, Response> {
println!(
"opening channel with {asset_amount:?} of asset {asset_id:?} from node {node_address} \
Expand Down Expand Up @@ -1383,7 +1387,7 @@ async fn open_channel_raw(
asset_amount,
asset_id: asset_id.map(|a| a.to_string()),
push_asset_amount,
public: true,
public,
with_anchors,
fee_base_msat,
fee_proportional_millionths,
Expand Down Expand Up @@ -1432,6 +1436,7 @@ async fn open_channel_with_custom_data(
fee_proportional_millionths,
temporary_channel_id,
with_anchors,
true,
)
.await
.expect("channel opening should succeed")
Expand Down
3 changes: 3 additions & 0 deletions src/test/openchannel_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async fn openchannel_fail() {
None,
None,
true,
true,
)
.await;
check_response_is_nok(
Expand Down Expand Up @@ -65,6 +66,7 @@ async fn openchannel_fail() {
None,
None,
true,
true,
)
.await;
check_response_is_nok(
Expand Down Expand Up @@ -95,6 +97,7 @@ async fn openchannel_fail() {
None,
None,
true,
true,
)
.await;
check_response_is_nok(
Expand Down
1 change: 1 addition & 0 deletions src/test/openchannel_no_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ async fn openchannel_no_indexer() {
None,
None,
true,
true,
)
.await;

Expand Down
62 changes: 62 additions & 0 deletions src/test/swap_reverse_same_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,66 @@ async fn swap_reverse_same_channel() {
assert_eq!(swaps_taker.taker.len(), 1);
let swap_taker = swaps_taker.taker.first().unwrap();
assert_eq!(swap_taker.status, SwapStatus::Succeeded);

let private_asset_id = issue_asset_nia(node1_addr).await.asset_id;
open_channel_funded_raw(
node1_addr,
&node2_pubkey,
Some(NODE2_PEER_PORT),
Some(100000),
Some(50000000),
Some(100),
Some(&private_asset_id),
None,
None,
None,
None,
true,
false,
)
.await
.expect("private channel opening should succeed");

println!("\nsetup private channel swap");
let maker_addr = node1_addr;
let taker_addr = node2_addr;
let qty_from = 25000;
let qty_to = 10;
let maker_init_response = maker_init(
maker_addr,
qty_from,
None,
qty_to,
Some(&private_asset_id),
3600,
)
.await;
taker(taker_addr, maker_init_response.swapstring.clone()).await;

println!("\nexecute private channel swap");
maker_execute(
maker_addr,
maker_init_response.swapstring,
maker_init_response.payment_secret,
node2_pubkey,
)
.await;

let swaps_maker = list_swaps(maker_addr).await;
assert_eq!(swaps_maker.maker.len(), 2);
let swap_maker = swaps_maker
.maker
.iter()
.find(|s| s.payment_hash == maker_init_response.payment_hash)
.unwrap();
assert_eq!(swap_maker.status, SwapStatus::Pending);
wait_for_swap_status(
taker_addr,
&maker_init_response.payment_hash,
SwapStatus::Pending,
)
.await;

wait_for_ln_balance(maker_addr, &private_asset_id, 90).await;
wait_for_ln_balance(taker_addr, &private_asset_id, 10).await;
}
21 changes: 20 additions & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,35 @@ pub(crate) fn get_max_local_rgb_amount<'r>(
max_balance
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn get_route(
channel_manager: &crate::ldk::ChannelManager,
router: &crate::ldk::Router,
ldk_data_dir_path: &Path,
start: PublicKey,
dest: PublicKey,
final_value_msat: Option<u64>,
rgb_payment: Option<(ContractId, u64)>,
hints: Vec<RouteHint>,
) -> Option<Route> {
let inflight_htlcs = channel_manager.compute_inflight_htlcs();
let usable_channels;
let first_hops = if start == channel_manager.get_our_node_id() {
usable_channels = channel_manager.list_usable_channels();
let first_hops = usable_channels
.iter()
.filter(|channel| match rgb_payment {
Some((contract_id, _)) => {
get_rgb_channel_info_optional(&channel.channel_id, ldk_data_dir_path, false)
.is_some_and(|(rgb_info, _)| rgb_info.contract_id == contract_id)
}
None => true,
})
.collect::<Vec<_>>();
(!first_hops.is_empty()).then_some(first_hops)
} else {
None
};
let payment_params = PaymentParameters {
payee: Payee::Clear {
node_id: dest,
Expand All @@ -438,7 +457,7 @@ pub(crate) fn get_route(
max_total_routing_fee_msat: None,
rgb_payment,
},
None,
first_hops.as_deref(),
inflight_htlcs,
);

Expand Down
Loading