Skip to content

Commit 35d1c52

Browse files
committed
Solve second issue.
1 parent 8c13fb6 commit 35d1c52

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3636,6 +3636,29 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
36363636
pub origin_node: &'a Node<'b, 'c, 'd>,
36373637
pub expected_paths: &'a [&'a [&'a Node<'b, 'c, 'd>]],
36383638
pub expected_extra_fees: Vec<u32>,
3639+
/// A one-off adjustment used only in tests to account for an existing
3640+
/// fee-handling trade-off in LDK.
3641+
///
3642+
/// When the payer is the introduction node of a blinded path, LDK does not
3643+
/// subtract the forward fee for the `payer -> next_hop` channel
3644+
/// (see [`BlindedPaymentPath::advance_path_by_one`]). This keeps the fee
3645+
/// logic simpler at the cost of a small, intentional overpayment.
3646+
///
3647+
/// In the simple two-hop case (payer as introduction node → payee),
3648+
/// this overpayment has historically been avoided by simply not charging
3649+
/// the payer the forward fee, since the payer knows there is only
3650+
/// a single hop after them.
3651+
///
3652+
/// However, with the introduction of dummy hops in LDK v3.0, even a
3653+
/// two-node real path (payer as introduction node → payee) may appear as a
3654+
/// multi-hop blinded path. This makes the existing overpayment surface in
3655+
/// tests.
3656+
///
3657+
/// Until the fee-handling trade-off is revisited, this field allows tests
3658+
/// to compensate for that expected difference.
3659+
///
3660+
/// [`BlindedPaymentPath::advance_path_by_one`]: crate::blinded_path::payment::BlindedPaymentPath::advance_path_by_one
3661+
pub expected_extra_total_fees_msat: u64,
36393662
pub expected_min_htlc_overpay: Vec<u32>,
36403663
pub skip_last: bool,
36413664
pub payment_preimage: PaymentPreimage,
@@ -3659,6 +3682,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
36593682
origin_node,
36603683
expected_paths,
36613684
expected_extra_fees: vec![0; expected_paths.len()],
3685+
expected_extra_total_fees_msat: 0,
36623686
expected_min_htlc_overpay: vec![0; expected_paths.len()],
36633687
skip_last: false,
36643688
payment_preimage,
@@ -3674,6 +3698,10 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
36743698
self.expected_extra_fees = extra_fees;
36753699
self
36763700
}
3701+
pub fn with_expected_extra_total_fees_msat(mut self, extra_total_fees: u64) -> Self {
3702+
self.expected_extra_total_fees_msat = extra_total_fees;
3703+
self
3704+
}
36773705
pub fn with_expected_min_htlc_overpay(mut self, extra_fees: Vec<u32>) -> Self {
36783706
self.expected_min_htlc_overpay = extra_fees;
36793707
self
@@ -3698,6 +3726,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
36983726
payment_preimage: our_payment_preimage,
36993727
allow_1_msat_fee_overpay,
37003728
custom_tlvs,
3729+
..
37013730
} = args;
37023731
let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
37033732
assert_eq!(claim_event.len(), 1);
@@ -3934,7 +3963,9 @@ pub fn claim_payment_along_route(
39343963
let origin_node = args.origin_node;
39353964
let payment_preimage = args.payment_preimage;
39363965
let skip_last = args.skip_last;
3937-
let expected_total_fee_msat = do_claim_payment_along_route(args);
3966+
let expected_extra_total_fees_msat = args.expected_extra_total_fees_msat;
3967+
let mut expected_total_fee_msat = do_claim_payment_along_route(args);
3968+
expected_total_fee_msat += expected_extra_total_fees_msat;
39383969
if !skip_last {
39393970
expect_payment_sent!(origin_node, payment_preimage, Some(expected_total_fee_msat))
39403971
} else {

lightning/src/ln/offers_tests.rs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,41 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
14101410
route_bolt12_payment(bob, &[alice], &invoice);
14111411
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
14121412

1413-
claim_bolt12_payment(bob, &[alice], payment_context, &invoice);
1413+
// Extract PaymentClaimable, verify context, and obtain the payment preimage.
1414+
let recipient = &alice;
1415+
let payment_purpose = match get_event!(recipient, Event::PaymentClaimable) {
1416+
Event::PaymentClaimable { purpose, .. } => purpose,
1417+
_ => panic!("No Event::PaymentClaimable"),
1418+
};
1419+
1420+
let payment_preimage = payment_purpose
1421+
.preimage()
1422+
.expect("No preimage in Event::PaymentClaimable");
1423+
1424+
match payment_purpose {
1425+
PaymentPurpose::Bolt12OfferPayment { payment_context: ctx, .. } => {
1426+
assert_eq!(PaymentContext::Bolt12Offer(ctx), payment_context);
1427+
},
1428+
PaymentPurpose::Bolt12RefundPayment { payment_context: ctx, .. } => {
1429+
assert_eq!(PaymentContext::Bolt12Refund(ctx), payment_context);
1430+
},
1431+
_ => panic!("Unexpected payment purpose: {:?}", payment_purpose),
1432+
};
1433+
1434+
// Build ClaimAlongRouteArgs and compensate for the expected overpayment
1435+
// caused by the payer being the introduction node of the blinded path with
1436+
// dummy hops.
1437+
let expected_paths: &[&[&Node]] = &[&[alice]];
1438+
let args = ClaimAlongRouteArgs::new(
1439+
bob,
1440+
expected_paths,
1441+
payment_preimage,
1442+
).with_expected_extra_total_fees_msat(1000);
1443+
1444+
// Execute the claim and verify the invoice was fulfilled.
1445+
let (inv, _events) = claim_payment_along_route(args);
1446+
assert_eq!(inv, Some(PaidBolt12Invoice::Bolt12Invoice(invoice.clone())));
1447+
14141448
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
14151449
}
14161450

0 commit comments

Comments
 (0)