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::Network;
44 use bitcoin::secp256k1::PublicKey;
45 use core::time::Duration;
46 use crate::blinded_path::{BlindedPath, IntroductionNode};
47 use crate::blinded_path::payment::{Bolt12OfferContext, Bolt12RefundContext, PaymentContext};
48 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
49 use crate::ln::channelmanager::{Bolt12PaymentError, MAX_SHORT_LIVED_RELATIVE_EXPIRY, PaymentId, RecentPaymentDetails, Retry, self};
50 use crate::ln::functional_test_utils::*;
51 use crate::ln::msgs::{ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
52 use crate::ln::outbound_payment::IDEMPOTENCY_TIMEOUT_TICKS;
53 use crate::offers::invoice::Bolt12Invoice;
54 use crate::offers::invoice_error::InvoiceError;
55 use crate::offers::invoice_request::{InvoiceRequest, InvoiceRequestFields};
56 use crate::offers::parse::Bolt12SemanticError;
57 use crate::onion_message::messenger::PeeledOnion;
58 use crate::onion_message::offers::OffersMessage;
59 use crate::onion_message::packet::ParsedOnionMessageContents;
60 use crate::routing::gossip::{NodeAlias, NodeId};
61 use crate::sign::{NodeSigner, Recipient};
63 use crate::prelude::*;
65 macro_rules! expect_recent_payment {
66 ($node: expr, $payment_state: path, $payment_id: expr) => {
67 match $node.node.list_recent_payments().first() {
68 Some(&$payment_state { payment_id: actual_payment_id, .. }) => {
69 assert_eq!($payment_id, actual_payment_id);
71 Some(_) => panic!("Unexpected recent payment state"),
72 None => panic!("No recent payments"),
77 fn connect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) {
78 let node_id_a = node_a.node.get_our_node_id();
79 let node_id_b = node_b.node.get_our_node_id();
82 features: node_a.init_features(&node_id_b),
84 remote_network_address: None,
87 features: node_b.init_features(&node_id_a),
89 remote_network_address: None,
92 node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap();
93 node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap();
94 node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap();
95 node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap();
98 fn disconnect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>]) {
100 node_a.node.peer_disconnected(&node_b.node.get_our_node_id());
101 node_b.node.peer_disconnected(&node_a.node.get_our_node_id());
102 node_a.onion_messenger.peer_disconnected(&node_b.node.get_our_node_id());
103 node_b.onion_messenger.peer_disconnected(&node_a.node.get_our_node_id());
107 fn announce_node_address<'a, 'b, 'c>(
108 node: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>], address: SocketAddress,
110 let features = node.onion_messenger.provided_node_features()
111 | node.gossip_sync.provided_node_features();
113 let announcement = UnsignedNodeAnnouncement {
116 node_id: NodeId::from_pubkey(&node.keys_manager.get_node_id(Recipient::Node).unwrap()),
118 alias: NodeAlias([0u8; 32]),
119 addresses: vec![address],
120 excess_address_data: Vec::new(),
121 excess_data: Vec::new(),
123 let signature = node.keys_manager.sign_gossip_message(
124 UnsignedGossipMessage::NodeAnnouncement(&announcement)
127 let msg = NodeAnnouncement {
129 contents: announcement
132 node.gossip_sync.handle_node_announcement(&msg).unwrap();
134 peer.gossip_sync.handle_node_announcement(&msg).unwrap();
138 fn resolve_introduction_node<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &BlindedPath) -> PublicKey {
139 path.public_introduction_node_id(&node.network_graph.read_only())
140 .and_then(|node_id| node_id.as_pubkey().ok())
144 fn route_bolt12_payment<'a, 'b, 'c>(
145 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice
147 // Monitor added when handling the invoice onion message.
148 check_added_monitors(node, 1);
150 let mut events = node.node.get_and_clear_pending_msg_events();
151 assert_eq!(events.len(), 1);
152 let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
154 // Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
155 // invoice contains the payment_hash but it was encrypted inside an onion message.
156 let amount_msats = invoice.amount_msats();
157 let payment_hash = invoice.payment_hash();
158 let args = PassAlongPathArgs::new(node, path, amount_msats, payment_hash, ev)
159 .without_clearing_recipient_events();
160 do_pass_along_path(args);
163 fn claim_bolt12_payment<'a, 'b, 'c>(
164 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], expected_payment_context: PaymentContext
166 let recipient = &path[path.len() - 1];
167 let payment_purpose = match get_event!(recipient, Event::PaymentClaimable) {
168 Event::PaymentClaimable { purpose, .. } => purpose,
169 _ => panic!("No Event::PaymentClaimable"),
171 let payment_preimage = match payment_purpose.preimage() {
172 Some(preimage) => preimage,
173 None => panic!("No preimage in Event::PaymentClaimable"),
175 match payment_purpose {
176 PaymentPurpose::Bolt12OfferPayment { payment_context, .. } => {
177 assert_eq!(PaymentContext::Bolt12Offer(payment_context), expected_payment_context);
179 PaymentPurpose::Bolt12RefundPayment { payment_context, .. } => {
180 assert_eq!(PaymentContext::Bolt12Refund(payment_context), expected_payment_context);
182 _ => panic!("Unexpected payment purpose: {:?}", payment_purpose),
184 claim_payment(node, path, payment_preimage);
187 fn extract_invoice_request<'a, 'b, 'c>(
188 node: &Node<'a, 'b, 'c>, message: &OnionMessage
189 ) -> (InvoiceRequest, BlindedPath) {
190 match node.onion_messenger.peel_onion_message(message) {
191 Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
192 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
193 OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path.unwrap()),
194 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
195 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
197 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
199 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
200 Err(e) => panic!("Failed to process onion message {:?}", e),
204 fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
205 match node.onion_messenger.peel_onion_message(message) {
206 Ok(PeeledOnion::Receive(message, _, _)) => match message {
207 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
208 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
209 OffersMessage::Invoice(invoice) => invoice,
210 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
212 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
214 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
215 Err(e) => panic!("Failed to process onion message {:?}", e),
219 fn extract_invoice_error<'a, 'b, 'c>(
220 node: &Node<'a, 'b, 'c>, message: &OnionMessage
222 match node.onion_messenger.peel_onion_message(message) {
223 Ok(PeeledOnion::Receive(message, _, _)) => match message {
224 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
225 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
226 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
227 OffersMessage::InvoiceError(error) => error,
229 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
231 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
232 Err(e) => panic!("Failed to process onion message {:?}", e),
236 /// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
238 fn prefers_non_tor_nodes_in_blinded_paths() {
239 let mut accept_forward_cfg = test_default_channel_config();
240 accept_forward_cfg.accept_forwards_to_priv_channels = true;
242 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
243 features.set_onion_messages_optional();
244 features.set_route_blinding_optional();
246 let chanmon_cfgs = create_chanmon_cfgs(6);
247 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
249 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
251 let node_chanmgrs = create_node_chanmgrs(
252 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
254 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
256 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
257 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
258 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
259 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
260 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
261 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
262 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
264 // Add an extra channel so that more than one of Bob's peers have MIN_PEER_CHANNELS.
265 create_announced_chan_between_nodes_with_value(&nodes, 4, 5, 10_000_000, 1_000_000_000);
267 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
268 let bob_id = bob.node.get_our_node_id();
269 let charlie_id = charlie.node.get_our_node_id();
271 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
272 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
274 let tor = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
275 announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor.clone());
278 .create_offer_builder(None).unwrap()
279 .amount_msats(10_000_000)
281 assert_ne!(offer.signing_pubkey(), Some(bob_id));
282 assert!(!offer.paths().is_empty());
283 for path in offer.paths() {
284 let introduction_node_id = resolve_introduction_node(david, &path);
285 assert_ne!(introduction_node_id, bob_id);
286 assert_ne!(introduction_node_id, charlie_id);
289 // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
290 announce_node_address(&nodes[4], &[alice, bob, charlie, david, &nodes[5]], tor.clone());
291 announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
294 .create_offer_builder(None).unwrap()
295 .amount_msats(10_000_000)
297 assert_ne!(offer.signing_pubkey(), Some(bob_id));
298 assert!(!offer.paths().is_empty());
299 for path in offer.paths() {
300 let introduction_node_id = resolve_introduction_node(david, &path);
301 assert_eq!(introduction_node_id, bob_id);
305 /// Checks that blinded paths prefer an introduction node that is the most connected.
307 fn prefers_more_connected_nodes_in_blinded_paths() {
308 let mut accept_forward_cfg = test_default_channel_config();
309 accept_forward_cfg.accept_forwards_to_priv_channels = true;
311 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
312 features.set_onion_messages_optional();
313 features.set_route_blinding_optional();
315 let chanmon_cfgs = create_chanmon_cfgs(6);
316 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
318 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
320 let node_chanmgrs = create_node_chanmgrs(
321 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
323 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
325 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
326 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
327 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
328 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
329 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
330 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
331 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
333 // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
334 // more than the others.
335 create_announced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000_000, 1_000_000_000);
336 create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 10_000_000, 1_000_000_000);
338 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
339 let bob_id = bob.node.get_our_node_id();
341 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
342 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
345 .create_offer_builder(None).unwrap()
346 .amount_msats(10_000_000)
348 assert_ne!(offer.signing_pubkey(), Some(bob_id));
349 assert!(!offer.paths().is_empty());
350 for path in offer.paths() {
351 let introduction_node_id = resolve_introduction_node(david, &path);
352 assert_eq!(introduction_node_id, nodes[4].node.get_our_node_id());
356 /// Checks that blinded paths are compact for short-lived offers.
358 fn creates_short_lived_offer() {
359 let chanmon_cfgs = create_chanmon_cfgs(2);
360 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
361 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
362 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
364 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
366 let alice = &nodes[0];
367 let alice_id = alice.node.get_our_node_id();
370 let absolute_expiry = alice.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY;
371 let offer = alice.node
372 .create_offer_builder(Some(absolute_expiry)).unwrap()
374 assert_eq!(offer.absolute_expiry(), Some(absolute_expiry));
375 assert!(!offer.paths().is_empty());
376 for path in offer.paths() {
377 let introduction_node_id = resolve_introduction_node(bob, &path);
378 assert_eq!(introduction_node_id, alice_id);
379 assert!(matches!(path.introduction_node, IntroductionNode::DirectedShortChannelId(..)));
383 /// Checks that blinded paths are not compact for long-lived offers.
385 fn creates_long_lived_offer() {
386 let chanmon_cfgs = create_chanmon_cfgs(2);
387 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
388 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
389 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
391 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
393 let alice = &nodes[0];
394 let alice_id = alice.node.get_our_node_id();
396 let absolute_expiry = alice.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY
397 + Duration::from_secs(1);
398 let offer = alice.node
399 .create_offer_builder(Some(absolute_expiry))
402 assert_eq!(offer.absolute_expiry(), Some(absolute_expiry));
403 assert!(!offer.paths().is_empty());
404 for path in offer.paths() {
405 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
408 let offer = alice.node
409 .create_offer_builder(None).unwrap()
411 assert_eq!(offer.absolute_expiry(), None);
412 assert!(!offer.paths().is_empty());
413 for path in offer.paths() {
414 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
418 /// Checks that blinded paths are compact for short-lived refunds.
420 fn creates_short_lived_refund() {
421 let chanmon_cfgs = create_chanmon_cfgs(2);
422 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
423 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
424 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
426 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
428 let alice = &nodes[0];
430 let bob_id = bob.node.get_our_node_id();
432 let absolute_expiry = bob.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY;
433 let payment_id = PaymentId([1; 32]);
434 let refund = bob.node
435 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
438 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
439 assert!(!refund.paths().is_empty());
440 for path in refund.paths() {
441 let introduction_node_id = resolve_introduction_node(alice, &path);
442 assert_eq!(introduction_node_id, bob_id);
443 assert!(matches!(path.introduction_node, IntroductionNode::DirectedShortChannelId(..)));
447 /// Checks that blinded paths are not compact for long-lived refunds.
449 fn creates_long_lived_refund() {
450 let chanmon_cfgs = create_chanmon_cfgs(2);
451 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
452 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
453 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
455 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
458 let bob_id = bob.node.get_our_node_id();
460 let absolute_expiry = bob.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY
461 + Duration::from_secs(1);
462 let payment_id = PaymentId([1; 32]);
463 let refund = bob.node
464 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
467 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
468 assert!(!refund.paths().is_empty());
469 for path in refund.paths() {
470 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
474 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
475 /// rather than exposing a node's pubkey.
477 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
478 let mut accept_forward_cfg = test_default_channel_config();
479 accept_forward_cfg.accept_forwards_to_priv_channels = true;
481 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
482 features.set_onion_messages_optional();
483 features.set_route_blinding_optional();
485 let chanmon_cfgs = create_chanmon_cfgs(6);
486 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
488 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
490 let node_chanmgrs = create_node_chanmgrs(
491 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
493 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
495 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
496 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
497 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
498 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
499 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
500 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
501 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
503 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
504 let alice_id = alice.node.get_our_node_id();
505 let bob_id = bob.node.get_our_node_id();
506 let charlie_id = charlie.node.get_our_node_id();
507 let david_id = david.node.get_our_node_id();
509 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
510 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
512 let offer = alice.node
513 .create_offer_builder(None)
515 .amount_msats(10_000_000)
517 assert_ne!(offer.signing_pubkey(), Some(alice_id));
518 assert!(!offer.paths().is_empty());
519 for path in offer.paths() {
520 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
523 let payment_id = PaymentId([1; 32]);
524 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
526 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
528 connect_peers(david, bob);
530 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
531 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
533 connect_peers(alice, charlie);
535 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
536 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
538 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
539 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
540 offer_id: offer.id(),
541 invoice_request: InvoiceRequestFields {
542 payer_id: invoice_request.payer_id(),
544 payer_note_truncated: None,
547 assert_eq!(invoice_request.amount_msats(), None);
548 assert_ne!(invoice_request.payer_id(), david_id);
549 assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(charlie_id));
551 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
552 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
554 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
555 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
557 let invoice = extract_invoice(david, &onion_message);
558 assert_eq!(invoice.amount_msats(), 10_000_000);
559 assert_ne!(invoice.signing_pubkey(), alice_id);
560 assert!(!invoice.payment_paths().is_empty());
561 for (_, path) in invoice.payment_paths() {
562 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
565 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
566 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
568 claim_bolt12_payment(david, &[charlie, bob, alice], payment_context);
569 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
572 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
573 /// rather than exposing a node's pubkey.
575 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
576 let mut accept_forward_cfg = test_default_channel_config();
577 accept_forward_cfg.accept_forwards_to_priv_channels = true;
579 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
580 features.set_onion_messages_optional();
581 features.set_route_blinding_optional();
583 let chanmon_cfgs = create_chanmon_cfgs(6);
584 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
586 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
588 let node_chanmgrs = create_node_chanmgrs(
589 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
591 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
593 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
594 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
595 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
596 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
597 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
598 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
599 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
601 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
602 let alice_id = alice.node.get_our_node_id();
603 let bob_id = bob.node.get_our_node_id();
604 let charlie_id = charlie.node.get_our_node_id();
605 let david_id = david.node.get_our_node_id();
607 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
608 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
610 let absolute_expiry = Duration::from_secs(u64::MAX);
611 let payment_id = PaymentId([1; 32]);
612 let refund = david.node
613 .create_refund_builder(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(), david_id);
619 assert!(!refund.paths().is_empty());
620 for path in refund.paths() {
621 assert_eq!(path.introduction_node, IntroductionNode::NodeId(charlie_id));
623 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
625 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
626 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
628 connect_peers(alice, charlie);
630 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
631 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
633 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
634 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
636 let invoice = extract_invoice(david, &onion_message);
637 assert_eq!(invoice, expected_invoice);
639 assert_eq!(invoice.amount_msats(), 10_000_000);
640 assert_ne!(invoice.signing_pubkey(), alice_id);
641 assert!(!invoice.payment_paths().is_empty());
642 for (_, path) in invoice.payment_paths() {
643 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
646 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
647 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
649 claim_bolt12_payment(david, &[charlie, bob, alice], payment_context);
650 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
653 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
654 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
655 /// introduction node of the blinded path.
657 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
658 let chanmon_cfgs = create_chanmon_cfgs(2);
659 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
660 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
661 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
663 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
665 let alice = &nodes[0];
666 let alice_id = alice.node.get_our_node_id();
668 let bob_id = bob.node.get_our_node_id();
670 let offer = alice.node
671 .create_offer_builder(None).unwrap()
672 .amount_msats(10_000_000)
674 assert_ne!(offer.signing_pubkey(), Some(alice_id));
675 assert!(!offer.paths().is_empty());
676 for path in offer.paths() {
677 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
680 let payment_id = PaymentId([1; 32]);
681 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
682 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
684 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
685 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
687 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
688 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
689 offer_id: offer.id(),
690 invoice_request: InvoiceRequestFields {
691 payer_id: invoice_request.payer_id(),
693 payer_note_truncated: None,
696 assert_eq!(invoice_request.amount_msats(), None);
697 assert_ne!(invoice_request.payer_id(), bob_id);
698 assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(bob_id));
700 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
701 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
703 let invoice = extract_invoice(bob, &onion_message);
704 assert_eq!(invoice.amount_msats(), 10_000_000);
705 assert_ne!(invoice.signing_pubkey(), alice_id);
706 assert!(!invoice.payment_paths().is_empty());
707 for (_, path) in invoice.payment_paths() {
708 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
711 route_bolt12_payment(bob, &[alice], &invoice);
712 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
714 claim_bolt12_payment(bob, &[alice], payment_context);
715 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
718 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
719 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
720 /// introduction node of the blinded path.
722 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
723 let chanmon_cfgs = create_chanmon_cfgs(2);
724 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
725 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
726 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
728 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
730 let alice = &nodes[0];
731 let alice_id = alice.node.get_our_node_id();
733 let bob_id = bob.node.get_our_node_id();
735 let absolute_expiry = Duration::from_secs(u64::MAX);
736 let payment_id = PaymentId([1; 32]);
737 let refund = bob.node
738 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
741 assert_eq!(refund.amount_msats(), 10_000_000);
742 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
743 assert_ne!(refund.payer_id(), bob_id);
744 assert!(!refund.paths().is_empty());
745 for path in refund.paths() {
746 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
748 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
750 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
751 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
753 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
754 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
756 let invoice = extract_invoice(bob, &onion_message);
757 assert_eq!(invoice, expected_invoice);
759 assert_eq!(invoice.amount_msats(), 10_000_000);
760 assert_ne!(invoice.signing_pubkey(), alice_id);
761 assert!(!invoice.payment_paths().is_empty());
762 for (_, path) in invoice.payment_paths() {
763 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
766 route_bolt12_payment(bob, &[alice], &invoice);
767 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
769 claim_bolt12_payment(bob, &[alice], payment_context);
770 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
773 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
774 /// the requested is sent directly using the node's pubkey, the response and the payment still use
775 /// blinded paths as required by the spec.
777 fn pays_for_offer_without_blinded_paths() {
778 let chanmon_cfgs = create_chanmon_cfgs(2);
779 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
780 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
781 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
783 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
785 let alice = &nodes[0];
786 let alice_id = alice.node.get_our_node_id();
788 let bob_id = bob.node.get_our_node_id();
790 let offer = alice.node
791 .create_offer_builder(None).unwrap()
793 .amount_msats(10_000_000)
795 assert_eq!(offer.signing_pubkey(), Some(alice_id));
796 assert!(offer.paths().is_empty());
798 let payment_id = PaymentId([1; 32]);
799 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
800 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
802 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
803 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
805 let (invoice_request, _) = extract_invoice_request(alice, &onion_message);
806 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
807 offer_id: offer.id(),
808 invoice_request: InvoiceRequestFields {
809 payer_id: invoice_request.payer_id(),
811 payer_note_truncated: None,
815 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
816 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
818 let invoice = extract_invoice(bob, &onion_message);
819 route_bolt12_payment(bob, &[alice], &invoice);
820 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
822 claim_bolt12_payment(bob, &[alice], payment_context);
823 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
826 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
827 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
829 fn pays_for_refund_without_blinded_paths() {
830 let chanmon_cfgs = create_chanmon_cfgs(2);
831 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
832 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
833 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
835 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
837 let alice = &nodes[0];
838 let alice_id = alice.node.get_our_node_id();
840 let bob_id = bob.node.get_our_node_id();
842 let absolute_expiry = Duration::from_secs(u64::MAX);
843 let payment_id = PaymentId([1; 32]);
844 let refund = bob.node
845 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
849 assert_eq!(refund.payer_id(), bob_id);
850 assert!(refund.paths().is_empty());
851 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
853 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
854 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
856 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
857 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
859 let invoice = extract_invoice(bob, &onion_message);
860 assert_eq!(invoice, expected_invoice);
862 route_bolt12_payment(bob, &[alice], &invoice);
863 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
865 claim_bolt12_payment(bob, &[alice], payment_context);
866 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
869 /// Checks that a deferred invoice can be paid asynchronously from an Event::InvoiceReceived.
871 fn pays_bolt12_invoice_asynchronously() {
872 let mut manually_pay_cfg = test_default_channel_config();
873 manually_pay_cfg.manually_handle_bolt12_invoices = true;
875 let chanmon_cfgs = create_chanmon_cfgs(2);
876 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
877 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, Some(manually_pay_cfg)]);
878 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
880 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
882 let alice = &nodes[0];
883 let alice_id = alice.node.get_our_node_id();
885 let bob_id = bob.node.get_our_node_id();
887 let offer = alice.node
888 .create_offer_builder(None).unwrap()
889 .amount_msats(10_000_000)
892 let payment_id = PaymentId([1; 32]);
893 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
894 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
896 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
897 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
899 let (invoice_request, _) = extract_invoice_request(alice, &onion_message);
900 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
901 offer_id: offer.id(),
902 invoice_request: InvoiceRequestFields {
903 payer_id: invoice_request.payer_id(),
905 payer_note_truncated: None,
909 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
910 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
912 let invoice = match get_event!(bob, Event::InvoiceReceived) {
913 Event::InvoiceReceived { payment_id: actual_payment_id, invoice, .. } => {
914 assert_eq!(actual_payment_id, payment_id);
917 _ => panic!("No Event::InvoiceReceived"),
919 assert_eq!(invoice.amount_msats(), 10_000_000);
920 assert_ne!(invoice.signing_pubkey(), alice_id);
921 assert!(!invoice.payment_paths().is_empty());
922 for (_, path) in invoice.payment_paths() {
923 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
926 assert!(bob.node.send_payment_for_bolt12_invoice(&invoice).is_ok());
928 bob.node.send_payment_for_bolt12_invoice(&invoice),
929 Err(Bolt12PaymentError::DuplicateInvoice),
932 route_bolt12_payment(bob, &[alice], &invoice);
933 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
935 claim_bolt12_payment(bob, &[alice], payment_context);
936 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
939 bob.node.send_payment_for_bolt12_invoice(&invoice),
940 Err(Bolt12PaymentError::DuplicateInvoice),
943 for _ in 0..=IDEMPOTENCY_TIMEOUT_TICKS {
944 bob.node.timer_tick_occurred();
948 bob.node.send_payment_for_bolt12_invoice(&invoice),
949 Err(Bolt12PaymentError::UnexpectedInvoice),
953 /// Checks that an offer can be created using an unannounced node as a blinded path's introduction
954 /// node. This is only preferred if there are no other options which may indicated either the offer
955 /// is intended for the unannounced node or that the node is actually announced (e.g., an LSP) but
956 /// the recipient doesn't have a network graph.
958 fn creates_offer_with_blinded_path_using_unannounced_introduction_node() {
959 let chanmon_cfgs = create_chanmon_cfgs(2);
960 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
961 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
962 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
964 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
966 let alice = &nodes[0];
967 let alice_id = alice.node.get_our_node_id();
969 let bob_id = bob.node.get_our_node_id();
971 let offer = alice.node
972 .create_offer_builder(None).unwrap()
973 .amount_msats(10_000_000)
975 assert_ne!(offer.signing_pubkey(), Some(alice_id));
976 assert!(!offer.paths().is_empty());
977 for path in offer.paths() {
978 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
981 let payment_id = PaymentId([1; 32]);
982 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
983 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
985 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
986 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
988 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
989 let payment_context = PaymentContext::Bolt12Offer(Bolt12OfferContext {
990 offer_id: offer.id(),
991 invoice_request: InvoiceRequestFields {
992 payer_id: invoice_request.payer_id(),
994 payer_note_truncated: None,
997 assert_ne!(invoice_request.payer_id(), bob_id);
998 assert_eq!(reply_path.introduction_node, IntroductionNode::NodeId(alice_id));
1000 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1001 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1003 let invoice = extract_invoice(bob, &onion_message);
1004 assert_ne!(invoice.signing_pubkey(), alice_id);
1005 assert!(!invoice.payment_paths().is_empty());
1006 for (_, path) in invoice.payment_paths() {
1007 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
1010 route_bolt12_payment(bob, &[alice], &invoice);
1011 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
1013 claim_bolt12_payment(bob, &[alice], payment_context);
1014 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
1017 /// Checks that a refund can be created using an unannounced node as a blinded path's introduction
1018 /// node. This is only preferred if there are no other options which may indicated either the refund
1019 /// is intended for the unannounced node or that the node is actually announced (e.g., an LSP) but
1020 /// the sender doesn't have a network graph.
1022 fn creates_refund_with_blinded_path_using_unannounced_introduction_node() {
1023 let chanmon_cfgs = create_chanmon_cfgs(2);
1024 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1025 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
1026 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1028 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1030 let alice = &nodes[0];
1031 let alice_id = alice.node.get_our_node_id();
1032 let bob = &nodes[1];
1033 let bob_id = bob.node.get_our_node_id();
1035 let absolute_expiry = Duration::from_secs(u64::MAX);
1036 let payment_id = PaymentId([1; 32]);
1037 let refund = bob.node
1038 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
1041 assert_ne!(refund.payer_id(), bob_id);
1042 assert!(!refund.paths().is_empty());
1043 for path in refund.paths() {
1044 assert_eq!(path.introduction_node, IntroductionNode::NodeId(alice_id));
1046 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
1048 let expected_invoice = alice.node.request_refund_payment(&refund).unwrap();
1050 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1052 let invoice = extract_invoice(bob, &onion_message);
1053 assert_eq!(invoice, expected_invoice);
1054 assert_ne!(invoice.signing_pubkey(), alice_id);
1055 assert!(!invoice.payment_paths().is_empty());
1056 for (_, path) in invoice.payment_paths() {
1057 assert_eq!(path.introduction_node, IntroductionNode::NodeId(bob_id));
1061 /// Fails creating or paying an offer when a blinded path cannot be created because no peers are
1064 fn fails_creating_or_paying_for_offer_without_connected_peers() {
1065 let chanmon_cfgs = create_chanmon_cfgs(6);
1066 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1067 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
1068 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1070 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1071 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1072 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1073 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1074 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1075 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1076 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1078 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1080 disconnect_peers(alice, &[bob, charlie, david, &nodes[4], &nodes[5]]);
1081 disconnect_peers(david, &[bob, charlie, &nodes[4], &nodes[5]]);
1083 let absolute_expiry = alice.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY;
1084 match alice.node.create_offer_builder(Some(absolute_expiry)) {
1085 Ok(_) => panic!("Expected error"),
1086 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1089 let mut args = ReconnectArgs::new(alice, bob);
1090 args.send_channel_ready = (true, true);
1091 reconnect_nodes(args);
1093 let offer = alice.node
1094 .create_offer_builder(Some(absolute_expiry)).unwrap()
1095 .amount_msats(10_000_000)
1098 let payment_id = PaymentId([1; 32]);
1100 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
1101 Ok(_) => panic!("Expected error"),
1102 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1105 assert!(nodes[0].node.list_recent_payments().is_empty());
1107 let mut args = ReconnectArgs::new(charlie, david);
1108 args.send_channel_ready = (true, true);
1109 reconnect_nodes(args);
1112 david.node.pay_for_offer(
1113 &offer, None, None, None, payment_id, Retry::Attempts(0), None
1117 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1120 /// Fails creating or sending an invoice for a refund when a blinded path cannot be created because
1121 /// no peers are connected.
1123 fn fails_creating_refund_or_sending_invoice_without_connected_peers() {
1124 let mut accept_forward_cfg = test_default_channel_config();
1125 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1127 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1128 features.set_onion_messages_optional();
1129 features.set_route_blinding_optional();
1131 let chanmon_cfgs = create_chanmon_cfgs(6);
1132 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1134 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1136 let node_chanmgrs = create_node_chanmgrs(
1137 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1139 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1141 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1142 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1143 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1144 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1145 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1146 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1147 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1149 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1151 disconnect_peers(alice, &[bob, charlie, david, &nodes[4], &nodes[5]]);
1152 disconnect_peers(david, &[bob, charlie, &nodes[4], &nodes[5]]);
1154 let absolute_expiry = david.node.duration_since_epoch() + MAX_SHORT_LIVED_RELATIVE_EXPIRY;
1155 let payment_id = PaymentId([1; 32]);
1156 match david.node.create_refund_builder(
1157 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1159 Ok(_) => panic!("Expected error"),
1160 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1163 let mut args = ReconnectArgs::new(charlie, david);
1164 args.send_channel_ready = (true, true);
1165 reconnect_nodes(args);
1167 let refund = david.node
1168 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
1172 match alice.node.request_refund_payment(&refund) {
1173 Ok(_) => panic!("Expected error"),
1174 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1177 let mut args = ReconnectArgs::new(alice, bob);
1178 args.send_channel_ready = (true, true);
1179 reconnect_nodes(args);
1181 assert!(alice.node.request_refund_payment(&refund).is_ok());
1184 /// Fails creating an invoice request when the offer contains an unsupported chain.
1186 fn fails_creating_invoice_request_for_unsupported_chain() {
1187 let chanmon_cfgs = create_chanmon_cfgs(2);
1188 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1189 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
1190 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1192 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1194 let alice = &nodes[0];
1195 let bob = &nodes[1];
1197 let offer = alice.node
1198 .create_offer_builder(None).unwrap()
1200 .chain(Network::Signet)
1203 let payment_id = PaymentId([1; 32]);
1204 match bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
1205 Ok(_) => panic!("Expected error"),
1206 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
1210 /// Fails requesting a payment when the refund contains an unsupported chain.
1212 fn fails_sending_invoice_with_unsupported_chain_for_refund() {
1213 let chanmon_cfgs = create_chanmon_cfgs(2);
1214 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1215 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
1216 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1218 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1220 let alice = &nodes[0];
1221 let bob = &nodes[1];
1223 let absolute_expiry = Duration::from_secs(u64::MAX);
1224 let payment_id = PaymentId([1; 32]);
1225 let refund = bob.node
1226 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
1228 .chain(Network::Signet)
1231 match alice.node.request_refund_payment(&refund) {
1232 Ok(_) => panic!("Expected error"),
1233 Err(e) => assert_eq!(e, Bolt12SemanticError::UnsupportedChain),
1237 /// Fails creating an invoice request when a blinded reply path cannot be created.
1239 fn fails_creating_invoice_request_without_blinded_reply_path() {
1240 let chanmon_cfgs = create_chanmon_cfgs(6);
1241 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1242 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
1243 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1245 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1246 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1247 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1248 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1249 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1251 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1253 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1254 disconnect_peers(david, &[bob, charlie, &nodes[4], &nodes[5]]);
1256 let offer = alice.node
1257 .create_offer_builder(None).unwrap()
1258 .amount_msats(10_000_000)
1261 let payment_id = PaymentId([1; 32]);
1263 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
1264 Ok(_) => panic!("Expected error"),
1265 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1268 assert!(nodes[0].node.list_recent_payments().is_empty());
1272 fn fails_creating_invoice_request_with_duplicate_payment_id() {
1273 let chanmon_cfgs = create_chanmon_cfgs(6);
1274 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1275 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
1276 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1278 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1279 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1280 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1281 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1282 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1283 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1284 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1286 let (alice, _bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1288 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1290 let offer = alice.node
1291 .create_offer_builder(None).unwrap()
1292 .amount_msats(10_000_000)
1295 let payment_id = PaymentId([1; 32]);
1297 david.node.pay_for_offer(
1298 &offer, None, None, None, payment_id, Retry::Attempts(0), None
1301 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1303 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
1304 Ok(_) => panic!("Expected error"),
1305 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
1308 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1312 fn fails_creating_refund_with_duplicate_payment_id() {
1313 let chanmon_cfgs = create_chanmon_cfgs(2);
1314 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1315 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
1316 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1318 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1320 let absolute_expiry = Duration::from_secs(u64::MAX);
1321 let payment_id = PaymentId([1; 32]);
1323 nodes[0].node.create_refund_builder(
1324 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1327 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
1329 match nodes[0].node.create_refund_builder(
1330 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
1332 Ok(_) => panic!("Expected error"),
1333 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
1336 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
1340 fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
1341 let mut accept_forward_cfg = test_default_channel_config();
1342 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1344 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
1345 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1346 features.set_onion_messages_optional();
1347 features.clear_route_blinding();
1349 let chanmon_cfgs = create_chanmon_cfgs(6);
1350 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1352 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1354 let node_chanmgrs = create_node_chanmgrs(
1355 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1357 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1359 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1360 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1361 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1362 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1363 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1364 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1365 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1367 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1368 let alice_id = alice.node.get_our_node_id();
1369 let bob_id = bob.node.get_our_node_id();
1370 let charlie_id = charlie.node.get_our_node_id();
1371 let david_id = david.node.get_our_node_id();
1373 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1374 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1376 let offer = alice.node
1377 .create_offer_builder(None).unwrap()
1378 .amount_msats(10_000_000)
1381 let payment_id = PaymentId([1; 32]);
1382 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
1385 connect_peers(david, bob);
1387 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1388 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1390 connect_peers(alice, charlie);
1392 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1393 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1395 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1396 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1398 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1399 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1401 let invoice_error = extract_invoice_error(david, &onion_message);
1402 assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
1406 fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
1407 let mut accept_forward_cfg = test_default_channel_config();
1408 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1410 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
1411 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1412 features.set_onion_messages_optional();
1413 features.clear_route_blinding();
1415 let chanmon_cfgs = create_chanmon_cfgs(6);
1416 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1418 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1420 let node_chanmgrs = create_node_chanmgrs(
1421 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1423 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1425 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1426 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1427 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1428 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1429 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1430 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1431 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1433 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1435 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1436 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1438 let absolute_expiry = Duration::from_secs(u64::MAX);
1439 let payment_id = PaymentId([1; 32]);
1440 let refund = david.node
1441 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
1445 match alice.node.request_refund_payment(&refund) {
1446 Ok(_) => panic!("Expected error"),
1447 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
1452 fn fails_paying_invoice_more_than_once() {
1453 let mut accept_forward_cfg = test_default_channel_config();
1454 accept_forward_cfg.accept_forwards_to_priv_channels = true;
1456 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
1457 features.set_onion_messages_optional();
1458 features.set_route_blinding_optional();
1460 let chanmon_cfgs = create_chanmon_cfgs(6);
1461 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
1463 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
1465 let node_chanmgrs = create_node_chanmgrs(
1466 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
1468 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
1470 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
1471 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
1472 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
1473 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
1474 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
1475 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
1476 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
1478 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
1479 let alice_id = alice.node.get_our_node_id();
1480 let bob_id = bob.node.get_our_node_id();
1481 let charlie_id = charlie.node.get_our_node_id();
1482 let david_id = david.node.get_our_node_id();
1484 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
1485 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
1487 let absolute_expiry = Duration::from_secs(u64::MAX);
1488 let payment_id = PaymentId([1; 32]);
1489 let refund = david.node
1490 .create_refund_builder(10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None)
1493 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
1495 // Alice sends the first invoice
1496 alice.node.request_refund_payment(&refund).unwrap();
1498 connect_peers(alice, charlie);
1500 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1501 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1503 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1504 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1506 // David pays the first invoice
1507 let payment_context = PaymentContext::Bolt12Refund(Bolt12RefundContext {});
1508 let invoice1 = extract_invoice(david, &onion_message);
1510 route_bolt12_payment(david, &[charlie, bob, alice], &invoice1);
1511 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
1513 claim_bolt12_payment(david, &[charlie, bob, alice], payment_context);
1514 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
1516 disconnect_peers(alice, &[charlie]);
1518 // Alice sends the second invoice
1519 alice.node.request_refund_payment(&refund).unwrap();
1521 connect_peers(alice, charlie);
1522 connect_peers(david, bob);
1524 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1525 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1527 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1528 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1530 let invoice2 = extract_invoice(david, &onion_message);
1531 assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata());
1533 // David sends an error instead of paying the second invoice
1534 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1535 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1537 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1538 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1540 let invoice_error = extract_invoice_error(alice, &onion_message);
1541 assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));