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::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext};
47 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
48 use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
49 use crate::ln::functional_test_utils::*;
50 use crate::ln::msgs::{ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
51 use crate::offers::invoice::Bolt12Invoice;
52 use crate::offers::invoice_error::InvoiceError;
53 use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields};
54 use crate::offers::parse::Bolt12SemanticError;
55 use crate::onion_message::messenger::PeeledOnion;
56 use crate::onion_message::offers::OffersMessage;
57 use crate::onion_message::packet::ParsedOnionMessageContents;
58 use crate::routing::gossip::{NodeAlias, NodeId};
59 use crate::sign::{NodeSigner, Recipient};
61 use crate::prelude::*;
63 macro_rules! expect_recent_payment {
64 ($node: expr, $payment_state: path, $payment_id: expr) => {
65 match $node.node.list_recent_payments().first() {
66 Some(&$payment_state { payment_id: actual_payment_id, .. }) => {
67 assert_eq!($payment_id, actual_payment_id);
69 Some(_) => panic!("Unexpected recent payment state"),
70 None => panic!("No recent payments"),
75 fn connect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) {
76 let node_id_a = node_a.node.get_our_node_id();
77 let node_id_b = node_b.node.get_our_node_id();
80 features: node_a.init_features(&node_id_b),
82 remote_network_address: None,
85 features: node_b.init_features(&node_id_a),
87 remote_network_address: None,
90 node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap();
91 node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap();
92 node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap();
93 node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap();
96 fn disconnect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>]) {
98 node_a.node.peer_disconnected(&node_b.node.get_our_node_id());
99 node_b.node.peer_disconnected(&node_a.node.get_our_node_id());
100 node_a.onion_messenger.peer_disconnected(&node_b.node.get_our_node_id());
101 node_b.onion_messenger.peer_disconnected(&node_a.node.get_our_node_id());
105 fn announce_node_address<'a, 'b, 'c>(
106 node: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>], address: SocketAddress,
108 let features = node.onion_messenger.provided_node_features()
109 | node.gossip_sync.provided_node_features();
111 let announcement = UnsignedNodeAnnouncement {
114 node_id: NodeId::from_pubkey(&node.keys_manager.get_node_id(Recipient::Node).unwrap()),
116 alias: NodeAlias([0u8; 32]),
117 addresses: vec![address],
118 excess_address_data: Vec::new(),
119 excess_data: Vec::new(),
121 let signature = node.keys_manager.sign_gossip_message(
122 UnsignedGossipMessage::NodeAnnouncement(&announcement)
125 let msg = NodeAnnouncement {
127 contents: announcement
130 node.gossip_sync.handle_node_announcement(&msg).unwrap();
132 peer.gossip_sync.handle_node_announcement(&msg).unwrap();
136 fn route_bolt12_payment<'a, 'b, 'c>(
137 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice
139 // Monitor added when handling the invoice onion message.
140 check_added_monitors(node, 1);
142 let mut events = node.node.get_and_clear_pending_msg_events();
143 assert_eq!(events.len(), 1);
144 let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
146 // Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
147 // invoice contains the payment_hash but it was encrypted inside an onion message.
148 let amount_msats = invoice.amount_msats();
149 let payment_hash = invoice.payment_hash();
150 let args = PassAlongPathArgs::new(node, path, amount_msats, payment_hash, ev)
151 .without_clearing_recipient_events();
152 do_pass_along_path(args);
155 fn claim_bolt12_payment<'a, 'b, 'c>(
156 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], expected_payment_context: PaymentContext
158 let recipient = &path[path.len() - 1];
159 let payment_purpose = match get_event!(recipient, Event::PaymentClaimable) {
160 Event::PaymentClaimable { purpose, .. } => purpose,
161 _ => panic!("No Event::PaymentClaimable"),
163 let payment_preimage = match payment_purpose.preimage() {
164 Some(preimage) => preimage,
165 None => panic!("No preimage in Event::PaymentClaimable"),
167 match payment_purpose {
168 PaymentPurpose::Bolt12OfferPayment { payment_context, .. } => {
169 assert_eq!(PaymentContext::Bolt12Offer(payment_context), expected_payment_context);
171 PaymentPurpose::Bolt12RefundPayment { payment_context, .. } => {
172 assert_eq!(PaymentContext::Bolt12Refund(payment_context), expected_payment_context);
174 _ => panic!("Unexpected payment purpose: {:?}", payment_purpose),
176 claim_payment(node, path, payment_preimage);
179 fn extract_invoice_request<'a, 'b, 'c>(
180 node: &Node<'a, 'b, 'c>, message: &OnionMessage
181 ) -> (InvoiceRequest, Option<BlindedPath>) {
182 match node.onion_messenger.peel_onion_message(message) {
183 Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
184 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
185 OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path),
186 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
187 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
189 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
191 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
192 Err(e) => panic!("Failed to process onion message {:?}", e),
196 fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
197 match node.onion_messenger.peel_onion_message(message) {
198 Ok(PeeledOnion::Receive(message, _, _)) => match message {
199 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
200 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
201 OffersMessage::Invoice(invoice) => invoice,
202 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
204 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
206 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
207 Err(e) => panic!("Failed to process onion message {:?}", e),
211 fn extract_invoice_error<'a, 'b, 'c>(
212 node: &Node<'a, 'b, 'c>, message: &OnionMessage
214 match node.onion_messenger.peel_onion_message(message) {
215 Ok(PeeledOnion::Receive(message, _, _)) => match message {
216 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
217 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
218 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
219 OffersMessage::InvoiceError(error) => error,
221 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
223 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
224 Err(e) => panic!("Failed to process onion message {:?}", e),
228 /// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
230 fn prefers_non_tor_nodes_in_blinded_paths() {
231 let mut accept_forward_cfg = test_default_channel_config();
232 accept_forward_cfg.accept_forwards_to_priv_channels = true;
234 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
235 features.set_onion_messages_optional();
236 features.set_route_blinding_optional();
238 let chanmon_cfgs = create_chanmon_cfgs(6);
239 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
241 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
243 let node_chanmgrs = create_node_chanmgrs(
244 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
246 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
248 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
249 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
250 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
251 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
252 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
253 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
254 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
256 // Add an extra channel so that more than one of Bob's peers have MIN_PEER_CHANNELS.
257 create_announced_chan_between_nodes_with_value(&nodes, 4, 5, 10_000_000, 1_000_000_000);
259 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
260 let bob_id = bob.node.get_our_node_id();
261 let charlie_id = charlie.node.get_our_node_id();
263 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
264 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
266 let tor = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
267 announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());
270 .create_offer_builder("coffee".to_string()).unwrap()
271 .amount_msats(10_000_000)
273 assert_ne!(offer.signing_pubkey(), Some(bob_id));
274 assert!(!offer.paths().is_empty());
275 for path in offer.paths() {
276 assert_ne!(path.introduction_node, IntroductionNode::NodeId(bob_id));
277 assert_ne!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
280 // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
281 announce_node_address(&nodes[4], &[alice, bob, charlie, david, &nodes[5]], tor.clone());
282 announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
285 .create_offer_builder("coffee".to_string()).unwrap()
286 .amount_msats(10_000_000)
288 assert_ne!(offer.signing_pubkey(), Some(bob_id));
289 assert!(!offer.paths().is_empty());
290 for path in offer.paths() {
291 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
295 /// Checks that blinded paths prefer an introduction node that is the most connected.
297 fn prefers_more_connected_nodes_in_blinded_paths() {
298 let mut accept_forward_cfg = test_default_channel_config();
299 accept_forward_cfg.accept_forwards_to_priv_channels = true;
301 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
302 features.set_onion_messages_optional();
303 features.set_route_blinding_optional();
305 let chanmon_cfgs = create_chanmon_cfgs(6);
306 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
308 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
310 let node_chanmgrs = create_node_chanmgrs(
311 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
313 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
315 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
316 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
317 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
318 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
319 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
320 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
321 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
323 // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
324 // more than the others.
325 create_announced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000_000, 1_000_000_000);
326 create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 10_000_000, 1_000_000_000);
328 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
329 let bob_id = bob.node.get_our_node_id();
331 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
332 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
335 .create_offer_builder("coffee".to_string()).unwrap()
336 .amount_msats(10_000_000)
338 assert_ne!(offer.signing_pubkey(), Some(bob_id));
339 assert!(!offer.paths().is_empty());
340 for path in offer.paths() {
341 assert_eq!(path.introduction_node, IntroductionNode::NodeId(nodes[4].node.get_our_node_id()));
345 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
346 /// rather than exposing a node's pubkey.
348 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
349 let mut accept_forward_cfg = test_default_channel_config();
350 accept_forward_cfg.accept_forwards_to_priv_channels = true;
352 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
353 features.set_onion_messages_optional();
354 features.set_route_blinding_optional();
356 let chanmon_cfgs = create_chanmon_cfgs(6);
357 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
359 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
361 let node_chanmgrs = create_node_chanmgrs(
362 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
364 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
366 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
367 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
368 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
369 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
370 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
371 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
372 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
374 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
375 let alice_id = alice.node.get_our_node_id();
376 let bob_id = bob.node.get_our_node_id();
377 let charlie_id = charlie.node.get_our_node_id();
378 let david_id = david.node.get_our_node_id();
380 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
381 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
383 let offer = alice.node
384 .create_offer_builder("coffee".to_string())
386 .amount_msats(10_000_000)
388 assert_ne!(offer.signing_pubkey(), Some(alice_id));
389 assert!(!offer.paths().is_empty());
390 for path in offer.paths() {
391 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
394 let payment_id = PaymentId([1; 32]);
395 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
397 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
399 connect_peers(david, bob);
401 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
402 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
404 connect_peers(alice, charlie);
406 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
407 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
409 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
410 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
411 offer_id: offer.id(),
412 invoice_request: InvoiceRequestFields {
413 payer_id: invoice_request.payer_id(),
415 payer_note_truncated: None,
418 assert_eq!(invoice_request.amount_msats(), None);
419 assert_ne!(invoice_request.payer_id(), david_id);
420 assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(charlie_id));
422 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
423 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
425 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
426 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
428 let invoice = extract_invoice(david, &onion_message);
429 assert_eq!(invoice.amount_msats(), 10_000_000);
430 assert_ne!(invoice.signing_pubkey(), alice_id);
431 assert!(!invoice.payment_paths().is_empty());
432 for (_, path) in invoice.payment_paths() {
433 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
436 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
437 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
439 claim_bolt12_payment(david, &[charlie, bob, alice], payment_context);
440 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
443 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
444 /// rather than exposing a node's pubkey.
446 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
447 let mut accept_forward_cfg = test_default_channel_config();
448 accept_forward_cfg.accept_forwards_to_priv_channels = true;
450 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
451 features.set_onion_messages_optional();
452 features.set_route_blinding_optional();
454 let chanmon_cfgs = create_chanmon_cfgs(6);
455 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
457 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
459 let node_chanmgrs = create_node_chanmgrs(
460 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
462 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
464 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
465 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
466 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
467 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
468 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
469 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
470 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
472 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
473 let alice_id = alice.node.get_our_node_id();
474 let bob_id = bob.node.get_our_node_id();
475 let charlie_id = charlie.node.get_our_node_id();
476 let david_id = david.node.get_our_node_id();
478 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
479 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
481 let absolute_expiry = Duration::from_secs(u64::MAX);
482 let payment_id = PaymentId([1; 32]);
483 let refund = david.node
484 .create_refund_builder(
485 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
489 assert_eq!(refund.amount_msats(), 10_000_000);
490 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
491 assert_ne!(refund.payer_id(), david_id);
492 assert!(!refund.paths().is_empty());
493 for path in refund.paths() {
494 assert_eq!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
496 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
498 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
499 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
501 connect_peers(alice, charlie);
503 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
504 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
506 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
507 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
509 let invoice = extract_invoice(david, &onion_message);
510 assert_eq!(invoice, expected_invoice);
512 assert_eq!(invoice.amount_msats(), 10_000_000);
513 assert_ne!(invoice.signing_pubkey(), alice_id);
514 assert!(!invoice.payment_paths().is_empty());
515 for (_, path) in invoice.payment_paths() {
516 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
519 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
520 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
522 claim_bolt12_payment(david, &[charlie, bob, alice], payment_context);
523 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
526 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
527 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
528 /// introduction node of the blinded path.
530 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
531 let chanmon_cfgs = create_chanmon_cfgs(2);
532 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
533 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
534 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
536 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
538 let alice = &nodes[0];
539 let alice_id = alice.node.get_our_node_id();
541 let bob_id = bob.node.get_our_node_id();
543 let offer = alice.node
544 .create_offer_builder("coffee".to_string()).unwrap()
545 .amount_msats(10_000_000)
547 assert_ne!(offer.signing_pubkey(), Some(alice_id));
548 assert!(!offer.paths().is_empty());
549 for path in offer.paths() {
550 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
553 let payment_id = PaymentId([1; 32]);
554 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
555 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
557 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
558 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
560 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
561 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
562 offer_id: offer.id(),
563 invoice_request: InvoiceRequestFields {
564 payer_id: invoice_request.payer_id(),
566 payer_note_truncated: None,
569 assert_eq!(invoice_request.amount_msats(), None);
570 assert_ne!(invoice_request.payer_id(), bob_id);
571 assert_eq!(reply_path.unwrap().introduction_node, IntroductionNode::NodeId(bob_id));
573 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
574 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
576 let invoice = extract_invoice(bob, &onion_message);
577 assert_eq!(invoice.amount_msats(), 10_000_000);
578 assert_ne!(invoice.signing_pubkey(), alice_id);
579 assert!(!invoice.payment_paths().is_empty());
580 for (_, path) in invoice.payment_paths() {
581 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
584 route_bolt12_payment(bob, &[alice], &invoice);
585 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
587 claim_bolt12_payment(bob, &[alice], payment_context);
588 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
591 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
592 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
593 /// introduction node of the blinded path.
595 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
596 let chanmon_cfgs = create_chanmon_cfgs(2);
597 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
598 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
599 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
601 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
603 let alice = &nodes[0];
604 let alice_id = alice.node.get_our_node_id();
606 let bob_id = bob.node.get_our_node_id();
608 let absolute_expiry = Duration::from_secs(u64::MAX);
609 let payment_id = PaymentId([1; 32]);
610 let refund = bob.node
611 .create_refund_builder(
612 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
616 assert_eq!(refund.amount_msats(), 10_000_000);
617 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
618 assert_ne!(refund.payer_id(), bob_id);
619 assert!(!refund.paths().is_empty());
620 for path in refund.paths() {
621 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
623 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
625 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
626 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
628 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
629 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
631 let invoice = extract_invoice(bob, &onion_message);
632 assert_eq!(invoice, expected_invoice);
634 assert_eq!(invoice.amount_msats(), 10_000_000);
635 assert_ne!(invoice.signing_pubkey(), alice_id);
636 assert!(!invoice.payment_paths().is_empty());
637 for (_, path) in invoice.payment_paths() {
638 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
641 route_bolt12_payment(bob, &[alice], &invoice);
642 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
644 claim_bolt12_payment(bob, &[alice], payment_context);
645 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
648 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
649 /// the requested is sent directly using the node's pubkey, the response and the payment still use
650 /// blinded paths as required by the spec.
652 fn pays_for_offer_without_blinded_paths() {
653 let chanmon_cfgs = create_chanmon_cfgs(2);
654 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
655 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
656 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
658 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
660 let alice = &nodes[0];
661 let alice_id = alice.node.get_our_node_id();
663 let bob_id = bob.node.get_our_node_id();
665 let offer = alice.node
666 .create_offer_builder("coffee".to_string()).unwrap()
668 .amount_msats(10_000_000)
670 assert_eq!(offer.signing_pubkey(), Some(alice_id));
671 assert!(offer.paths().is_empty());
673 let payment_id = PaymentId([1; 32]);
674 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
675 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
677 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
678 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
680 let (invoice_request, _) = extract_invoice_request(alice, &onion_message);
681 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
682 offer_id: offer.id(),
683 invoice_request: InvoiceRequestFields {
684 payer_id: invoice_request.payer_id(),
686 payer_note_truncated: None,
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 route_bolt12_payment(bob, &[alice], &invoice);
695 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
697 claim_bolt12_payment(bob, &[alice], payment_context);
698 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
701 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
702 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
704 fn pays_for_refund_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_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
712 let alice = &nodes[0];
713 let alice_id = alice.node.get_our_node_id();
715 let bob_id = bob.node.get_our_node_id();
717 let absolute_expiry = Duration::from_secs(u64::MAX);
718 let payment_id = PaymentId([1; 32]);
719 let refund = bob.node
720 .create_refund_builder(
721 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
726 assert_eq!(refund.payer_id(), bob_id);
727 assert!(refund.paths().is_empty());
728 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
730 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
731 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
733 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
734 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
736 let invoice = extract_invoice(bob, &onion_message);
737 assert_eq!(invoice, expected_invoice);
739 route_bolt12_payment(bob, &[alice], &invoice);
740 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
742 claim_bolt12_payment(bob, &[alice], payment_context);
743 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
746 /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
748 fn fails_creating_offer_without_blinded_paths() {
749 let chanmon_cfgs = create_chanmon_cfgs(2);
750 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
751 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
752 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
754 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
756 match nodes[0].node.create_offer_builder("coffee".to_string()) {
757 Ok(_) => panic!("Expected error"),
758 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
762 /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
764 fn fails_creating_refund_without_blinded_paths() {
765 let chanmon_cfgs = create_chanmon_cfgs(2);
766 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
767 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
768 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
770 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
772 let absolute_expiry = Duration::from_secs(u64::MAX);
773 let payment_id = PaymentId([1; 32]);
775 match nodes[0].node.create_refund_builder(
776 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
778 Ok(_) => panic!("Expected error"),
779 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
782 assert!(nodes[0].node.list_recent_payments().is_empty());
785 /// Fails creating an invoice request when the offer contains an unsupported chain.
787 fn fails_creating_invoice_request_for_unsupported_chain() {
788 let chanmon_cfgs = create_chanmon_cfgs(2);
789 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
790 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
791 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
793 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
795 let alice = &nodes[0];
798 let offer = alice.node
799 .create_offer_builder("coffee".to_string()).unwrap()
801 .chain(Network::Signet)
804 let payment_id = PaymentId([1; 32]);
805 match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
806 Ok(_) => panic!("Expected error"),
807 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
811 /// Fails requesting a payment when the refund contains an unsupported chain.
813 fn fails_sending_invoice_with_unsupported_chain_for_refund() {
814 let chanmon_cfgs = create_chanmon_cfgs(2);
815 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
816 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
817 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
819 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
821 let alice = &nodes[0];
824 let absolute_expiry = Duration::from_secs(u64::MAX);
825 let payment_id = PaymentId([1; 32]);
826 let refund = bob.node
827 .create_refund_builder(
828 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
831 .chain(Network::Signet)
834 match alice.node.request_refund_payment(&refund) {
835 Ok(_) => panic!("Expected error"),
836 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
840 /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
843 fn fails_creating_invoice_request_without_blinded_reply_path() {
844 let chanmon_cfgs = create_chanmon_cfgs(6);
845 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
846 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
847 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
849 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
850 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
851 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
852 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
853 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
855 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
857 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
858 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
860 let offer = alice.node
861 .create_offer_builder("coffee".to_string()).unwrap()
862 .amount_msats(10_000_000)
865 let payment_id = PaymentId([1; 32]);
867 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
868 Ok(_) => panic!("Expected error"),
869 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
872 assert!(nodes[0].node.list_recent_payments().is_empty());
876 fn fails_creating_invoice_request_with_duplicate_payment_id() {
877 let chanmon_cfgs = create_chanmon_cfgs(6);
878 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
879 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
880 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
882 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
883 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
884 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
885 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
886 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
887 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
888 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
890 let (alice, _bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
892 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
894 let offer = alice.node
895 .create_offer_builder("coffee".to_string()).unwrap()
896 .amount_msats(10_000_000)
899 let payment_id = PaymentId([1; 32]);
901 david.node.pay_for_offer(
902 &offer, None, None, None, payment_id, Retry::Attempts(0), None
905 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
907 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
908 Ok(_) => panic!("Expected error"),
909 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
912 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
916 fn fails_creating_refund_with_duplicate_payment_id() {
917 let chanmon_cfgs = create_chanmon_cfgs(2);
918 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
919 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
920 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
922 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
924 let absolute_expiry = Duration::from_secs(u64::MAX);
925 let payment_id = PaymentId([1; 32]);
927 nodes[0].node.create_refund_builder(
928 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
931 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
933 match nodes[0].node.create_refund_builder(
934 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
936 Ok(_) => panic!("Expected error"),
937 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
940 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
944 fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
945 let mut accept_forward_cfg = test_default_channel_config();
946 accept_forward_cfg.accept_forwards_to_priv_channels = true;
948 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
949 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
950 features.set_onion_messages_optional();
951 features.clear_route_blinding();
953 let chanmon_cfgs = create_chanmon_cfgs(6);
954 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
956 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
958 let node_chanmgrs = create_node_chanmgrs(
959 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
961 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
963 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
964 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
965 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
966 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
967 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
968 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
969 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
971 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
972 let alice_id = alice.node.get_our_node_id();
973 let bob_id = bob.node.get_our_node_id();
974 let charlie_id = charlie.node.get_our_node_id();
975 let david_id = david.node.get_our_node_id();
977 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
978 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
980 let offer = alice.node
981 .create_offer_builder("coffee".to_string()).unwrap()
982 .amount_msats(10_000_000)
985 let payment_id = PaymentId([1; 32]);
986 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
989 connect_peers(david, bob);
991 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
992 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
994 connect_peers(alice, charlie);
996 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
997 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
999 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1000 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1002 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1003 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1005 let invoice_error = extract_invoice_error(david, &onion_message);
1006 assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
1010 fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
1011 let mut accept_forward_cfg = test_default_channel_config();
1012 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1014 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
1015 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1016 features.set_onion_messages_optional();
1017 features.clear_route_blinding();
1019 let chanmon_cfgs = create_chanmon_cfgs(6);
1020 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1022 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1024 let node_chanmgrs = create_node_chanmgrs(
1025 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1027 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1029 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1030 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1031 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1032 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1033 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1034 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1035 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1037 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1039 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1040 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1042 let absolute_expiry = Duration::from_secs(u64::MAX);
1043 let payment_id = PaymentId([1; 32]);
1044 let refund = david.node
1045 .create_refund_builder(
1046 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1051 match alice.node.request_refund_payment(&refund) {
1052 Ok(_) => panic!("Expected error"),
1053 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1058 fn fails_paying_invoice_more_than_once() {
1059 let mut accept_forward_cfg = test_default_channel_config();
1060 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1062 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1063 features.set_onion_messages_optional();
1064 features.set_route_blinding_optional();
1066 let chanmon_cfgs = create_chanmon_cfgs(6);
1067 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1069 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1071 let node_chanmgrs = create_node_chanmgrs(
1072 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1074 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1076 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1077 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1078 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1079 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1080 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1081 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1082 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1084 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1085 let alice_id = alice.node.get_our_node_id();
1086 let bob_id = bob.node.get_our_node_id();
1087 let charlie_id = charlie.node.get_our_node_id();
1088 let david_id = david.node.get_our_node_id();
1090 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1091 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1093 let absolute_expiry = Duration::from_secs(u64::MAX);
1094 let payment_id = PaymentId([1; 32]);
1095 let refund = david.node
1096 .create_refund_builder(
1097 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1101 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1103 // Alice sends the first invoice
1104 alice.node.request_refund_payment(&refund).unwrap();
1106 connect_peers(alice, charlie);
1108 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1109 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1111 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1112 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1114 // David pays the first invoice
1115 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1116 let invoice1 = extract_invoice(david, &onion_message);
1118 route_bolt12_payment(david, &[charlie, bob, alice], &invoice1);
1119 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
1121 claim_bolt12_payment(david, &[charlie, bob, alice], payment_context);
1122 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
1124 disconnect_peers(alice, &[charlie]);
1126 // Alice sends the second invoice
1127 alice.node.request_refund_payment(&refund).unwrap();
1129 connect_peers(alice, charlie);
1130 connect_peers(david, bob);
1132 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1133 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1135 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1136 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1138 let invoice2 = extract_invoice(david, &onion_message);
1139 assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata());
1141 // David sends an error instead of paying the second invoice
1142 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1143 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1145 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1146 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1148 let invoice_error = extract_invoice_error(alice, &onion_message);
1149 assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));