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;
46 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
47 use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
48 use crate::ln::functional_test_utils::*;
49 use crate::ln::msgs::{ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
50 use crate::offers::invoice::Bolt12Invoice;
51 use crate::offers::invoice_error::InvoiceError;
52 use crate::offers::invoice_request::InvoiceRequest;
53 use crate::offers::parse::Bolt12SemanticError;
54 use crate::onion_message::messenger::PeeledOnion;
55 use crate::onion_message::offers::OffersMessage;
56 use crate::onion_message::packet::ParsedOnionMessageContents;
57 use crate::routing::gossip::{NodeAlias, NodeId};
58 use crate::sign::{NodeSigner, Recipient};
60 use crate::prelude::*;
62 macro_rules! expect_recent_payment {
63 ($node: expr, $payment_state: path, $payment_id: expr) => {
64 match $node.node.list_recent_payments().first() {
65 Some(&$payment_state { payment_id: actual_payment_id, .. }) => {
66 assert_eq!($payment_id, actual_payment_id);
68 Some(_) => panic!("Unexpected recent payment state"),
69 None => panic!("No recent payments"),
74 fn connect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) {
75 let node_id_a = node_a.node.get_our_node_id();
76 let node_id_b = node_b.node.get_our_node_id();
79 features: node_a.init_features(&node_id_b),
81 remote_network_address: None,
84 features: node_b.init_features(&node_id_a),
86 remote_network_address: None,
89 node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap();
90 node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap();
91 node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap();
92 node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap();
95 fn disconnect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>]) {
97 node_a.node.peer_disconnected(&node_b.node.get_our_node_id());
98 node_b.node.peer_disconnected(&node_a.node.get_our_node_id());
99 node_a.onion_messenger.peer_disconnected(&node_b.node.get_our_node_id());
100 node_b.onion_messenger.peer_disconnected(&node_a.node.get_our_node_id());
104 fn announce_node_address<'a, 'b, 'c>(
105 node: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>], address: SocketAddress,
107 let features = node.onion_messenger.provided_node_features()
108 | node.gossip_sync.provided_node_features();
110 let announcement = UnsignedNodeAnnouncement {
113 node_id: NodeId::from_pubkey(&node.keys_manager.get_node_id(Recipient::Node).unwrap()),
115 alias: NodeAlias([0u8; 32]),
116 addresses: vec![address],
117 excess_address_data: Vec::new(),
118 excess_data: Vec::new(),
120 let signature = node.keys_manager.sign_gossip_message(
121 UnsignedGossipMessage::NodeAnnouncement(&announcement)
124 let msg = NodeAnnouncement {
126 contents: announcement
129 node.gossip_sync.handle_node_announcement(&msg).unwrap();
131 peer.gossip_sync.handle_node_announcement(&msg).unwrap();
135 fn route_bolt12_payment<'a, 'b, 'c>(
136 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice
138 // Monitor added when handling the invoice onion message.
139 check_added_monitors(node, 1);
141 let mut events = node.node.get_and_clear_pending_msg_events();
142 assert_eq!(events.len(), 1);
143 let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
145 // Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
146 // invoice contains the payment_hash but it was encrypted inside an onion message.
147 let amount_msats = invoice.amount_msats();
148 let payment_hash = invoice.payment_hash();
150 node, path, amount_msats, payment_hash, None, ev, false, false, None, false
154 fn claim_bolt12_payment<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>]) {
155 let recipient = &path[path.len() - 1];
156 match get_event!(recipient, Event::PaymentClaimable) {
157 Event::PaymentClaimable {
158 purpose: PaymentPurpose::InvoicePayment {
159 payment_preimage: Some(payment_preimage), ..
161 } => claim_payment(node, path, payment_preimage),
166 fn extract_invoice_request<'a, 'b, 'c>(
167 node: &Node<'a, 'b, 'c>, message: &OnionMessage
168 ) -> (InvoiceRequest, Option<BlindedPath>) {
169 match node.onion_messenger.peel_onion_message(message) {
170 Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
171 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
172 OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path),
173 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
174 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
176 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
178 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
179 Err(e) => panic!("Failed to process onion message {:?}", e),
183 fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
184 match node.onion_messenger.peel_onion_message(message) {
185 Ok(PeeledOnion::Receive(message, _, _)) => match message {
186 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
187 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
188 OffersMessage::Invoice(invoice) => invoice,
189 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
191 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
193 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
194 Err(e) => panic!("Failed to process onion message {:?}", e),
198 fn extract_invoice_error<'a, 'b, 'c>(
199 node: &Node<'a, 'b, 'c>, message: &OnionMessage
201 match node.onion_messenger.peel_onion_message(message) {
202 Ok(PeeledOnion::Receive(message, _, _)) => match message {
203 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
204 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
205 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
206 OffersMessage::InvoiceError(error) => error,
208 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
210 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
211 Err(e) => panic!("Failed to process onion message {:?}", e),
215 /// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
217 fn prefers_non_tor_nodes_in_blinded_paths() {
218 let mut accept_forward_cfg = test_default_channel_config();
219 accept_forward_cfg.accept_forwards_to_priv_channels = true;
221 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
222 features.set_onion_messages_optional();
223 features.set_route_blinding_optional();
225 let chanmon_cfgs = create_chanmon_cfgs(6);
226 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
228 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
230 let node_chanmgrs = create_node_chanmgrs(
231 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
233 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
235 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
236 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
237 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
238 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
239 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
240 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
241 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
243 // Add an extra channel so that more than one of Bob's peers have MIN_PEER_CHANNELS.
244 create_announced_chan_between_nodes_with_value(&nodes, 4, 5, 10_000_000, 1_000_000_000);
246 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
247 let bob_id = bob.node.get_our_node_id();
248 let charlie_id = charlie.node.get_our_node_id();
250 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
251 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
253 let tor = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
254 announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());
257 .create_offer_builder("coffee".to_string()).unwrap()
258 .amount_msats(10_000_000)
260 assert_ne!(offer.signing_pubkey(), bob_id);
261 assert!(!offer.paths().is_empty());
262 for path in offer.paths() {
263 assert_ne!(path.introduction_node_id, bob_id);
264 assert_ne!(path.introduction_node_id, charlie_id);
267 // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
268 announce_node_address(&nodes[4], &[alice, bob, charlie, david, &nodes[5]], tor.clone());
269 announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
272 .create_offer_builder("coffee".to_string()).unwrap()
273 .amount_msats(10_000_000)
275 assert_ne!(offer.signing_pubkey(), bob_id);
276 assert!(!offer.paths().is_empty());
277 for path in offer.paths() {
278 assert_eq!(path.introduction_node_id, bob_id);
282 /// Checks that blinded paths prefer an introduction node that is the most connected.
284 fn prefers_more_connected_nodes_in_blinded_paths() {
285 let mut accept_forward_cfg = test_default_channel_config();
286 accept_forward_cfg.accept_forwards_to_priv_channels = true;
288 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
289 features.set_onion_messages_optional();
290 features.set_route_blinding_optional();
292 let chanmon_cfgs = create_chanmon_cfgs(6);
293 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
295 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
297 let node_chanmgrs = create_node_chanmgrs(
298 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
300 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
302 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
303 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
304 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
305 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
306 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
307 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
308 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
310 // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
311 // more than the others.
312 create_announced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000_000, 1_000_000_000);
313 create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 10_000_000, 1_000_000_000);
315 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
316 let bob_id = bob.node.get_our_node_id();
318 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
319 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
322 .create_offer_builder("coffee".to_string()).unwrap()
323 .amount_msats(10_000_000)
325 assert_ne!(offer.signing_pubkey(), bob_id);
326 assert!(!offer.paths().is_empty());
327 for path in offer.paths() {
328 assert_eq!(path.introduction_node_id, nodes[4].node.get_our_node_id());
332 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
333 /// rather than exposing a node's pubkey.
335 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
336 let mut accept_forward_cfg = test_default_channel_config();
337 accept_forward_cfg.accept_forwards_to_priv_channels = true;
339 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
340 features.set_onion_messages_optional();
341 features.set_route_blinding_optional();
343 let chanmon_cfgs = create_chanmon_cfgs(6);
344 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
346 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
348 let node_chanmgrs = create_node_chanmgrs(
349 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
351 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
353 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
354 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
355 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
356 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
357 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
358 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
359 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
361 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
362 let alice_id = alice.node.get_our_node_id();
363 let bob_id = bob.node.get_our_node_id();
364 let charlie_id = charlie.node.get_our_node_id();
365 let david_id = david.node.get_our_node_id();
367 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
368 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
370 let offer = alice.node
371 .create_offer_builder("coffee".to_string()).unwrap()
372 .amount_msats(10_000_000)
374 assert_ne!(offer.signing_pubkey(), alice_id);
375 assert!(!offer.paths().is_empty());
376 for path in offer.paths() {
377 assert_eq!(path.introduction_node_id, bob_id);
380 let payment_id = PaymentId([1; 32]);
381 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
383 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
385 connect_peers(david, bob);
387 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
388 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
390 connect_peers(alice, charlie);
392 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
393 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
395 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
396 assert_eq!(invoice_request.amount_msats(), None);
397 assert_ne!(invoice_request.payer_id(), david_id);
398 assert_eq!(reply_path.unwrap().introduction_node_id, charlie_id);
400 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
401 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
403 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
404 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
406 let invoice = extract_invoice(david, &onion_message);
407 assert_eq!(invoice.amount_msats(), 10_000_000);
408 assert_ne!(invoice.signing_pubkey(), alice_id);
409 assert!(!invoice.payment_paths().is_empty());
410 for (_, path) in invoice.payment_paths() {
411 assert_eq!(path.introduction_node_id, bob_id);
414 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
415 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
417 claim_bolt12_payment(david, &[charlie, bob, alice]);
418 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
421 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
422 /// rather than exposing a node's pubkey.
424 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
425 let mut accept_forward_cfg = test_default_channel_config();
426 accept_forward_cfg.accept_forwards_to_priv_channels = true;
428 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
429 features.set_onion_messages_optional();
430 features.set_route_blinding_optional();
432 let chanmon_cfgs = create_chanmon_cfgs(6);
433 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
435 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
437 let node_chanmgrs = create_node_chanmgrs(
438 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
440 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
442 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
443 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
444 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
445 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
446 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
447 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
448 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
450 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
451 let alice_id = alice.node.get_our_node_id();
452 let bob_id = bob.node.get_our_node_id();
453 let charlie_id = charlie.node.get_our_node_id();
454 let david_id = david.node.get_our_node_id();
456 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
457 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
459 let absolute_expiry = Duration::from_secs(u64::MAX);
460 let payment_id = PaymentId([1; 32]);
461 let refund = david.node
462 .create_refund_builder(
463 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
467 assert_eq!(refund.amount_msats(), 10_000_000);
468 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
469 assert_ne!(refund.payer_id(), david_id);
470 assert!(!refund.paths().is_empty());
471 for path in refund.paths() {
472 assert_eq!(path.introduction_node_id, charlie_id);
474 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
476 alice.node.request_refund_payment(&refund).unwrap();
478 connect_peers(alice, charlie);
480 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
481 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
483 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
484 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
486 let invoice = extract_invoice(david, &onion_message);
487 assert_eq!(invoice.amount_msats(), 10_000_000);
488 assert_ne!(invoice.signing_pubkey(), alice_id);
489 assert!(!invoice.payment_paths().is_empty());
490 for (_, path) in invoice.payment_paths() {
491 assert_eq!(path.introduction_node_id, bob_id);
494 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
495 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
497 claim_bolt12_payment(david, &[charlie, bob, alice]);
498 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
501 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
502 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
503 /// introduction node of the blinded path.
505 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
506 let chanmon_cfgs = create_chanmon_cfgs(2);
507 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
508 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
509 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
511 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
513 let alice = &nodes[0];
514 let alice_id = alice.node.get_our_node_id();
516 let bob_id = bob.node.get_our_node_id();
518 let offer = alice.node
519 .create_offer_builder("coffee".to_string()).unwrap()
520 .amount_msats(10_000_000)
522 assert_ne!(offer.signing_pubkey(), alice_id);
523 assert!(!offer.paths().is_empty());
524 for path in offer.paths() {
525 assert_eq!(path.introduction_node_id, alice_id);
528 let payment_id = PaymentId([1; 32]);
529 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
530 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
532 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
533 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
535 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
536 assert_eq!(invoice_request.amount_msats(), None);
537 assert_ne!(invoice_request.payer_id(), bob_id);
538 assert_eq!(reply_path.unwrap().introduction_node_id, bob_id);
540 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
541 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
543 let invoice = extract_invoice(bob, &onion_message);
544 assert_eq!(invoice.amount_msats(), 10_000_000);
545 assert_ne!(invoice.signing_pubkey(), alice_id);
546 assert!(!invoice.payment_paths().is_empty());
547 for (_, path) in invoice.payment_paths() {
548 assert_eq!(path.introduction_node_id, alice_id);
551 route_bolt12_payment(bob, &[alice], &invoice);
552 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
554 claim_bolt12_payment(bob, &[alice]);
555 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
558 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
559 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
560 /// introduction node of the blinded path.
562 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
563 let chanmon_cfgs = create_chanmon_cfgs(2);
564 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
565 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
566 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
568 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
570 let alice = &nodes[0];
571 let alice_id = alice.node.get_our_node_id();
573 let bob_id = bob.node.get_our_node_id();
575 let absolute_expiry = Duration::from_secs(u64::MAX);
576 let payment_id = PaymentId([1; 32]);
577 let refund = bob.node
578 .create_refund_builder(
579 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
583 assert_eq!(refund.amount_msats(), 10_000_000);
584 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
585 assert_ne!(refund.payer_id(), bob_id);
586 assert!(!refund.paths().is_empty());
587 for path in refund.paths() {
588 assert_eq!(path.introduction_node_id, bob_id);
590 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
592 alice.node.request_refund_payment(&refund).unwrap();
594 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
595 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
597 let invoice = extract_invoice(bob, &onion_message);
598 assert_eq!(invoice.amount_msats(), 10_000_000);
599 assert_ne!(invoice.signing_pubkey(), alice_id);
600 assert!(!invoice.payment_paths().is_empty());
601 for (_, path) in invoice.payment_paths() {
602 assert_eq!(path.introduction_node_id, alice_id);
605 route_bolt12_payment(bob, &[alice], &invoice);
606 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
608 claim_bolt12_payment(bob, &[alice]);
609 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
612 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
613 /// the requested is sent directly using the node's pubkey, the response and the payment still use
614 /// blinded paths as required by the spec.
616 fn pays_for_offer_without_blinded_paths() {
617 let chanmon_cfgs = create_chanmon_cfgs(2);
618 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
619 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
620 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
622 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
624 let alice = &nodes[0];
625 let alice_id = alice.node.get_our_node_id();
627 let bob_id = bob.node.get_our_node_id();
629 let offer = alice.node
630 .create_offer_builder("coffee".to_string()).unwrap()
632 .amount_msats(10_000_000)
634 assert_eq!(offer.signing_pubkey(), alice_id);
635 assert!(offer.paths().is_empty());
637 let payment_id = PaymentId([1; 32]);
638 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
639 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
641 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
642 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
644 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
645 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
647 let invoice = extract_invoice(bob, &onion_message);
648 route_bolt12_payment(bob, &[alice], &invoice);
649 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
651 claim_bolt12_payment(bob, &[alice]);
652 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
655 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
656 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
658 fn pays_for_refund_without_blinded_paths() {
659 let chanmon_cfgs = create_chanmon_cfgs(2);
660 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
661 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
662 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
664 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
666 let alice = &nodes[0];
667 let alice_id = alice.node.get_our_node_id();
669 let bob_id = bob.node.get_our_node_id();
671 let absolute_expiry = Duration::from_secs(u64::MAX);
672 let payment_id = PaymentId([1; 32]);
673 let refund = bob.node
674 .create_refund_builder(
675 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
680 assert_eq!(refund.payer_id(), bob_id);
681 assert!(refund.paths().is_empty());
682 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
684 alice.node.request_refund_payment(&refund).unwrap();
686 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
687 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
689 let invoice = extract_invoice(bob, &onion_message);
690 route_bolt12_payment(bob, &[alice], &invoice);
691 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
693 claim_bolt12_payment(bob, &[alice]);
694 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
697 /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
699 fn fails_creating_offer_without_blinded_paths() {
700 let chanmon_cfgs = create_chanmon_cfgs(2);
701 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
702 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
703 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
705 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
707 match nodes[0].node.create_offer_builder("coffee".to_string()) {
708 Ok(_) => panic!("Expected error"),
709 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
713 /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
715 fn fails_creating_refund_without_blinded_paths() {
716 let chanmon_cfgs = create_chanmon_cfgs(2);
717 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
718 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
719 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
721 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
723 let absolute_expiry = Duration::from_secs(u64::MAX);
724 let payment_id = PaymentId([1; 32]);
726 match nodes[0].node.create_refund_builder(
727 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
729 Ok(_) => panic!("Expected error"),
730 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
733 assert!(nodes[0].node.list_recent_payments().is_empty());
736 /// Fails creating an invoice request when the offer contains an unsupported chain.
738 fn fails_creating_invoice_request_for_unsupported_chain() {
739 let chanmon_cfgs = create_chanmon_cfgs(2);
740 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
741 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
742 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
744 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
746 let alice = &nodes[0];
749 let offer = alice.node
750 .create_offer_builder("coffee".to_string()).unwrap()
752 .chain(Network::Signet)
755 let payment_id = PaymentId([1; 32]);
756 match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
757 Ok(_) => panic!("Expected error"),
758 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
762 /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
765 fn fails_creating_invoice_request_without_blinded_reply_path() {
766 let chanmon_cfgs = create_chanmon_cfgs(6);
767 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
768 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
769 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
771 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
772 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
773 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
774 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
775 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
777 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
779 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
780 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
782 let offer = alice.node
783 .create_offer_builder("coffee".to_string()).unwrap()
784 .amount_msats(10_000_000)
787 let payment_id = PaymentId([1; 32]);
789 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
790 Ok(_) => panic!("Expected error"),
791 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
794 assert!(nodes[0].node.list_recent_payments().is_empty());
798 fn fails_creating_invoice_request_with_duplicate_payment_id() {
799 let chanmon_cfgs = create_chanmon_cfgs(6);
800 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
801 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
802 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
804 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
805 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
806 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
807 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
808 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
809 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
810 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
812 let (alice, _bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
814 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
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 david.node.pay_for_offer(
824 &offer, None, None, None, payment_id, Retry::Attempts(0), None
827 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
829 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
830 Ok(_) => panic!("Expected error"),
831 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
834 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
838 fn fails_creating_refund_with_duplicate_payment_id() {
839 let chanmon_cfgs = create_chanmon_cfgs(2);
840 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
841 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
842 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
844 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
846 let absolute_expiry = Duration::from_secs(u64::MAX);
847 let payment_id = PaymentId([1; 32]);
849 nodes[0].node.create_refund_builder(
850 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
853 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
855 match nodes[0].node.create_refund_builder(
856 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
858 Ok(_) => panic!("Expected error"),
859 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
862 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
866 fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
867 let mut accept_forward_cfg = test_default_channel_config();
868 accept_forward_cfg.accept_forwards_to_priv_channels = true;
870 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
871 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
872 features.set_onion_messages_optional();
873 features.clear_route_blinding();
875 let chanmon_cfgs = create_chanmon_cfgs(6);
876 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
878 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
880 let node_chanmgrs = create_node_chanmgrs(
881 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
883 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
885 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
886 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
887 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
888 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
889 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
890 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
891 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
893 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
894 let alice_id = alice.node.get_our_node_id();
895 let bob_id = bob.node.get_our_node_id();
896 let charlie_id = charlie.node.get_our_node_id();
897 let david_id = david.node.get_our_node_id();
899 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
900 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
902 let offer = alice.node
903 .create_offer_builder("coffee".to_string()).unwrap()
904 .amount_msats(10_000_000)
907 let payment_id = PaymentId([1; 32]);
908 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
911 connect_peers(david, bob);
913 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
914 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
916 connect_peers(alice, charlie);
918 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
919 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
921 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
922 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
924 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
925 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
927 let invoice_error = extract_invoice_error(david, &onion_message);
928 assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
932 fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
933 let mut accept_forward_cfg = test_default_channel_config();
934 accept_forward_cfg.accept_forwards_to_priv_channels = true;
936 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
937 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
938 features.set_onion_messages_optional();
939 features.clear_route_blinding();
941 let chanmon_cfgs = create_chanmon_cfgs(6);
942 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
944 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
946 let node_chanmgrs = create_node_chanmgrs(
947 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
949 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
951 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
952 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
953 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
954 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
955 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
956 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
957 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
959 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
961 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
962 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
964 let absolute_expiry = Duration::from_secs(u64::MAX);
965 let payment_id = PaymentId([1; 32]);
966 let refund = david.node
967 .create_refund_builder(
968 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
973 match alice.node.request_refund_payment(&refund) {
974 Ok(_) => panic!("Expected error"),
975 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
980 fn fails_paying_invoice_more_than_once() {
981 let mut accept_forward_cfg = test_default_channel_config();
982 accept_forward_cfg.accept_forwards_to_priv_channels = true;
984 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
985 features.set_onion_messages_optional();
986 features.set_route_blinding_optional();
988 let chanmon_cfgs = create_chanmon_cfgs(6);
989 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
991 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
993 let node_chanmgrs = create_node_chanmgrs(
994 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
996 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
998 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
999 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1000 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1001 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1002 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1003 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1004 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1006 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1007 let alice_id = alice.node.get_our_node_id();
1008 let bob_id = bob.node.get_our_node_id();
1009 let charlie_id = charlie.node.get_our_node_id();
1010 let david_id = david.node.get_our_node_id();
1012 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1013 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1015 let absolute_expiry = Duration::from_secs(u64::MAX);
1016 let payment_id = PaymentId([1; 32]);
1017 let refund = david.node
1018 .create_refund_builder(
1019 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1023 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1025 // Alice sends the first invoice
1026 alice.node.request_refund_payment(&refund).unwrap();
1028 connect_peers(alice, charlie);
1030 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1031 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1033 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1034 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1036 // David pays the first invoice
1037 let invoice1 = extract_invoice(david, &onion_message);
1039 route_bolt12_payment(david, &[charlie, bob, alice], &invoice1);
1040 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
1042 claim_bolt12_payment(david, &[charlie, bob, alice]);
1043 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
1045 disconnect_peers(alice, &[charlie]);
1047 // Alice sends the second invoice
1048 alice.node.request_refund_payment(&refund).unwrap();
1050 connect_peers(alice, charlie);
1051 connect_peers(david, bob);
1053 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1054 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1056 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1057 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1059 let invoice2 = extract_invoice(david, &onion_message);
1060 assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata());
1062 // David sends an error instead of paying the second invoice
1063 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1064 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1066 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1067 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1069 let invoice_error = extract_invoice_error(alice, &onion_message);
1070 assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));