Skip to content

Commit 890607e

Browse files
committed
Update Offers Test to Verify BOLT12 Invoice Reply Paths
1. Updated the Offers Test to check the reply paths in BOLT12 Invoices. 2. Changed the `extract_invoice` return type from `Option<BlindedMessagePath>` to `BlindedMessagePath` since all BOLT12Invoices now have a corresponding reply path by default.
1 parent 681bd5a commit 890607e

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

lightning/src/ln/channelmanager.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10853,7 +10853,7 @@ where
1085310853

1085410854
match response {
1085510855
Ok(invoice) => {
10856-
let context = MessageContext::Offers(OffersContext::Unknown {});
10856+
let context = MessageContext::Offers(OffersContext::InboundPayment { payment_hash });
1085710857
responder.respond_with_reply_path(OffersMessage::Invoice(invoice), context)
1085810858
},
1085910859
Err(error) => responder.respond(OffersMessage::InvoiceError(error.into())),

lightning/src/ln/offers_tests.rs

+26-14
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ fn extract_invoice_request<'a, 'b, 'c>(
219219
}
220220
}
221221

222-
fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> (Bolt12Invoice, Option<BlindedMessagePath>) {
222+
fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> (Bolt12Invoice, BlindedMessagePath) {
223223
match node.onion_messenger.peel_onion_message(message) {
224224
Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
225225
ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
226226
OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
227-
OffersMessage::Invoice(invoice) => (invoice, reply_path),
227+
OffersMessage::Invoice(invoice) => (invoice, reply_path.unwrap()),
228228
#[cfg(async_payments)]
229229
OffersMessage::StaticInvoice(invoice) => panic!("Unexpected static invoice: {:?}", invoice),
230230
OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
@@ -508,15 +508,15 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
508508
features.set_onion_messages_optional();
509509
features.set_route_blinding_optional();
510510

511-
let chanmon_cfgs = create_chanmon_cfgs(6);
512-
let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
511+
let chanmon_cfgs = create_chanmon_cfgs(7);
512+
let node_cfgs = create_node_cfgs(7, &chanmon_cfgs);
513513

514514
*node_cfgs[1].override_init_features.borrow_mut() = Some(features);
515515

516516
let node_chanmgrs = create_node_chanmgrs(
517-
6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
517+
7, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None, None]
518518
);
519-
let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
519+
let nodes = create_network(7, &node_cfgs, &node_chanmgrs);
520520

521521
create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
522522
create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
@@ -526,6 +526,12 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
526526
create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
527527
create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
528528

529+
// Create an announced channel between Bob and node[6] to ensure that in the event of a tie
530+
// between Bob and Charlie for becoming the introduction node candidate, Bob is deterministically
531+
// preferred over Charlie.
532+
create_announced_chan_between_nodes_with_value(&nodes, 1, 6, 10_000_000, 1_000_000_000);
533+
534+
529535
let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
530536
let alice_id = alice.node.get_our_node_id();
531537
let bob_id = bob.node.get_our_node_id();
@@ -580,13 +586,14 @@ fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
580586
let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
581587
david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
582588

583-
let (invoice, _) = extract_invoice(david, &onion_message);
589+
let (invoice, reply_path) = extract_invoice(david, &onion_message);
584590
assert_eq!(invoice.amount_msats(), 10_000_000);
585591
assert_ne!(invoice.signing_pubkey(), alice_id);
586592
assert!(!invoice.payment_paths().is_empty());
587593
for path in invoice.payment_paths() {
588594
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
589595
}
596+
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id));
590597

591598
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
592599
expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
@@ -659,7 +666,7 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
659666
let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
660667
david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
661668

662-
let (invoice, _) = extract_invoice(david, &onion_message);
669+
let (invoice, reply_path) = extract_invoice(david, &onion_message);
663670
assert_eq!(invoice, expected_invoice);
664671

665672
assert_eq!(invoice.amount_msats(), 10_000_000);
@@ -668,6 +675,8 @@ fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
668675
for path in invoice.payment_paths() {
669676
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
670677
}
678+
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id));
679+
671680

672681
route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
673682
expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
@@ -726,13 +735,14 @@ fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
726735
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
727736
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
728737

729-
let (invoice, _) = extract_invoice(bob, &onion_message);
738+
let (invoice, reply_path) = extract_invoice(bob, &onion_message);
730739
assert_eq!(invoice.amount_msats(), 10_000_000);
731740
assert_ne!(invoice.signing_pubkey(), alice_id);
732741
assert!(!invoice.payment_paths().is_empty());
733742
for path in invoice.payment_paths() {
734743
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
735744
}
745+
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(alice_id));
736746

737747
route_bolt12_payment(bob, &[alice], &invoice);
738748
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
@@ -779,7 +789,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
779789
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
780790
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
781791

782-
let (invoice, _) = extract_invoice(bob, &onion_message);
792+
let (invoice, reply_path) = extract_invoice(bob, &onion_message);
783793
assert_eq!(invoice, expected_invoice);
784794

785795
assert_eq!(invoice.amount_msats(), 10_000_000);
@@ -788,6 +798,7 @@ fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
788798
for path in invoice.payment_paths() {
789799
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(alice_id));
790800
}
801+
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(alice_id));
791802

792803
route_bolt12_payment(bob, &[alice], &invoice);
793804
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
@@ -1044,7 +1055,7 @@ fn send_invoice_for_refund_with_distinct_reply_path() {
10441055
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
10451056

10461057
let (_, reply_path) = extract_invoice(alice, &onion_message);
1047-
assert_eq!(reply_path.unwrap().introduction_node(), &IntroductionNode::NodeId(charlie_id));
1058+
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(charlie_id));
10481059

10491060
// Send, extract and verify the second Invoice Request message
10501061
let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
@@ -1053,7 +1064,7 @@ fn send_invoice_for_refund_with_distinct_reply_path() {
10531064
let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
10541065

10551066
let (_, reply_path) = extract_invoice(alice, &onion_message);
1056-
assert_eq!(reply_path.unwrap().introduction_node(), &IntroductionNode::NodeId(nodes[6].node.get_our_node_id()));
1067+
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(nodes[6].node.get_our_node_id()));
10571068
}
10581069

10591070
/// Checks that a deferred invoice can be paid asynchronously from an Event::InvoiceReceived.
@@ -1190,12 +1201,13 @@ fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
11901201
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
11911202
bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
11921203

1193-
let (invoice, _) = extract_invoice(bob, &onion_message);
1204+
let (invoice, reply_path) = extract_invoice(bob, &onion_message);
11941205
assert_ne!(invoice.signing_pubkey(), alice_id);
11951206
assert!(!invoice.payment_paths().is_empty());
11961207
for path in invoice.payment_paths() {
11971208
assert_eq!(path.introduction_node(), &IntroductionNode::NodeId(bob_id));
11981209
}
1210+
assert_eq!(reply_path.introduction_node(), &IntroductionNode::NodeId(bob_id));
11991211

12001212
route_bolt12_payment(bob, &[alice], &invoice);
12011213
expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
@@ -1239,7 +1251,7 @@ fn creates_refund_with_blinded_path_using_unannounced_introduction_node() {
12391251

12401252
let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
12411253

1242-
let (invoice, _) = extract_invoice(bob, &onion_message);
1254+
let (invoice, _reply_path) = extract_invoice(bob, &onion_message);
12431255
assert_eq!(invoice, expected_invoice);
12441256
assert_ne!(invoice.signing_pubkey(), alice_id);
12451257
assert!(!invoice.payment_paths().is_empty());

0 commit comments

Comments
 (0)