Skip to content

Commit dcaa1e3

Browse files
committed
Introduce Blinded Payment Dummy Path test
1 parent cbf3a20 commit dcaa1e3

File tree

2 files changed

+86
-48
lines changed

2 files changed

+86
-48
lines changed

lightning/src/ln/blinded_payment_tests.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,56 @@ fn do_one_hop_blinded_path(success: bool) {
190190
}
191191
}
192192

193+
#[test]
194+
fn one_hop_blinded_path_with_dummy_hops() {
195+
let chanmon_cfgs = create_chanmon_cfgs(2);
196+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
197+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
198+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
199+
let chan_upd = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0).0.contents;
200+
201+
let amt_msat = 5000;
202+
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash(&nodes[1], Some(amt_msat), None);
203+
let payee_tlvs = ReceiveTlvs {
204+
payment_secret,
205+
payment_constraints: PaymentConstraints {
206+
max_cltv_expiry: u32::max_value(),
207+
htlc_minimum_msat: chan_upd.htlc_minimum_msat,
208+
},
209+
payment_context: PaymentContext::Bolt12Refund(Bolt12RefundContext {}),
210+
};
211+
let receive_auth_key = chanmon_cfgs[1].keys_manager.get_receive_auth_key();
212+
let dummy_hops = 2;
213+
214+
let mut secp_ctx = Secp256k1::new();
215+
let blinded_path = BlindedPaymentPath::new_with_dummy_hops(
216+
&[], nodes[1].node.get_our_node_id(), dummy_hops, receive_auth_key,
217+
payee_tlvs, u64::MAX, TEST_FINAL_CLTV as u16,
218+
&chanmon_cfgs[1].keys_manager, &secp_ctx
219+
).unwrap();
220+
221+
let route_params = RouteParameters::from_payment_params_and_value(
222+
PaymentParameters::blinded(vec![blinded_path]),
223+
amt_msat,
224+
);
225+
nodes[0].node.send_payment(payment_hash, RecipientOnionFields::spontaneous_empty(),
226+
PaymentId(payment_hash.0), route_params, Retry::Attempts(0)).unwrap();
227+
check_added_monitors(&nodes[0], 1);
228+
229+
let mut events = nodes[0].node.get_and_clear_pending_msg_events();
230+
assert_eq!(events.len(), 1);
231+
let ev = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut events);
232+
233+
let path = &[&nodes[1]];
234+
let args =
235+
PassAlongPathArgs::new(&nodes[0], path, amt_msat, payment_hash, ev)
236+
.with_dummy_override(dummy_hops)
237+
.with_payment_secret(payment_secret);
238+
239+
do_pass_along_path(args);
240+
claim_payment(&nodes[0], &[&nodes[1]], payment_preimage);
241+
}
242+
193243
#[test]
194244
fn mpp_to_one_hop_blinded_path() {
195245
let chanmon_cfgs = create_chanmon_cfgs(4);

lightning/src/ln/offers_tests.rs

Lines changed: 36 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,20 @@ fn route_bolt12_payment<'a, 'b, 'c>(
185185
fn claim_bolt12_payment<'a, 'b, 'c>(
186186
node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], expected_payment_context: PaymentContext, invoice: &Bolt12Invoice
187187
) {
188-
let recipient = &path[path.len() - 1];
188+
claim_bolt12_payment_with_fees(
189+
node,
190+
path,
191+
expected_payment_context,
192+
invoice,
193+
None,
194+
)
195+
}
196+
197+
fn claim_bolt12_payment_with_fees<'a, 'b, 'c>(
198+
node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], expected_payment_context: PaymentContext, invoice: &Bolt12Invoice,
199+
expected_extra_fees_msat: Option<u64>,
200+
) {
201+
let recipient = path.last().expect("Empty path?");
189202
let payment_purpose = match get_event!(recipient, Event::PaymentClaimable) {
190203
Event::PaymentClaimable { purpose, .. } => purpose,
191204
_ => panic!("No Event::PaymentClaimable"),
@@ -194,20 +207,29 @@ fn claim_bolt12_payment<'a, 'b, 'c>(
194207
Some(preimage) => preimage,
195208
None => panic!("No preimage in Event::PaymentClaimable"),
196209
};
197-
match payment_purpose {
198-
PaymentPurpose::Bolt12OfferPayment { payment_context, .. } => {
199-
assert_eq!(PaymentContext::Bolt12Offer(payment_context), expected_payment_context);
200-
},
201-
PaymentPurpose::Bolt12RefundPayment { payment_context, .. } => {
202-
assert_eq!(PaymentContext::Bolt12Refund(payment_context), expected_payment_context);
203-
},
210+
let context = match payment_purpose {
211+
PaymentPurpose::Bolt12OfferPayment { payment_context, .. } =>
212+
PaymentContext::Bolt12Offer(payment_context),
213+
PaymentPurpose::Bolt12RefundPayment { payment_context, .. } =>
214+
PaymentContext::Bolt12Refund(payment_context),
204215
_ => panic!("Unexpected payment purpose: {:?}", payment_purpose),
205-
}
206-
if let Some(inv) = claim_payment(node, path, payment_preimage) {
207-
assert_eq!(inv, PaidBolt12Invoice::Bolt12Invoice(invoice.to_owned()));
208-
} else {
209-
panic!("Expected PaidInvoice::Bolt12Invoice");
210216
};
217+
218+
assert_eq!(context, expected_payment_context);
219+
220+
let expected_paths = [path];
221+
let mut args = ClaimAlongRouteArgs::new(
222+
node,
223+
&expected_paths,
224+
payment_preimage,
225+
);
226+
227+
if let Some(extra) = expected_extra_fees_msat {
228+
args = args.with_expected_extra_total_fees_msat(extra);
229+
}
230+
231+
let (inv, _) = claim_payment_along_route(args);
232+
assert_eq!(inv, Some(PaidBolt12Invoice::Bolt12Invoice(invoice.clone())));
211233
}
212234

213235
fn extract_offer_nonce<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Nonce {
@@ -1410,41 +1432,7 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
14101432
route_bolt12_payment(bob, &[alice], &invoice);
14111433
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
14121434

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-
1435+
claim_bolt12_payment_with_fees(bob, &[alice], payment_context, &invoice, Some(1000));
14481436
expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
14491437
}
14501438

0 commit comments

Comments
 (0)