1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! Functional tests for the BOLT 12 Offers payment flow.
12 //! [`ChannelManager`] provides utilities to create [`Offer`]s and [`Refund`]s along with utilities
13 //! to initiate and request payment for them, respectively. It also manages the payment flow via
14 //! implementing [`OffersMessageHandler`]. This module tests that functionality, including the
15 //! resulting [`Event`] generation.
17 //! Two-node success tests use an announced channel:
21 //! While two-node failure tests use an unannounced channel:
25 //! Six-node tests use unannounced channels for the sender and recipient and announced channels for
26 //! the rest of the network.
32 //! Alice ... Bob -------- Charlie ... David
38 //! Unnamed nodes are needed to ensure unannounced nodes can create two-hop blinded paths.
40 //! Nodes without channels are disconnected and connected as needed to ensure that deterministic
41 //! blinded paths are used.
43 use bitcoin::network::constants::Network;
44 use core::time::Duration;
45 use crate::blinded_path::{BlindedPath, IntroductionNode};
46 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
47 use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
48 use crate::ln::functional_test_utils::*;
49 use crate::ln::msgs::{ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
50 use crate::offers::invoice::Bolt12Invoice;
51 use crate::offers::invoice_error::InvoiceError;
52 use crate::offers::invoice_request::InvoiceRequest;
53 use crate::offers::parse::Bolt12SemanticError;
54 use crate::onion_message::messenger::PeeledOnion;
55 use crate::onion_message::offers::OffersMessage;
56 use crate::onion_message::packet::ParsedOnionMessageContents;
57 use crate::routing::gossip::{NodeAlias, NodeId};
58 use crate::sign::{NodeSigner, Recipient};
60 use crate::prelude::*;
62 macro_rules! expect_recent_payment {
63 ($node: expr, $payment_state: path, $payment_id: expr) => {
64 match $node.node.list_recent_payments().first() {
65 Some(&$payment_state { payment_id: actual_payment_id, .. }) => {
66 assert_eq!($payment_id, actual_payment_id);
68 Some(_) => panic!("Unexpected recent payment state"),
69 None => panic!("No recent payments"),
74 fn connect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) {
75 let node_id_a = node_a.node.get_our_node_id();
76 let node_id_b = node_b.node.get_our_node_id();
79 features: node_a.init_features(&node_id_b),
81 remote_network_address: None,
84 features: node_b.init_features(&node_id_a),
86 remote_network_address: None,
89 node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap();
90 node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap();
91 node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap();
92 node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap();
95 fn disconnect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>]) {
97 node_a.node.peer_disconnected(&node_b.node.get_our_node_id());
98 node_b.node.peer_disconnected(&node_a.node.get_our_node_id());
99 node_a.onion_messenger.peer_disconnected(&node_b.node.get_our_node_id());
100 node_b.onion_messenger.peer_disconnected(&node_a.node.get_our_node_id());
104 fn announce_node_address<'a, 'b, 'c>(
105 node: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>], address: SocketAddress,
107 let features = node.onion_messenger.provided_node_features()
108 | node.gossip_sync.provided_node_features();
110 let announcement = UnsignedNodeAnnouncement {
113 node_id: NodeId::from_pubkey(&node.keys_manager.get_node_id(Recipient::Node).unwrap()),
115 alias: NodeAlias([0u8; 32]),
116 addresses: vec![address],
117 excess_address_data: Vec::new(),
118 excess_data: Vec::new(),
120 let signature = node.keys_manager.sign_gossip_message(
121 UnsignedGossipMessage::NodeAnnouncement(&announcement)
124 let msg = NodeAnnouncement {
126 contents: announcement
129 node.gossip_sync.handle_node_announcement(&msg).unwrap();
131 peer.gossip_sync.handle_node_announcement(&msg).unwrap();
135 fn route_bolt12_payment<'a, 'b, 'c>(
136 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice
138 // Monitor added when handling the invoice onion message.
139 check_added_monitors(node, 1);
141 let mut events = node.node.get_and_clear_pending_msg_events();
142 assert_eq!(events.len(), 1);
143 let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
145 // Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
146 // invoice contains the payment_hash but it was encrypted inside an onion message.
147 let amount_msats = invoice.amount_msats();
148 let payment_hash = invoice.payment_hash();
149 let args = PassAlongPathArgs::new(node, path, amount_msats, payment_hash, ev)
150 .without_clearing_recipient_events();
151 do_pass_along_path(args);
154 fn claim_bolt12_payment<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>]) {
155 let recipient = &path[path.len() - 1];
156 match get_event!(recipient, Event::PaymentClaimable) {
157 Event::PaymentClaimable {
158 purpose: PaymentPurpose::InvoicePayment {
159 payment_preimage: Some(payment_preimage), ..
161 } => claim_payment(node, path, payment_preimage),
166 fn extract_invoice_request<'a, 'b, 'c>(
167 node: &Node<'a, 'b, 'c>, message: &OnionMessage
168 ) -> (InvoiceRequest, Option<BlindedPath>) {
169 match node.onion_messenger.peel_onion_message(message) {
170 Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
171 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
172 OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path),
173 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
174 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
176 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
178 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
179 Err(e) => panic!("Failed to process onion message {:?}", e),
183 fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
184 match node.onion_messenger.peel_onion_message(message) {
185 Ok(PeeledOnion::Receive(message, _, _)) => match message {
186 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
187 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
188 OffersMessage::Invoice(invoice) => invoice,
189 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
191 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
193 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
194 Err(e) => panic!("Failed to process onion message {:?}", e),
198 fn extract_invoice_error<'a, 'b, 'c>(
199 node: &Node<'a, 'b, 'c>, message: &OnionMessage
201 match node.onion_messenger.peel_onion_message(message) {
202 Ok(PeeledOnion::Receive(message, _, _)) => match message {
203 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
204 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
205 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
206 OffersMessage::InvoiceError(error) => error,
208 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
210 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
211 Err(e) => panic!("Failed to process onion message {:?}", e),
215 /// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
217 fn prefers_non_tor_nodes_in_blinded_paths() {
218 let mut accept_forward_cfg = test_default_channel_config();
219 accept_forward_cfg.accept_forwards_to_priv_channels = true;
221 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
222 features.set_onion_messages_optional();
223 features.set_route_blinding_optional();
225 let chanmon_cfgs = create_chanmon_cfgs(6);
226 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
228 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
230 let node_chanmgrs = create_node_chanmgrs(
231 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
233 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
235 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
236 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
237 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
238 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
239 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
240 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
241 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
243 // Add an extra channel so that more than one of Bob's peers have MIN_PEER_CHANNELS.
244 create_announced_chan_between_nodes_with_value(&nodes, 4, 5, 10_000_000, 1_000_000_000);
246 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
247 let bob_id = bob.node.get_our_node_id();
248 let charlie_id = charlie.node.get_our_node_id();
250 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
251 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
253 let tor = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
254 announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());
257 .create_offer_builder("coffee".to_string()).unwrap()
258 .amount_msats(10_000_000)
260 assert_ne!(offer.signing_pubkey(), bob_id);
261 assert!(!offer.paths().is_empty());
262 for path in offer.paths() {
263 assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
264 assert_ne!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
267 // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
268 announce_node_address(&nodes[4], &[alice, bob, charlie, david, &nodes[5]], tor.clone());
269 announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
272 .create_offer_builder("coffee".to_string()).unwrap()
273 .amount_msats(10_000_000)
275 assert_ne!(offer.signing_pubkey(), bob_id);
276 assert!(!offer.paths().is_empty());
277 for path in offer.paths() {
278 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
282 /// Checks that blinded paths prefer an introduction node that is the most connected.
284 fn prefers_more_connected_nodes_in_blinded_paths() {
285 let mut accept_forward_cfg = test_default_channel_config();
286 accept_forward_cfg.accept_forwards_to_priv_channels = true;
288 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
289 features.set_onion_messages_optional();
290 features.set_route_blinding_optional();
292 let chanmon_cfgs = create_chanmon_cfgs(6);
293 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
295 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
297 let node_chanmgrs = create_node_chanmgrs(
298 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
300 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
302 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
303 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
304 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
305 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
306 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
307 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
308 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
310 // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
311 // more than the others.
312 create_announced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000_000, 1_000_000_000);
313 create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 10_000_000, 1_000_000_000);
315 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
316 let bob_id = bob.node.get_our_node_id();
318 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
319 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
322 .create_offer_builder("coffee".to_string()).unwrap()
323 .amount_msats(10_000_000)
325 assert_ne!(offer.signing_pubkey(), bob_id);
326 assert!(!offer.paths().is_empty());
327 for path in offer.paths() {
328 assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
332 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
333 /// rather than exposing a node's pubkey.
335 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
336 let mut accept_forward_cfg = test_default_channel_config();
337 accept_forward_cfg.accept_forwards_to_priv_channels = true;
339 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
340 features.set_onion_messages_optional();
341 features.set_route_blinding_optional();
343 let chanmon_cfgs = create_chanmon_cfgs(6);
344 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
346 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
348 let node_chanmgrs = create_node_chanmgrs(
349 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
351 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
353 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
354 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
355 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
356 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
357 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
358 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
359 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
361 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
362 let alice_id = alice.node.get_our_node_id();
363 let bob_id = bob.node.get_our_node_id();
364 let charlie_id = charlie.node.get_our_node_id();
365 let david_id = david.node.get_our_node_id();
367 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
368 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
370 let offer = alice.node
371 .create_offer_builder("coffee".to_string()).unwrap()
372 .amount_msats(10_000_000)
374 assert_ne!(offer.signing_pubkey(), alice_id);
375 assert!(!offer.paths().is_empty());
376 for path in offer.paths() {
377 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
380 let payment_id = PaymentId([1; 32]);
381 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
383 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
385 connect_peers(david, bob);
387 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
388 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
390 connect_peers(alice, charlie);
392 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
393 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
395 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
396 assert_eq!(invoice_request.amount_msats(), None);
397 assert_ne!(invoice_request.payer_id(), david_id);
398 assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(charlie_id));
400 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
401 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
403 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
404 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
406 let invoice = extract_invoice(david, &onion_message);
407 assert_eq!(invoice.amount_msats(), 10_000_000);
408 assert_ne!(invoice.signing_pubkey(), alice_id);
409 assert!(!invoice.payment_paths().is_empty());
410 for (_, path) in invoice.payment_paths() {
411 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
414 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
415 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
417 claim_bolt12_payment(david, &[charlie, bob, alice]);
418 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
421 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
422 /// rather than exposing a node's pubkey.
424 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
425 let mut accept_forward_cfg = test_default_channel_config();
426 accept_forward_cfg.accept_forwards_to_priv_channels = true;
428 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
429 features.set_onion_messages_optional();
430 features.set_route_blinding_optional();
432 let chanmon_cfgs = create_chanmon_cfgs(6);
433 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
435 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
437 let node_chanmgrs = create_node_chanmgrs(
438 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
440 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
442 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
443 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
444 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
445 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
446 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
447 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
448 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
450 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
451 let alice_id = alice.node.get_our_node_id();
452 let bob_id = bob.node.get_our_node_id();
453 let charlie_id = charlie.node.get_our_node_id();
454 let david_id = david.node.get_our_node_id();
456 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
457 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
459 let absolute_expiry = Duration::from_secs(u64::MAX);
460 let payment_id = PaymentId([1; 32]);
461 let refund = david.node
462 .create_refund_builder(
463 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
467 assert_eq!(refund.amount_msats(), 10_000_000);
468 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
469 assert_ne!(refund.payer_id(), david_id);
470 assert!(!refund.paths().is_empty());
471 for path in refund.paths() {
472 assert_eq!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
474 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
476 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
478 connect_peers(alice, charlie);
480 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
481 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
483 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
484 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
486 let invoice = extract_invoice(david, &onion_message);
487 assert_eq!(invoice, expected_invoice);
489 assert_eq!(invoice.amount_msats(), 10_000_000);
490 assert_ne!(invoice.signing_pubkey(), alice_id);
491 assert!(!invoice.payment_paths().is_empty());
492 for (_, path) in invoice.payment_paths() {
493 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
496 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
497 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
499 claim_bolt12_payment(david, &[charlie, bob, alice]);
500 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
503 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
504 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
505 /// introduction node of the blinded path.
507 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
508 let chanmon_cfgs = create_chanmon_cfgs(2);
509 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
510 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
511 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
513 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
515 let alice = &nodes[0];
516 let alice_id = alice.node.get_our_node_id();
518 let bob_id = bob.node.get_our_node_id();
520 let offer = alice.node
521 .create_offer_builder("coffee".to_string()).unwrap()
522 .amount_msats(10_000_000)
524 assert_ne!(offer.signing_pubkey(), alice_id);
525 assert!(!offer.paths().is_empty());
526 for path in offer.paths() {
527 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
530 let payment_id = PaymentId([1; 32]);
531 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
532 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
534 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
535 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
537 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
538 assert_eq!(invoice_request.amount_msats(), None);
539 assert_ne!(invoice_request.payer_id(), bob_id);
540 assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(bob_id));
542 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
543 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
545 let invoice = extract_invoice(bob, &onion_message);
546 assert_eq!(invoice.amount_msats(), 10_000_000);
547 assert_ne!(invoice.signing_pubkey(), alice_id);
548 assert!(!invoice.payment_paths().is_empty());
549 for (_, path) in invoice.payment_paths() {
550 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
553 route_bolt12_payment(bob, &[alice], &invoice);
554 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
556 claim_bolt12_payment(bob, &[alice]);
557 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
560 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
561 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
562 /// introduction node of the blinded path.
564 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
565 let chanmon_cfgs = create_chanmon_cfgs(2);
566 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
567 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
568 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
570 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
572 let alice = &nodes[0];
573 let alice_id = alice.node.get_our_node_id();
575 let bob_id = bob.node.get_our_node_id();
577 let absolute_expiry = Duration::from_secs(u64::MAX);
578 let payment_id = PaymentId([1; 32]);
579 let refund = bob.node
580 .create_refund_builder(
581 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
585 assert_eq!(refund.amount_msats(), 10_000_000);
586 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
587 assert_ne!(refund.payer_id(), bob_id);
588 assert!(!refund.paths().is_empty());
589 for path in refund.paths() {
590 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
592 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
594 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
596 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
597 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
599 let invoice = extract_invoice(bob, &onion_message);
600 assert_eq!(invoice, expected_invoice);
602 assert_eq!(invoice.amount_msats(), 10_000_000);
603 assert_ne!(invoice.signing_pubkey(), alice_id);
604 assert!(!invoice.payment_paths().is_empty());
605 for (_, path) in invoice.payment_paths() {
606 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
609 route_bolt12_payment(bob, &[alice], &invoice);
610 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
612 claim_bolt12_payment(bob, &[alice]);
613 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
616 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
617 /// the requested is sent directly using the node's pubkey, the response and the payment still use
618 /// blinded paths as required by the spec.
620 fn pays_for_offer_without_blinded_paths() {
621 let chanmon_cfgs = create_chanmon_cfgs(2);
622 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
623 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
624 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
626 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
628 let alice = &nodes[0];
629 let alice_id = alice.node.get_our_node_id();
631 let bob_id = bob.node.get_our_node_id();
633 let offer = alice.node
634 .create_offer_builder("coffee".to_string()).unwrap()
636 .amount_msats(10_000_000)
638 assert_eq!(offer.signing_pubkey(), alice_id);
639 assert!(offer.paths().is_empty());
641 let payment_id = PaymentId([1; 32]);
642 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
643 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
645 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
646 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
648 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
649 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
651 let invoice = extract_invoice(bob, &onion_message);
652 route_bolt12_payment(bob, &[alice], &invoice);
653 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
655 claim_bolt12_payment(bob, &[alice]);
656 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
659 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
660 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
662 fn pays_for_refund_without_blinded_paths() {
663 let chanmon_cfgs = create_chanmon_cfgs(2);
664 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
665 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
666 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
668 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
670 let alice = &nodes[0];
671 let alice_id = alice.node.get_our_node_id();
673 let bob_id = bob.node.get_our_node_id();
675 let absolute_expiry = Duration::from_secs(u64::MAX);
676 let payment_id = PaymentId([1; 32]);
677 let refund = bob.node
678 .create_refund_builder(
679 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
684 assert_eq!(refund.payer_id(), bob_id);
685 assert!(refund.paths().is_empty());
686 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
688 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
690 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
691 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
693 let invoice = extract_invoice(bob, &onion_message);
694 assert_eq!(invoice, expected_invoice);
696 route_bolt12_payment(bob, &[alice], &invoice);
697 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
699 claim_bolt12_payment(bob, &[alice]);
700 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
703 /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
705 fn fails_creating_offer_without_blinded_paths() {
706 let chanmon_cfgs = create_chanmon_cfgs(2);
707 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
708 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
709 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
711 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
713 match nodes[0].node.create_offer_builder("coffee".to_string()) {
714 Ok(_) => panic!("Expected error"),
715 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
719 /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
721 fn fails_creating_refund_without_blinded_paths() {
722 let chanmon_cfgs = create_chanmon_cfgs(2);
723 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
724 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
725 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
727 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
729 let absolute_expiry = Duration::from_secs(u64::MAX);
730 let payment_id = PaymentId([1; 32]);
732 match nodes[0].node.create_refund_builder(
733 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
735 Ok(_) => panic!("Expected error"),
736 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
739 assert!(nodes[0].node.list_recent_payments().is_empty());
742 /// Fails creating an invoice request when the offer contains an unsupported chain.
744 fn fails_creating_invoice_request_for_unsupported_chain() {
745 let chanmon_cfgs = create_chanmon_cfgs(2);
746 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
747 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
748 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
750 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
752 let alice = &nodes[0];
755 let offer = alice.node
756 .create_offer_builder("coffee".to_string()).unwrap()
758 .chain(Network::Signet)
761 let payment_id = PaymentId([1; 32]);
762 match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
763 Ok(_) => panic!("Expected error"),
764 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
768 /// Fails requesting a payment when the refund contains an unsupported chain.
770 fn fails_sending_invoice_with_unsupported_chain_for_refund() {
771 let chanmon_cfgs = create_chanmon_cfgs(2);
772 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
773 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
774 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
776 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
778 let alice = &nodes[0];
781 let absolute_expiry = Duration::from_secs(u64::MAX);
782 let payment_id = PaymentId([1; 32]);
783 let refund = bob.node
784 .create_refund_builder(
785 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
788 .chain(Network::Signet)
791 match alice.node.request_refund_payment(&refund) {
792 Ok(_) => panic!("Expected error"),
793 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
797 /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
800 fn fails_creating_invoice_request_without_blinded_reply_path() {
801 let chanmon_cfgs = create_chanmon_cfgs(6);
802 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
803 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
804 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
806 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
807 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
808 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
809 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
810 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
812 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
814 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
815 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
817 let offer = alice.node
818 .create_offer_builder("coffee".to_string()).unwrap()
819 .amount_msats(10_000_000)
822 let payment_id = PaymentId([1; 32]);
824 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
825 Ok(_) => panic!("Expected error"),
826 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
829 assert!(nodes[0].node.list_recent_payments().is_empty());
833 fn fails_creating_invoice_request_with_duplicate_payment_id() {
834 let chanmon_cfgs = create_chanmon_cfgs(6);
835 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
836 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
837 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
839 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
840 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
841 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
842 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
843 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
844 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
845 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
847 let (alice, _bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
849 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
851 let offer = alice.node
852 .create_offer_builder("coffee".to_string()).unwrap()
853 .amount_msats(10_000_000)
856 let payment_id = PaymentId([1; 32]);
858 david.node.pay_for_offer(
859 &offer, None, None, None, payment_id, Retry::Attempts(0), None
862 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
864 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
865 Ok(_) => panic!("Expected error"),
866 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
869 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
873 fn fails_creating_refund_with_duplicate_payment_id() {
874 let chanmon_cfgs = create_chanmon_cfgs(2);
875 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
876 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
877 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
879 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
881 let absolute_expiry = Duration::from_secs(u64::MAX);
882 let payment_id = PaymentId([1; 32]);
884 nodes[0].node.create_refund_builder(
885 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
888 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
890 match nodes[0].node.create_refund_builder(
891 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
893 Ok(_) => panic!("Expected error"),
894 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
897 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
901 fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
902 let mut accept_forward_cfg = test_default_channel_config();
903 accept_forward_cfg.accept_forwards_to_priv_channels = true;
905 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
906 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
907 features.set_onion_messages_optional();
908 features.clear_route_blinding();
910 let chanmon_cfgs = create_chanmon_cfgs(6);
911 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
913 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
915 let node_chanmgrs = create_node_chanmgrs(
916 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
918 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
920 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
921 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
922 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
923 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
924 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
925 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
926 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
928 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
929 let alice_id = alice.node.get_our_node_id();
930 let bob_id = bob.node.get_our_node_id();
931 let charlie_id = charlie.node.get_our_node_id();
932 let david_id = david.node.get_our_node_id();
934 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
935 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
937 let offer = alice.node
938 .create_offer_builder("coffee".to_string()).unwrap()
939 .amount_msats(10_000_000)
942 let payment_id = PaymentId([1; 32]);
943 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
946 connect_peers(david, bob);
948 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
949 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
951 connect_peers(alice, charlie);
953 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
954 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
956 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
957 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
959 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
960 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
962 let invoice_error = extract_invoice_error(david, &onion_message);
963 assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
967 fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
968 let mut accept_forward_cfg = test_default_channel_config();
969 accept_forward_cfg.accept_forwards_to_priv_channels = true;
971 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
972 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
973 features.set_onion_messages_optional();
974 features.clear_route_blinding();
976 let chanmon_cfgs = create_chanmon_cfgs(6);
977 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
979 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
981 let node_chanmgrs = create_node_chanmgrs(
982 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
984 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
986 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
987 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
988 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
989 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
990 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
991 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
992 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
994 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
996 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
997 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
999 let absolute_expiry = Duration::from_secs(u64::MAX);
1000 let payment_id = PaymentId([1; 32]);
1001 let refund = david.node
1002 .create_refund_builder(
1003 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1008 match alice.node.request_refund_payment(&refund) {
1009 Ok(_) => panic!("Expected error"),
1010 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1015 fn fails_paying_invoice_more_than_once() {
1016 let mut accept_forward_cfg = test_default_channel_config();
1017 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1019 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1020 features.set_onion_messages_optional();
1021 features.set_route_blinding_optional();
1023 let chanmon_cfgs = create_chanmon_cfgs(6);
1024 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1026 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1028 let node_chanmgrs = create_node_chanmgrs(
1029 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1031 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1033 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1034 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1035 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1036 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1037 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1038 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1039 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1041 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1042 let alice_id = alice.node.get_our_node_id();
1043 let bob_id = bob.node.get_our_node_id();
1044 let charlie_id = charlie.node.get_our_node_id();
1045 let david_id = david.node.get_our_node_id();
1047 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1048 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1050 let absolute_expiry = Duration::from_secs(u64::MAX);
1051 let payment_id = PaymentId([1; 32]);
1052 let refund = david.node
1053 .create_refund_builder(
1054 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1058 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1060 // Alice sends the first invoice
1061 alice.node.request_refund_payment(&refund).unwrap();
1063 connect_peers(alice, charlie);
1065 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1066 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1068 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1069 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1071 // David pays the first invoice
1072 let invoice1 = extract_invoice(david, &onion_message);
1074 route_bolt12_payment(david, &[charlie, bob, alice], &invoice1);
1075 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
1077 claim_bolt12_payment(david, &[charlie, bob, alice]);
1078 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
1080 disconnect_peers(alice, &[charlie]);
1082 // Alice sends the second invoice
1083 alice.node.request_refund_payment(&refund).unwrap();
1085 connect_peers(alice, charlie);
1086 connect_peers(david, bob);
1088 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1089 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1091 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1092 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1094 let invoice2 = extract_invoice(david, &onion_message);
1095 assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata());
1097 // David sends an error instead of paying the second invoice
1098 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1099 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1101 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1102 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1104 let invoice_error = extract_invoice_error(alice, &onion_message);
1105 assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));