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};
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 { purpose, .. } => match purpose.preimage() {
158 Some(payment_preimage) => claim_payment(node, path, payment_preimage),
159 None => panic!("No preimage in Event::PaymentClaimable"),
161 _ => panic!("No Event::PaymentClaimable"),
165 fn extract_invoice_request<'a, 'b, 'c>(
166 node: &Node<'a, 'b, 'c>, message: &OnionMessage
167 ) -> (InvoiceRequest, Option<BlindedPath>) {
168 match node.onion_messenger.peel_onion_message(message) {
169 Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
170 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
171 OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path),
172 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
173 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
175 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
177 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
178 Err(e) => panic!("Failed to process onion message {:?}", e),
182 fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
183 match node.onion_messenger.peel_onion_message(message) {
184 Ok(PeeledOnion::Receive(message, _, _)) => match message {
185 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
186 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
187 OffersMessage::Invoice(invoice) => invoice,
188 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
190 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
192 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
193 Err(e) => panic!("Failed to process onion message {:?}", e),
197 fn extract_invoice_error<'a, 'b, 'c>(
198 node: &Node<'a, 'b, 'c>, message: &OnionMessage
200 match node.onion_messenger.peel_onion_message(message) {
201 Ok(PeeledOnion::Receive(message, _, _)) => match message {
202 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
203 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
204 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
205 OffersMessage::InvoiceError(error) => error,
207 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
209 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
210 Err(e) => panic!("Failed to process onion message {:?}", e),
214 /// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
216 fn prefers_non_tor_nodes_in_blinded_paths() {
217 let mut accept_forward_cfg = test_default_channel_config();
218 accept_forward_cfg.accept_forwards_to_priv_channels = true;
220 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
221 features.set_onion_messages_optional();
222 features.set_route_blinding_optional();
224 let chanmon_cfgs = create_chanmon_cfgs(6);
225 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
227 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
229 let node_chanmgrs = create_node_chanmgrs(
230 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
232 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
234 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
235 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
236 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
237 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
238 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
239 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
240 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
242 // Add an extra channel so that more than one of Bob's peers have MIN_PEER_CHANNELS.
243 create_announced_chan_between_nodes_with_value(&nodes, 4, 5, 10_000_000, 1_000_000_000);
245 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
246 let bob_id = bob.node.get_our_node_id();
247 let charlie_id = charlie.node.get_our_node_id();
249 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
250 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
252 let tor = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
253 announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());
256 .create_offer_builder("coffee".to_string()).unwrap()
257 .amount_msats(10_000_000)
259 assert_ne!(offer.signing_pubkey(), bob_id);
260 assert!(!offer.paths().is_empty());
261 for path in offer.paths() {
262 assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
263 assert_ne!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
266 // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
267 announce_node_address(&nodes[4], &[alice, bob, charlie, david, &nodes[5]], tor.clone());
268 announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
271 .create_offer_builder("coffee".to_string()).unwrap()
272 .amount_msats(10_000_000)
274 assert_ne!(offer.signing_pubkey(), bob_id);
275 assert!(!offer.paths().is_empty());
276 for path in offer.paths() {
277 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
281 /// Checks that blinded paths prefer an introduction node that is the most connected.
283 fn prefers_more_connected_nodes_in_blinded_paths() {
284 let mut accept_forward_cfg = test_default_channel_config();
285 accept_forward_cfg.accept_forwards_to_priv_channels = true;
287 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
288 features.set_onion_messages_optional();
289 features.set_route_blinding_optional();
291 let chanmon_cfgs = create_chanmon_cfgs(6);
292 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
294 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
296 let node_chanmgrs = create_node_chanmgrs(
297 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
299 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
301 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
302 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
303 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
304 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
305 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
306 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
307 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
309 // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
310 // more than the others.
311 create_announced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000_000, 1_000_000_000);
312 create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 10_000_000, 1_000_000_000);
314 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
315 let bob_id = bob.node.get_our_node_id();
317 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
318 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
321 .create_offer_builder("coffee".to_string()).unwrap()
322 .amount_msats(10_000_000)
324 assert_ne!(offer.signing_pubkey(), bob_id);
325 assert!(!offer.paths().is_empty());
326 for path in offer.paths() {
327 assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
331 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
332 /// rather than exposing a node's pubkey.
334 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
335 let mut accept_forward_cfg = test_default_channel_config();
336 accept_forward_cfg.accept_forwards_to_priv_channels = true;
338 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
339 features.set_onion_messages_optional();
340 features.set_route_blinding_optional();
342 let chanmon_cfgs = create_chanmon_cfgs(6);
343 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
345 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
347 let node_chanmgrs = create_node_chanmgrs(
348 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
350 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
352 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
353 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
354 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
355 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
356 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
357 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
358 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
360 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
361 let alice_id = alice.node.get_our_node_id();
362 let bob_id = bob.node.get_our_node_id();
363 let charlie_id = charlie.node.get_our_node_id();
364 let david_id = david.node.get_our_node_id();
366 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
367 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
369 let offer = alice.node
370 .create_offer_builder("coffee".to_string()).unwrap()
371 .amount_msats(10_000_000)
373 assert_ne!(offer.signing_pubkey(), alice_id);
374 assert!(!offer.paths().is_empty());
375 for path in offer.paths() {
376 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
379 let payment_id = PaymentId([1; 32]);
380 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
382 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
384 connect_peers(david, bob);
386 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
387 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
389 connect_peers(alice, charlie);
391 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
392 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
394 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
395 assert_eq!(invoice_request.amount_msats(), None);
396 assert_ne!(invoice_request.payer_id(), david_id);
397 assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(charlie_id));
399 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
400 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
402 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
403 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
405 let invoice = extract_invoice(david, &onion_message);
406 assert_eq!(invoice.amount_msats(), 10_000_000);
407 assert_ne!(invoice.signing_pubkey(), alice_id);
408 assert!(!invoice.payment_paths().is_empty());
409 for (_, path) in invoice.payment_paths() {
410 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
413 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
414 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
416 claim_bolt12_payment(david, &[charlie, bob, alice]);
417 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
420 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
421 /// rather than exposing a node's pubkey.
423 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
424 let mut accept_forward_cfg = test_default_channel_config();
425 accept_forward_cfg.accept_forwards_to_priv_channels = true;
427 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
428 features.set_onion_messages_optional();
429 features.set_route_blinding_optional();
431 let chanmon_cfgs = create_chanmon_cfgs(6);
432 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
434 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
436 let node_chanmgrs = create_node_chanmgrs(
437 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
439 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
441 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
442 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
443 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
444 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
445 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
446 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
447 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
449 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
450 let alice_id = alice.node.get_our_node_id();
451 let bob_id = bob.node.get_our_node_id();
452 let charlie_id = charlie.node.get_our_node_id();
453 let david_id = david.node.get_our_node_id();
455 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
456 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
458 let absolute_expiry = Duration::from_secs(u64::MAX);
459 let payment_id = PaymentId([1; 32]);
460 let refund = david.node
461 .create_refund_builder(
462 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
466 assert_eq!(refund.amount_msats(), 10_000_000);
467 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
468 assert_ne!(refund.payer_id(), david_id);
469 assert!(!refund.paths().is_empty());
470 for path in refund.paths() {
471 assert_eq!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
473 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
475 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
477 connect_peers(alice, charlie);
479 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
480 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
482 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
483 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
485 let invoice = extract_invoice(david, &onion_message);
486 assert_eq!(invoice, expected_invoice);
488 assert_eq!(invoice.amount_msats(), 10_000_000);
489 assert_ne!(invoice.signing_pubkey(), alice_id);
490 assert!(!invoice.payment_paths().is_empty());
491 for (_, path) in invoice.payment_paths() {
492 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
495 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
496 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
498 claim_bolt12_payment(david, &[charlie, bob, alice]);
499 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
502 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
503 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
504 /// introduction node of the blinded path.
506 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
507 let chanmon_cfgs = create_chanmon_cfgs(2);
508 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
509 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
510 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
512 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
514 let alice = &nodes[0];
515 let alice_id = alice.node.get_our_node_id();
517 let bob_id = bob.node.get_our_node_id();
519 let offer = alice.node
520 .create_offer_builder("coffee".to_string()).unwrap()
521 .amount_msats(10_000_000)
523 assert_ne!(offer.signing_pubkey(), alice_id);
524 assert!(!offer.paths().is_empty());
525 for path in offer.paths() {
526 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
529 let payment_id = PaymentId([1; 32]);
530 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
531 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
533 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
534 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
536 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
537 assert_eq!(invoice_request.amount_msats(), None);
538 assert_ne!(invoice_request.payer_id(), bob_id);
539 assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(bob_id));
541 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
542 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
544 let invoice = extract_invoice(bob, &onion_message);
545 assert_eq!(invoice.amount_msats(), 10_000_000);
546 assert_ne!(invoice.signing_pubkey(), alice_id);
547 assert!(!invoice.payment_paths().is_empty());
548 for (_, path) in invoice.payment_paths() {
549 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
552 route_bolt12_payment(bob, &[alice], &invoice);
553 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
555 claim_bolt12_payment(bob, &[alice]);
556 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
559 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
560 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
561 /// introduction node of the blinded path.
563 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
564 let chanmon_cfgs = create_chanmon_cfgs(2);
565 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
566 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
567 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
569 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
571 let alice = &nodes[0];
572 let alice_id = alice.node.get_our_node_id();
574 let bob_id = bob.node.get_our_node_id();
576 let absolute_expiry = Duration::from_secs(u64::MAX);
577 let payment_id = PaymentId([1; 32]);
578 let refund = bob.node
579 .create_refund_builder(
580 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
584 assert_eq!(refund.amount_msats(), 10_000_000);
585 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
586 assert_ne!(refund.payer_id(), bob_id);
587 assert!(!refund.paths().is_empty());
588 for path in refund.paths() {
589 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
591 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
593 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
595 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
596 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
598 let invoice = extract_invoice(bob, &onion_message);
599 assert_eq!(invoice, expected_invoice);
601 assert_eq!(invoice.amount_msats(), 10_000_000);
602 assert_ne!(invoice.signing_pubkey(), alice_id);
603 assert!(!invoice.payment_paths().is_empty());
604 for (_, path) in invoice.payment_paths() {
605 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
608 route_bolt12_payment(bob, &[alice], &invoice);
609 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
611 claim_bolt12_payment(bob, &[alice]);
612 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
615 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
616 /// the requested is sent directly using the node's pubkey, the response and the payment still use
617 /// blinded paths as required by the spec.
619 fn pays_for_offer_without_blinded_paths() {
620 let chanmon_cfgs = create_chanmon_cfgs(2);
621 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
622 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
623 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
625 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
627 let alice = &nodes[0];
628 let alice_id = alice.node.get_our_node_id();
630 let bob_id = bob.node.get_our_node_id();
632 let offer = alice.node
633 .create_offer_builder("coffee".to_string()).unwrap()
635 .amount_msats(10_000_000)
637 assert_eq!(offer.signing_pubkey(), alice_id);
638 assert!(offer.paths().is_empty());
640 let payment_id = PaymentId([1; 32]);
641 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
642 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
644 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
645 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
647 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
648 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
650 let invoice = extract_invoice(bob, &onion_message);
651 route_bolt12_payment(bob, &[alice], &invoice);
652 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
654 claim_bolt12_payment(bob, &[alice]);
655 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
658 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
659 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
661 fn pays_for_refund_without_blinded_paths() {
662 let chanmon_cfgs = create_chanmon_cfgs(2);
663 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
664 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
665 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
667 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
669 let alice = &nodes[0];
670 let alice_id = alice.node.get_our_node_id();
672 let bob_id = bob.node.get_our_node_id();
674 let absolute_expiry = Duration::from_secs(u64::MAX);
675 let payment_id = PaymentId([1; 32]);
676 let refund = bob.node
677 .create_refund_builder(
678 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
683 assert_eq!(refund.payer_id(), bob_id);
684 assert!(refund.paths().is_empty());
685 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
687 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
689 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
690 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
692 let invoice = extract_invoice(bob, &onion_message);
693 assert_eq!(invoice, expected_invoice);
695 route_bolt12_payment(bob, &[alice], &invoice);
696 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
698 claim_bolt12_payment(bob, &[alice]);
699 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
702 /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
704 fn fails_creating_offer_without_blinded_paths() {
705 let chanmon_cfgs = create_chanmon_cfgs(2);
706 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
707 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
708 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
710 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
712 match nodes[0].node.create_offer_builder("coffee".to_string()) {
713 Ok(_) => panic!("Expected error"),
714 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
718 /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
720 fn fails_creating_refund_without_blinded_paths() {
721 let chanmon_cfgs = create_chanmon_cfgs(2);
722 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
723 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
724 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
726 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
728 let absolute_expiry = Duration::from_secs(u64::MAX);
729 let payment_id = PaymentId([1; 32]);
731 match nodes[0].node.create_refund_builder(
732 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
734 Ok(_) => panic!("Expected error"),
735 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
738 assert!(nodes[0].node.list_recent_payments().is_empty());
741 /// Fails creating an invoice request when the offer contains an unsupported chain.
743 fn fails_creating_invoice_request_for_unsupported_chain() {
744 let chanmon_cfgs = create_chanmon_cfgs(2);
745 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
746 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
747 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
749 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
751 let alice = &nodes[0];
754 let offer = alice.node
755 .create_offer_builder("coffee".to_string()).unwrap()
757 .chain(Network::Signet)
760 let payment_id = PaymentId([1; 32]);
761 match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
762 Ok(_) => panic!("Expected error"),
763 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
767 /// Fails requesting a payment when the refund contains an unsupported chain.
769 fn fails_sending_invoice_with_unsupported_chain_for_refund() {
770 let chanmon_cfgs = create_chanmon_cfgs(2);
771 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
772 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
773 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
775 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
777 let alice = &nodes[0];
780 let absolute_expiry = Duration::from_secs(u64::MAX);
781 let payment_id = PaymentId([1; 32]);
782 let refund = bob.node
783 .create_refund_builder(
784 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
787 .chain(Network::Signet)
790 match alice.node.request_refund_payment(&refund) {
791 Ok(_) => panic!("Expected error"),
792 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
796 /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
799 fn fails_creating_invoice_request_without_blinded_reply_path() {
800 let chanmon_cfgs = create_chanmon_cfgs(6);
801 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
802 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
803 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
805 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
806 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
807 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
808 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
809 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
811 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
813 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
814 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
816 let offer = alice.node
817 .create_offer_builder("coffee".to_string()).unwrap()
818 .amount_msats(10_000_000)
821 let payment_id = PaymentId([1; 32]);
823 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
824 Ok(_) => panic!("Expected error"),
825 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
828 assert!(nodes[0].node.list_recent_payments().is_empty());
832 fn fails_creating_invoice_request_with_duplicate_payment_id() {
833 let chanmon_cfgs = create_chanmon_cfgs(6);
834 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
835 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
836 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
838 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
839 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
840 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
841 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
842 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
843 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
844 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
846 let (alice, _bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
848 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
850 let offer = alice.node
851 .create_offer_builder("coffee".to_string()).unwrap()
852 .amount_msats(10_000_000)
855 let payment_id = PaymentId([1; 32]);
857 david.node.pay_for_offer(
858 &offer, None, None, None, payment_id, Retry::Attempts(0), None
861 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
863 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
864 Ok(_) => panic!("Expected error"),
865 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
868 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
872 fn fails_creating_refund_with_duplicate_payment_id() {
873 let chanmon_cfgs = create_chanmon_cfgs(2);
874 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
875 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
876 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
878 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
880 let absolute_expiry = Duration::from_secs(u64::MAX);
881 let payment_id = PaymentId([1; 32]);
883 nodes[0].node.create_refund_builder(
884 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
887 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
889 match nodes[0].node.create_refund_builder(
890 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
892 Ok(_) => panic!("Expected error"),
893 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
896 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
900 fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
901 let mut accept_forward_cfg = test_default_channel_config();
902 accept_forward_cfg.accept_forwards_to_priv_channels = true;
904 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
905 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
906 features.set_onion_messages_optional();
907 features.clear_route_blinding();
909 let chanmon_cfgs = create_chanmon_cfgs(6);
910 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
912 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
914 let node_chanmgrs = create_node_chanmgrs(
915 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
917 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
919 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
920 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
921 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
922 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
923 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
924 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
925 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
927 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
928 let alice_id = alice.node.get_our_node_id();
929 let bob_id = bob.node.get_our_node_id();
930 let charlie_id = charlie.node.get_our_node_id();
931 let david_id = david.node.get_our_node_id();
933 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
934 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
936 let offer = alice.node
937 .create_offer_builder("coffee".to_string()).unwrap()
938 .amount_msats(10_000_000)
941 let payment_id = PaymentId([1; 32]);
942 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
945 connect_peers(david, bob);
947 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
948 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
950 connect_peers(alice, charlie);
952 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
953 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
955 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
956 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
958 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
959 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
961 let invoice_error = extract_invoice_error(david, &onion_message);
962 assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
966 fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
967 let mut accept_forward_cfg = test_default_channel_config();
968 accept_forward_cfg.accept_forwards_to_priv_channels = true;
970 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
971 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
972 features.set_onion_messages_optional();
973 features.clear_route_blinding();
975 let chanmon_cfgs = create_chanmon_cfgs(6);
976 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
978 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
980 let node_chanmgrs = create_node_chanmgrs(
981 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
983 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
985 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
986 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
987 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
988 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
989 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
990 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
991 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
993 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
995 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
996 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
998 let absolute_expiry = Duration::from_secs(u64::MAX);
999 let payment_id = PaymentId([1; 32]);
1000 let refund = david.node
1001 .create_refund_builder(
1002 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1007 match alice.node.request_refund_payment(&refund) {
1008 Ok(_) => panic!("Expected error"),
1009 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1014 fn fails_paying_invoice_more_than_once() {
1015 let mut accept_forward_cfg = test_default_channel_config();
1016 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1018 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1019 features.set_onion_messages_optional();
1020 features.set_route_blinding_optional();
1022 let chanmon_cfgs = create_chanmon_cfgs(6);
1023 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1025 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1027 let node_chanmgrs = create_node_chanmgrs(
1028 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1030 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1032 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1033 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1034 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1035 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1036 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1037 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1038 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1040 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1041 let alice_id = alice.node.get_our_node_id();
1042 let bob_id = bob.node.get_our_node_id();
1043 let charlie_id = charlie.node.get_our_node_id();
1044 let david_id = david.node.get_our_node_id();
1046 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1047 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1049 let absolute_expiry = Duration::from_secs(u64::MAX);
1050 let payment_id = PaymentId([1; 32]);
1051 let refund = david.node
1052 .create_refund_builder(
1053 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1057 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1059 // Alice sends the first invoice
1060 alice.node.request_refund_payment(&refund).unwrap();
1062 connect_peers(alice, charlie);
1064 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1065 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1067 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1068 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1070 // David pays the first invoice
1071 let invoice1 = extract_invoice(david, &onion_message);
1073 route_bolt12_payment(david, &[charlie, bob, alice], &invoice1);
1074 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
1076 claim_bolt12_payment(david, &[charlie, bob, alice]);
1077 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
1079 disconnect_peers(alice, &[charlie]);
1081 // Alice sends the second invoice
1082 alice.node.request_refund_payment(&refund).unwrap();
1084 connect_peers(alice, charlie);
1085 connect_peers(david, bob);
1087 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1088 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1090 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1091 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1093 let invoice2 = extract_invoice(david, &onion_message);
1094 assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata());
1096 // David sends an error instead of paying the second invoice
1097 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1098 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1100 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1101 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1103 let invoice_error = extract_invoice_error(alice, &onion_message);
1104 assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));