Skip to content

Commit 923ece5

Browse files
committed
Solve second issue.
1 parent 948d1d2 commit 923ece5

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
@@ -3796,6 +3796,29 @@ pub struct ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
37963796
pub origin_node: &'a Node<'b, 'c, 'd>,
37973797
pub expected_paths: &'a [&'a [&'a Node<'b, 'c, 'd>]],
37983798
pub expected_extra_fees: Vec<u32>,
3799+
/// A one-off adjustment used only in tests to account for an existing
3800+
/// fee-handling trade-off in LDK.
3801+
///
3802+
/// When the payer is the introduction node of a blinded path, LDK does not
3803+
/// subtract the forward fee for the `payer -> next_hop` channel
3804+
/// (see [`BlindedPaymentPath::advance_path_by_one`]). This keeps the fee
3805+
/// logic simpler at the cost of a small, intentional overpayment.
3806+
///
3807+
/// In the simple two-hop case (payer as introduction node → payee),
3808+
/// this overpayment has historically been avoided by simply not charging
3809+
/// the payer the forward fee, since the payer knows there is only
3810+
/// a single hop after them.
3811+
///
3812+
/// However, with the introduction of dummy hops in LDK v3.0, even a
3813+
/// two-node real path (payer as introduction node → payee) may appear as a
3814+
/// multi-hop blinded path. This makes the existing overpayment surface in
3815+
/// tests.
3816+
///
3817+
/// Until the fee-handling trade-off is revisited, this field allows tests
3818+
/// to compensate for that expected difference.
3819+
///
3820+
/// [`BlindedPaymentPath::advance_path_by_one`]: crate::blinded_path::payment::BlindedPaymentPath::advance_path_by_one
3821+
pub expected_extra_total_fees_msat: u64,
37993822
pub expected_min_htlc_overpay: Vec<u32>,
38003823
pub skip_last: bool,
38013824
pub payment_preimage: PaymentPreimage,
@@ -3819,6 +3842,7 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
38193842
origin_node,
38203843
expected_paths,
38213844
expected_extra_fees: vec![0; expected_paths.len()],
3845+
expected_extra_total_fees_msat: 0,
38223846
expected_min_htlc_overpay: vec![0; expected_paths.len()],
38233847
skip_last: false,
38243848
payment_preimage,
@@ -3834,6 +3858,10 @@ impl<'a, 'b, 'c, 'd> ClaimAlongRouteArgs<'a, 'b, 'c, 'd> {
38343858
self.expected_extra_fees = extra_fees;
38353859
self
38363860
}
3861+
pub fn with_expected_extra_total_fees_msat(mut self, extra_total_fees: u64) -> Self {
3862+
self.expected_extra_total_fees_msat = extra_total_fees;
3863+
self
3864+
}
38373865
pub fn with_expected_min_htlc_overpay(mut self, extra_fees: Vec<u32>) -> Self {
38383866
self.expected_min_htlc_overpay = extra_fees;
38393867
self
@@ -3858,6 +3886,7 @@ pub fn pass_claimed_payment_along_route(args: ClaimAlongRouteArgs) -> u64 {
38583886
payment_preimage: our_payment_preimage,
38593887
allow_1_msat_fee_overpay,
38603888
custom_tlvs,
3889+
..
38613890
} = args;
38623891
let claim_event = expected_paths[0].last().unwrap().node.get_and_clear_pending_events();
38633892
assert_eq!(claim_event.len(), 1);
@@ -4096,7 +4125,9 @@ pub fn claim_payment_along_route(
40964125
let origin_node = args.origin_node;
40974126
let payment_preimage = args.payment_preimage;
40984127
let skip_last = args.skip_last;
4099-
let expected_total_fee_msat = do_claim_payment_along_route(args);
4128+
let expected_extra_total_fees_msat = args.expected_extra_total_fees_msat;
4129+
let mut expected_total_fee_msat = do_claim_payment_along_route(args);
4130+
expected_total_fee_msat += expected_extra_total_fees_msat;
41004131
if !skip_last {
41014132
expect_payment_sent!(origin_node, payment_preimage, Some(expected_total_fee_msat))
41024133
} 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)