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 core::time::Duration;
44 use crate::blinded_path::BlindedPath;
45 use crate::events::{Event, MessageSendEventsProvider, PaymentPurpose};
46 use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
47 use crate::ln::functional_test_utils::*;
48 use crate::ln::msgs::{ChannelMessageHandler, Init, NodeAnnouncement, OnionMessage, OnionMessageHandler, RoutingMessageHandler, SocketAddress, UnsignedGossipMessage, UnsignedNodeAnnouncement};
49 use crate::offers::invoice::Bolt12Invoice;
50 use crate::offers::invoice_error::InvoiceError;
51 use crate::offers::invoice_request::InvoiceRequest;
52 use crate::offers::parse::Bolt12SemanticError;
53 use crate::onion_message::messenger::PeeledOnion;
54 use crate::onion_message::offers::OffersMessage;
55 use crate::onion_message::packet::ParsedOnionMessageContents;
56 use crate::routing::gossip::{NodeAlias, NodeId};
57 use crate::sign::{NodeSigner, Recipient};
59 use crate::prelude::*;
61 macro_rules! expect_recent_payment {
62 ($node: expr, $payment_state: path, $payment_id: expr) => {
63 match $node.node.list_recent_payments().first() {
64 Some(&$payment_state { payment_id: actual_payment_id, .. }) => {
65 assert_eq!($payment_id, actual_payment_id);
67 Some(_) => panic!("Unexpected recent payment state"),
68 None => panic!("No recent payments"),
73 fn connect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, node_b: &Node<'a, 'b, 'c>) {
74 let node_id_a = node_a.node.get_our_node_id();
75 let node_id_b = node_b.node.get_our_node_id();
78 features: node_a.init_features(&node_id_b),
80 remote_network_address: None,
83 features: node_b.init_features(&node_id_a),
85 remote_network_address: None,
88 node_a.node.peer_connected(&node_id_b, &init_b, true).unwrap();
89 node_b.node.peer_connected(&node_id_a, &init_a, false).unwrap();
90 node_a.onion_messenger.peer_connected(&node_id_b, &init_b, true).unwrap();
91 node_b.onion_messenger.peer_connected(&node_id_a, &init_a, false).unwrap();
94 fn disconnect_peers<'a, 'b, 'c>(node_a: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>]) {
96 node_a.node.peer_disconnected(&node_b.node.get_our_node_id());
97 node_b.node.peer_disconnected(&node_a.node.get_our_node_id());
98 node_a.onion_messenger.peer_disconnected(&node_b.node.get_our_node_id());
99 node_b.onion_messenger.peer_disconnected(&node_a.node.get_our_node_id());
103 fn announce_node_address<'a, 'b, 'c>(
104 node: &Node<'a, 'b, 'c>, peers: &[&Node<'a, 'b, 'c>], address: SocketAddress,
106 let features = node.onion_messenger.provided_node_features()
107 | node.gossip_sync.provided_node_features();
109 let announcement = UnsignedNodeAnnouncement {
112 node_id: NodeId::from_pubkey(&node.keys_manager.get_node_id(Recipient::Node).unwrap()),
114 alias: NodeAlias([0u8; 32]),
115 addresses: vec![address],
116 excess_address_data: Vec::new(),
117 excess_data: Vec::new(),
119 let signature = node.keys_manager.sign_gossip_message(
120 UnsignedGossipMessage::NodeAnnouncement(&announcement)
123 let msg = NodeAnnouncement {
125 contents: announcement
128 node.gossip_sync.handle_node_announcement(&msg).unwrap();
130 peer.gossip_sync.handle_node_announcement(&msg).unwrap();
134 fn route_bolt12_payment<'a, 'b, 'c>(
135 node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>], invoice: &Bolt12Invoice
137 // Monitor added when handling the invoice onion message.
138 check_added_monitors(node, 1);
140 let mut events = node.node.get_and_clear_pending_msg_events();
141 assert_eq!(events.len(), 1);
142 let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
144 // Use a fake payment_hash and bypass checking for the PaymentClaimable event since the
145 // invoice contains the payment_hash but it was encrypted inside an onion message.
146 let amount_msats = invoice.amount_msats();
147 let payment_hash = invoice.payment_hash();
149 node, path, amount_msats, payment_hash, None, ev, false, false, None, false
153 fn claim_bolt12_payment<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>]) {
154 let recipient = &path[path.len() - 1];
155 match get_event!(recipient, Event::PaymentClaimable) {
156 Event::PaymentClaimable {
157 purpose: PaymentPurpose::InvoicePayment {
158 payment_preimage: Some(payment_preimage), ..
160 } => claim_payment(node, path, payment_preimage),
165 fn extract_invoice_request<'a, 'b, 'c>(
166 node: &Node<'a, 'b, 'c>, message: &OnionMessage
167 ) -> (InvoiceRequest, Option<BlindedPath>) {
168 match node.onion_messenger.peel_onion_message(message) {
169 Ok(PeeledOnion::Receive(message, _, reply_path)) => match message {
170 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
171 OffersMessage::InvoiceRequest(invoice_request) => (invoice_request, reply_path),
172 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
173 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
175 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
177 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
178 Err(e) => panic!("Failed to process onion message {:?}", e),
182 fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage) -> Bolt12Invoice {
183 match node.onion_messenger.peel_onion_message(message) {
184 Ok(PeeledOnion::Receive(message, _, _)) => match message {
185 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
186 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
187 OffersMessage::Invoice(invoice) => invoice,
188 OffersMessage::InvoiceError(error) => panic!("Unexpected invoice_error: {:?}", error),
190 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
192 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
193 Err(e) => panic!("Failed to process onion message {:?}", e),
197 fn extract_invoice_error<'a, 'b, 'c>(
198 node: &Node<'a, 'b, 'c>, message: &OnionMessage
200 match node.onion_messenger.peel_onion_message(message) {
201 Ok(PeeledOnion::Receive(message, _, _)) => match message {
202 ParsedOnionMessageContents::Offers(offers_message) => match offers_message {
203 OffersMessage::InvoiceRequest(invoice_request) => panic!("Unexpected invoice_request: {:?}", invoice_request),
204 OffersMessage::Invoice(invoice) => panic!("Unexpected invoice: {:?}", invoice),
205 OffersMessage::InvoiceError(error) => error,
207 ParsedOnionMessageContents::Custom(message) => panic!("Unexpected custom message: {:?}", message),
209 Ok(PeeledOnion::Forward(_, _)) => panic!("Unexpected onion message forward"),
210 Err(e) => panic!("Failed to process onion message {:?}", e),
214 /// Checks that blinded paths without Tor-only nodes are preferred when constructing an offer.
216 fn prefers_non_tor_nodes_in_blinded_paths() {
217 let mut accept_forward_cfg = test_default_channel_config();
218 accept_forward_cfg.accept_forwards_to_priv_channels = true;
220 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
221 features.set_onion_messages_optional();
222 features.set_route_blinding_optional();
224 let chanmon_cfgs = create_chanmon_cfgs(6);
225 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
227 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
229 let node_chanmgrs = create_node_chanmgrs(
230 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
232 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
234 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
235 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
236 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
237 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
238 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
239 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
240 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
242 // Add an extra channel so that more than one of Bob's peers have MIN_PEER_CHANNELS.
243 create_announced_chan_between_nodes_with_value(&nodes, 4, 5, 10_000_000, 1_000_000_000);
245 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
246 let bob_id = bob.node.get_our_node_id();
247 let charlie_id = charlie.node.get_our_node_id();
249 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
250 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
252 let tor = SocketAddress::OnionV2([255, 254, 253, 252, 251, 250, 249, 248, 247, 246, 38, 7]);
253 announce_node_address(charlie, &[alice, bob, david, &nodes[4], &nodes[5]], tor);
256 .create_offer_builder("coffee".to_string()).unwrap()
257 .amount_msats(10_000_000)
259 assert_ne!(offer.signing_pubkey(), bob_id);
260 assert!(!offer.paths().is_empty());
261 for path in offer.paths() {
262 assert_ne!(path.introduction_node_id, charlie_id);
266 /// Checks that blinded paths prefer an introduction node that is the most connected.
268 fn prefers_more_connected_nodes_in_blinded_paths() {
269 let mut accept_forward_cfg = test_default_channel_config();
270 accept_forward_cfg.accept_forwards_to_priv_channels = true;
272 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
273 features.set_onion_messages_optional();
274 features.set_route_blinding_optional();
276 let chanmon_cfgs = create_chanmon_cfgs(6);
277 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
279 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
281 let node_chanmgrs = create_node_chanmgrs(
282 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
284 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
286 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
287 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
288 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
289 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
290 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
291 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
292 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
294 // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
295 // more than the others.
296 create_announced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000_000, 1_000_000_000);
297 create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 10_000_000, 1_000_000_000);
299 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
300 let bob_id = bob.node.get_our_node_id();
302 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
303 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
306 .create_offer_builder("coffee".to_string()).unwrap()
307 .amount_msats(10_000_000)
309 assert_ne!(offer.signing_pubkey(), bob_id);
310 assert!(!offer.paths().is_empty());
311 for path in offer.paths() {
312 assert_eq!(path.introduction_node_id, nodes[4].node.get_our_node_id());
316 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
317 /// rather than exposing a node's pubkey.
319 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
320 let mut accept_forward_cfg = test_default_channel_config();
321 accept_forward_cfg.accept_forwards_to_priv_channels = true;
323 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
324 features.set_onion_messages_optional();
325 features.set_route_blinding_optional();
327 let chanmon_cfgs = create_chanmon_cfgs(6);
328 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
330 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
332 let node_chanmgrs = create_node_chanmgrs(
333 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
335 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
337 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
338 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
339 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
340 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
341 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
342 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
343 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
345 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
346 let alice_id = alice.node.get_our_node_id();
347 let bob_id = bob.node.get_our_node_id();
348 let charlie_id = charlie.node.get_our_node_id();
349 let david_id = david.node.get_our_node_id();
351 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
352 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
354 let offer = alice.node
355 .create_offer_builder("coffee".to_string()).unwrap()
356 .amount_msats(10_000_000)
358 assert_ne!(offer.signing_pubkey(), alice_id);
359 assert!(!offer.paths().is_empty());
360 for path in offer.paths() {
361 assert_eq!(path.introduction_node_id, bob_id);
364 let payment_id = PaymentId([1; 32]);
365 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
367 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
369 connect_peers(david, bob);
371 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
372 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
374 connect_peers(alice, charlie);
376 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
377 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
379 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
380 assert_eq!(invoice_request.amount_msats(), None);
381 assert_ne!(invoice_request.payer_id(), david_id);
382 assert_eq!(reply_path.unwrap().introduction_node_id, charlie_id);
384 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
385 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
387 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
388 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
390 let invoice = extract_invoice(david, &onion_message);
391 assert_eq!(invoice.amount_msats(), 10_000_000);
392 assert_ne!(invoice.signing_pubkey(), alice_id);
393 assert!(!invoice.payment_paths().is_empty());
394 for (_, path) in invoice.payment_paths() {
395 assert_eq!(path.introduction_node_id, bob_id);
398 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
399 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
401 claim_bolt12_payment(david, &[charlie, bob, alice]);
402 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
405 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
406 /// rather than exposing a node's pubkey.
408 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
409 let mut accept_forward_cfg = test_default_channel_config();
410 accept_forward_cfg.accept_forwards_to_priv_channels = true;
412 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
413 features.set_onion_messages_optional();
414 features.set_route_blinding_optional();
416 let chanmon_cfgs = create_chanmon_cfgs(6);
417 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
419 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
421 let node_chanmgrs = create_node_chanmgrs(
422 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
424 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
426 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
427 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
428 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
429 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
430 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
431 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
432 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
434 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
435 let alice_id = alice.node.get_our_node_id();
436 let bob_id = bob.node.get_our_node_id();
437 let charlie_id = charlie.node.get_our_node_id();
438 let david_id = david.node.get_our_node_id();
440 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
441 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
443 let absolute_expiry = Duration::from_secs(u64::MAX);
444 let payment_id = PaymentId([1; 32]);
445 let refund = david.node
446 .create_refund_builder(
447 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
451 assert_eq!(refund.amount_msats(), 10_000_000);
452 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
453 assert_ne!(refund.payer_id(), david_id);
454 assert!(!refund.paths().is_empty());
455 for path in refund.paths() {
456 assert_eq!(path.introduction_node_id, charlie_id);
458 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
460 alice.node.request_refund_payment(&refund).unwrap();
462 connect_peers(alice, charlie);
464 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
465 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
467 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
468 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
470 let invoice = extract_invoice(david, &onion_message);
471 assert_eq!(invoice.amount_msats(), 10_000_000);
472 assert_ne!(invoice.signing_pubkey(), alice_id);
473 assert!(!invoice.payment_paths().is_empty());
474 for (_, path) in invoice.payment_paths() {
475 assert_eq!(path.introduction_node_id, bob_id);
478 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
479 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
481 claim_bolt12_payment(david, &[charlie, bob, alice]);
482 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
485 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
486 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
487 /// introduction node of the blinded path.
489 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
490 let chanmon_cfgs = create_chanmon_cfgs(2);
491 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
492 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
493 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
495 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
497 let alice = &nodes[0];
498 let alice_id = alice.node.get_our_node_id();
500 let bob_id = bob.node.get_our_node_id();
502 let offer = alice.node
503 .create_offer_builder("coffee".to_string()).unwrap()
504 .amount_msats(10_000_000)
506 assert_ne!(offer.signing_pubkey(), alice_id);
507 assert!(!offer.paths().is_empty());
508 for path in offer.paths() {
509 assert_eq!(path.introduction_node_id, alice_id);
512 let payment_id = PaymentId([1; 32]);
513 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
514 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
516 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
517 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
519 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
520 assert_eq!(invoice_request.amount_msats(), None);
521 assert_ne!(invoice_request.payer_id(), bob_id);
522 assert_eq!(reply_path.unwrap().introduction_node_id, bob_id);
524 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
525 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
527 let invoice = extract_invoice(bob, &onion_message);
528 assert_eq!(invoice.amount_msats(), 10_000_000);
529 assert_ne!(invoice.signing_pubkey(), alice_id);
530 assert!(!invoice.payment_paths().is_empty());
531 for (_, path) in invoice.payment_paths() {
532 assert_eq!(path.introduction_node_id, alice_id);
535 route_bolt12_payment(bob, &[alice], &invoice);
536 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
538 claim_bolt12_payment(bob, &[alice]);
539 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
542 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
543 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
544 /// introduction node of the blinded path.
546 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
547 let chanmon_cfgs = create_chanmon_cfgs(2);
548 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
549 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
550 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
552 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
554 let alice = &nodes[0];
555 let alice_id = alice.node.get_our_node_id();
557 let bob_id = bob.node.get_our_node_id();
559 let absolute_expiry = Duration::from_secs(u64::MAX);
560 let payment_id = PaymentId([1; 32]);
561 let refund = bob.node
562 .create_refund_builder(
563 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
567 assert_eq!(refund.amount_msats(), 10_000_000);
568 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
569 assert_ne!(refund.payer_id(), bob_id);
570 assert!(!refund.paths().is_empty());
571 for path in refund.paths() {
572 assert_eq!(path.introduction_node_id, bob_id);
574 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
576 alice.node.request_refund_payment(&refund).unwrap();
578 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
579 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
581 let invoice = extract_invoice(bob, &onion_message);
582 assert_eq!(invoice.amount_msats(), 10_000_000);
583 assert_ne!(invoice.signing_pubkey(), alice_id);
584 assert!(!invoice.payment_paths().is_empty());
585 for (_, path) in invoice.payment_paths() {
586 assert_eq!(path.introduction_node_id, alice_id);
589 route_bolt12_payment(bob, &[alice], &invoice);
590 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
592 claim_bolt12_payment(bob, &[alice]);
593 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
596 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
597 /// the requested is sent directly using the node's pubkey, the response and the payment still use
598 /// blinded paths as required by the spec.
600 fn pays_for_offer_without_blinded_paths() {
601 let chanmon_cfgs = create_chanmon_cfgs(2);
602 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
603 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
604 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
606 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
608 let alice = &nodes[0];
609 let alice_id = alice.node.get_our_node_id();
611 let bob_id = bob.node.get_our_node_id();
613 let offer = alice.node
614 .create_offer_builder("coffee".to_string()).unwrap()
616 .amount_msats(10_000_000)
618 assert_eq!(offer.signing_pubkey(), alice_id);
619 assert!(offer.paths().is_empty());
621 let payment_id = PaymentId([1; 32]);
622 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
623 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
625 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
626 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
628 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
629 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
631 let invoice = extract_invoice(bob, &onion_message);
632 route_bolt12_payment(bob, &[alice], &invoice);
633 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
635 claim_bolt12_payment(bob, &[alice]);
636 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
639 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
640 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
642 fn pays_for_refund_without_blinded_paths() {
643 let chanmon_cfgs = create_chanmon_cfgs(2);
644 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
645 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
646 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
648 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
650 let alice = &nodes[0];
651 let alice_id = alice.node.get_our_node_id();
653 let bob_id = bob.node.get_our_node_id();
655 let absolute_expiry = Duration::from_secs(u64::MAX);
656 let payment_id = PaymentId([1; 32]);
657 let refund = bob.node
658 .create_refund_builder(
659 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
664 assert_eq!(refund.payer_id(), bob_id);
665 assert!(refund.paths().is_empty());
666 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
668 alice.node.request_refund_payment(&refund).unwrap();
670 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
671 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
673 let invoice = extract_invoice(bob, &onion_message);
674 route_bolt12_payment(bob, &[alice], &invoice);
675 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
677 claim_bolt12_payment(bob, &[alice]);
678 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
681 /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
683 fn fails_creating_offer_without_blinded_paths() {
684 let chanmon_cfgs = create_chanmon_cfgs(2);
685 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
686 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
687 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
689 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
691 match nodes[0].node.create_offer_builder("coffee".to_string()) {
692 Ok(_) => panic!("Expected error"),
693 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
697 /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
699 fn fails_creating_refund_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 let absolute_expiry = Duration::from_secs(u64::MAX);
708 let payment_id = PaymentId([1; 32]);
710 match nodes[0].node.create_refund_builder(
711 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
713 Ok(_) => panic!("Expected error"),
714 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
717 assert!(nodes[0].node.list_recent_payments().is_empty());
720 /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
723 fn fails_creating_invoice_request_without_blinded_reply_path() {
724 let chanmon_cfgs = create_chanmon_cfgs(6);
725 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
726 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
727 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
729 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
730 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
731 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
732 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
733 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
735 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
737 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
738 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
740 let offer = alice.node
741 .create_offer_builder("coffee".to_string()).unwrap()
742 .amount_msats(10_000_000)
745 let payment_id = PaymentId([1; 32]);
747 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
748 Ok(_) => panic!("Expected error"),
749 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
752 assert!(nodes[0].node.list_recent_payments().is_empty());
756 fn fails_creating_invoice_request_with_duplicate_payment_id() {
757 let chanmon_cfgs = create_chanmon_cfgs(6);
758 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
759 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
760 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
762 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
763 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
764 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
765 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
766 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
767 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
768 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
770 let (alice, _bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
772 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
774 let offer = alice.node
775 .create_offer_builder("coffee".to_string()).unwrap()
776 .amount_msats(10_000_000)
779 let payment_id = PaymentId([1; 32]);
781 david.node.pay_for_offer(
782 &offer, None, None, None, payment_id, Retry::Attempts(0), None
785 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
787 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
788 Ok(_) => panic!("Expected error"),
789 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
792 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
796 fn fails_creating_refund_with_duplicate_payment_id() {
797 let chanmon_cfgs = create_chanmon_cfgs(2);
798 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
799 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
800 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
802 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
804 let absolute_expiry = Duration::from_secs(u64::MAX);
805 let payment_id = PaymentId([1; 32]);
807 nodes[0].node.create_refund_builder(
808 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
811 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
813 match nodes[0].node.create_refund_builder(
814 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
816 Ok(_) => panic!("Expected error"),
817 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
820 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
824 fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
825 let mut accept_forward_cfg = test_default_channel_config();
826 accept_forward_cfg.accept_forwards_to_priv_channels = true;
828 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
829 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
830 features.set_onion_messages_optional();
831 features.clear_route_blinding();
833 let chanmon_cfgs = create_chanmon_cfgs(6);
834 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
836 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
838 let node_chanmgrs = create_node_chanmgrs(
839 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
841 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
843 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
844 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
845 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
846 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
847 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
848 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
849 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
851 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
852 let alice_id = alice.node.get_our_node_id();
853 let bob_id = bob.node.get_our_node_id();
854 let charlie_id = charlie.node.get_our_node_id();
855 let david_id = david.node.get_our_node_id();
857 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
858 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
860 let offer = alice.node
861 .create_offer_builder("coffee".to_string()).unwrap()
862 .amount_msats(10_000_000)
865 let payment_id = PaymentId([1; 32]);
866 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
869 connect_peers(david, bob);
871 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
872 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
874 connect_peers(alice, charlie);
876 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
877 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
879 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
880 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
882 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
883 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
885 let invoice_error = extract_invoice_error(david, &onion_message);
886 assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
890 fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
891 let mut accept_forward_cfg = test_default_channel_config();
892 accept_forward_cfg.accept_forwards_to_priv_channels = true;
894 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
895 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
896 features.set_onion_messages_optional();
897 features.clear_route_blinding();
899 let chanmon_cfgs = create_chanmon_cfgs(6);
900 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
902 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
904 let node_chanmgrs = create_node_chanmgrs(
905 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
907 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
909 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
910 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
911 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
912 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
913 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
914 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
915 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
917 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
919 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
920 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
922 let absolute_expiry = Duration::from_secs(u64::MAX);
923 let payment_id = PaymentId([1; 32]);
924 let refund = david.node
925 .create_refund_builder(
926 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
931 match alice.node.request_refund_payment(&refund) {
932 Ok(_) => panic!("Expected error"),
933 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
938 fn fails_paying_invoice_more_than_once() {
939 let mut accept_forward_cfg = test_default_channel_config();
940 accept_forward_cfg.accept_forwards_to_priv_channels = true;
942 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
943 features.set_onion_messages_optional();
944 features.set_route_blinding_optional();
946 let chanmon_cfgs = create_chanmon_cfgs(6);
947 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
949 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
951 let node_chanmgrs = create_node_chanmgrs(
952 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
954 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
956 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
957 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
958 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
959 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
960 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
961 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
962 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
964 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
965 let alice_id = alice.node.get_our_node_id();
966 let bob_id = bob.node.get_our_node_id();
967 let charlie_id = charlie.node.get_our_node_id();
968 let david_id = david.node.get_our_node_id();
970 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
971 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
973 let absolute_expiry = Duration::from_secs(u64::MAX);
974 let payment_id = PaymentId([1; 32]);
975 let refund = david.node
976 .create_refund_builder(
977 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
981 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
983 // Alice sends the first invoice
984 alice.node.request_refund_payment(&refund).unwrap();
986 connect_peers(alice, charlie);
988 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
989 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
991 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
992 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
994 // David pays the first invoice
995 let invoice1 = extract_invoice(david, &onion_message);
997 route_bolt12_payment(david, &[charlie, bob, alice], &invoice1);
998 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
1000 claim_bolt12_payment(david, &[charlie, bob, alice]);
1001 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
1003 disconnect_peers(alice, &[charlie]);
1005 // Alice sends the second invoice
1006 alice.node.request_refund_payment(&refund).unwrap();
1008 connect_peers(alice, charlie);
1009 connect_peers(david, bob);
1011 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1012 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1014 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1015 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1017 let invoice2 = extract_invoice(david, &onion_message);
1018 assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata());
1020 // David sends an error instead of paying the second invoice
1021 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1022 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1024 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1025 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1027 let invoice_error = extract_invoice_error(alice, &onion_message);
1028 assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));