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();
148 let args = PassAlongPathArgs::new(node, path, amount_msats, payment_hash, ev)
149 .without_clearing_recipient_events();
150 do_pass_along_path(args);
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.clone());
256 .create_offer_builder("coffee".to_string()).unwrap()
257 .amount_msats(10_000_000)
259 assert_ne!(offer.signing_pubkey(), bob_id);
260 assert!(!offer.paths().is_empty());
261 for path in offer.paths() {
262 assert_ne!(path.introduction_node_id, bob_id);
263 assert_ne!(path.introduction_node_id, charlie_id);
266 // Use a one-hop blinded path when Bob is announced and all his peers are Tor-only.
267 announce_node_address(&nodes[4], &[alice, bob, charlie, david, &nodes[5]], tor.clone());
268 announce_node_address(&nodes[5], &[alice, bob, charlie, david, &nodes[4]], tor.clone());
271 .create_offer_builder("coffee".to_string()).unwrap()
272 .amount_msats(10_000_000)
274 assert_ne!(offer.signing_pubkey(), bob_id);
275 assert!(!offer.paths().is_empty());
276 for path in offer.paths() {
277 assert_eq!(path.introduction_node_id, bob_id);
281 /// Checks that blinded paths prefer an introduction node that is the most connected.
283 fn prefers_more_connected_nodes_in_blinded_paths() {
284 let mut accept_forward_cfg = test_default_channel_config();
285 accept_forward_cfg.accept_forwards_to_priv_channels = true;
287 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
288 features.set_onion_messages_optional();
289 features.set_route_blinding_optional();
291 let chanmon_cfgs = create_chanmon_cfgs(6);
292 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
294 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
296 let node_chanmgrs = create_node_chanmgrs(
297 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
299 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
301 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
302 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
303 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
304 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
305 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
306 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
307 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
309 // Add extra channels so that more than one of Bob's peers have MIN_PEER_CHANNELS and one has
310 // more than the others.
311 create_announced_chan_between_nodes_with_value(&nodes, 0, 4, 10_000_000, 1_000_000_000);
312 create_announced_chan_between_nodes_with_value(&nodes, 3, 4, 10_000_000, 1_000_000_000);
314 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
315 let bob_id = bob.node.get_our_node_id();
317 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
318 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
321 .create_offer_builder("coffee".to_string()).unwrap()
322 .amount_msats(10_000_000)
324 assert_ne!(offer.signing_pubkey(), bob_id);
325 assert!(!offer.paths().is_empty());
326 for path in offer.paths() {
327 assert_eq!(path.introduction_node_id, nodes[4].node.get_our_node_id());
331 /// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
332 /// rather than exposing a node's pubkey.
334 fn creates_and_pays_for_offer_using_two_hop_blinded_path() {
335 let mut accept_forward_cfg = test_default_channel_config();
336 accept_forward_cfg.accept_forwards_to_priv_channels = true;
338 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
339 features.set_onion_messages_optional();
340 features.set_route_blinding_optional();
342 let chanmon_cfgs = create_chanmon_cfgs(6);
343 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
345 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
347 let node_chanmgrs = create_node_chanmgrs(
348 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
350 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
352 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
353 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
354 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
355 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
356 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
357 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
358 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
360 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
361 let alice_id = alice.node.get_our_node_id();
362 let bob_id = bob.node.get_our_node_id();
363 let charlie_id = charlie.node.get_our_node_id();
364 let david_id = david.node.get_our_node_id();
366 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
367 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
369 let offer = alice.node
370 .create_offer_builder("coffee".to_string()).unwrap()
371 .amount_msats(10_000_000)
373 assert_ne!(offer.signing_pubkey(), alice_id);
374 assert!(!offer.paths().is_empty());
375 for path in offer.paths() {
376 assert_eq!(path.introduction_node_id, bob_id);
379 let payment_id = PaymentId([1; 32]);
380 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
382 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
384 connect_peers(david, bob);
386 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
387 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
389 connect_peers(alice, charlie);
391 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
392 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
394 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
395 assert_eq!(invoice_request.amount_msats(), None);
396 assert_ne!(invoice_request.payer_id(), david_id);
397 assert_eq!(reply_path.unwrap().introduction_node_id, charlie_id);
399 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
400 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
402 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
403 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
405 let invoice = extract_invoice(david, &onion_message);
406 assert_eq!(invoice.amount_msats(), 10_000_000);
407 assert_ne!(invoice.signing_pubkey(), alice_id);
408 assert!(!invoice.payment_paths().is_empty());
409 for (_, path) in invoice.payment_paths() {
410 assert_eq!(path.introduction_node_id, bob_id);
413 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
414 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
416 claim_bolt12_payment(david, &[charlie, bob, alice]);
417 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
420 /// Checks that a refund can be paid through blinded paths and that ephemeral pubkeys are used
421 /// rather than exposing a node's pubkey.
423 fn creates_and_pays_for_refund_using_two_hop_blinded_path() {
424 let mut accept_forward_cfg = test_default_channel_config();
425 accept_forward_cfg.accept_forwards_to_priv_channels = true;
427 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
428 features.set_onion_messages_optional();
429 features.set_route_blinding_optional();
431 let chanmon_cfgs = create_chanmon_cfgs(6);
432 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
434 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
436 let node_chanmgrs = create_node_chanmgrs(
437 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
439 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
441 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
442 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
443 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
444 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
445 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
446 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
447 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
449 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
450 let alice_id = alice.node.get_our_node_id();
451 let bob_id = bob.node.get_our_node_id();
452 let charlie_id = charlie.node.get_our_node_id();
453 let david_id = david.node.get_our_node_id();
455 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
456 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
458 let absolute_expiry = Duration::from_secs(u64::MAX);
459 let payment_id = PaymentId([1; 32]);
460 let refund = david.node
461 .create_refund_builder(
462 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
466 assert_eq!(refund.amount_msats(), 10_000_000);
467 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
468 assert_ne!(refund.payer_id(), david_id);
469 assert!(!refund.paths().is_empty());
470 for path in refund.paths() {
471 assert_eq!(path.introduction_node_id, charlie_id);
473 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
475 alice.node.request_refund_payment(&refund).unwrap();
477 connect_peers(alice, charlie);
479 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
480 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
482 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
483 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
485 let invoice = extract_invoice(david, &onion_message);
486 assert_eq!(invoice.amount_msats(), 10_000_000);
487 assert_ne!(invoice.signing_pubkey(), alice_id);
488 assert!(!invoice.payment_paths().is_empty());
489 for (_, path) in invoice.payment_paths() {
490 assert_eq!(path.introduction_node_id, bob_id);
493 route_bolt12_payment(david, &[charlie, bob, alice], &invoice);
494 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
496 claim_bolt12_payment(david, &[charlie, bob, alice]);
497 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
500 /// Checks that an offer can be paid through a one-hop blinded path and that ephemeral pubkeys are
501 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
502 /// introduction node of the blinded path.
504 fn creates_and_pays_for_offer_using_one_hop_blinded_path() {
505 let chanmon_cfgs = create_chanmon_cfgs(2);
506 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
507 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
508 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
510 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
512 let alice = &nodes[0];
513 let alice_id = alice.node.get_our_node_id();
515 let bob_id = bob.node.get_our_node_id();
517 let offer = alice.node
518 .create_offer_builder("coffee".to_string()).unwrap()
519 .amount_msats(10_000_000)
521 assert_ne!(offer.signing_pubkey(), alice_id);
522 assert!(!offer.paths().is_empty());
523 for path in offer.paths() {
524 assert_eq!(path.introduction_node_id, alice_id);
527 let payment_id = PaymentId([1; 32]);
528 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
529 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
531 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
532 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
534 let (invoice_request, reply_path) = extract_invoice_request(alice, &onion_message);
535 assert_eq!(invoice_request.amount_msats(), None);
536 assert_ne!(invoice_request.payer_id(), bob_id);
537 assert_eq!(reply_path.unwrap().introduction_node_id, bob_id);
539 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
540 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
542 let invoice = extract_invoice(bob, &onion_message);
543 assert_eq!(invoice.amount_msats(), 10_000_000);
544 assert_ne!(invoice.signing_pubkey(), alice_id);
545 assert!(!invoice.payment_paths().is_empty());
546 for (_, path) in invoice.payment_paths() {
547 assert_eq!(path.introduction_node_id, alice_id);
550 route_bolt12_payment(bob, &[alice], &invoice);
551 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
553 claim_bolt12_payment(bob, &[alice]);
554 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
557 /// Checks that a refund can be paid through a one-hop blinded path and that ephemeral pubkeys are
558 /// used rather than exposing a node's pubkey. However, the node's pubkey is still used as the
559 /// introduction node of the blinded path.
561 fn creates_and_pays_for_refund_using_one_hop_blinded_path() {
562 let chanmon_cfgs = create_chanmon_cfgs(2);
563 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
564 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
565 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
567 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
569 let alice = &nodes[0];
570 let alice_id = alice.node.get_our_node_id();
572 let bob_id = bob.node.get_our_node_id();
574 let absolute_expiry = Duration::from_secs(u64::MAX);
575 let payment_id = PaymentId([1; 32]);
576 let refund = bob.node
577 .create_refund_builder(
578 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
582 assert_eq!(refund.amount_msats(), 10_000_000);
583 assert_eq!(refund.absolute_expiry(), Some(absolute_expiry));
584 assert_ne!(refund.payer_id(), bob_id);
585 assert!(!refund.paths().is_empty());
586 for path in refund.paths() {
587 assert_eq!(path.introduction_node_id, bob_id);
589 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
591 alice.node.request_refund_payment(&refund).unwrap();
593 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
594 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
596 let invoice = extract_invoice(bob, &onion_message);
597 assert_eq!(invoice.amount_msats(), 10_000_000);
598 assert_ne!(invoice.signing_pubkey(), alice_id);
599 assert!(!invoice.payment_paths().is_empty());
600 for (_, path) in invoice.payment_paths() {
601 assert_eq!(path.introduction_node_id, alice_id);
604 route_bolt12_payment(bob, &[alice], &invoice);
605 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
607 claim_bolt12_payment(bob, &[alice]);
608 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
611 /// Checks that an invoice for an offer without any blinded paths can be requested. Note that while
612 /// the requested is sent directly using the node's pubkey, the response and the payment still use
613 /// blinded paths as required by the spec.
615 fn pays_for_offer_without_blinded_paths() {
616 let chanmon_cfgs = create_chanmon_cfgs(2);
617 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
618 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
619 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
621 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
623 let alice = &nodes[0];
624 let alice_id = alice.node.get_our_node_id();
626 let bob_id = bob.node.get_our_node_id();
628 let offer = alice.node
629 .create_offer_builder("coffee".to_string()).unwrap()
631 .amount_msats(10_000_000)
633 assert_eq!(offer.signing_pubkey(), alice_id);
634 assert!(offer.paths().is_empty());
636 let payment_id = PaymentId([1; 32]);
637 bob.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None).unwrap();
638 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
640 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
641 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
643 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
644 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
646 let invoice = extract_invoice(bob, &onion_message);
647 route_bolt12_payment(bob, &[alice], &invoice);
648 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
650 claim_bolt12_payment(bob, &[alice]);
651 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
654 /// Checks that a refund without any blinded paths can be paid. Note that while the invoice is sent
655 /// directly using the node's pubkey, the payment still use blinded paths as required by the spec.
657 fn pays_for_refund_without_blinded_paths() {
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 absolute_expiry = Duration::from_secs(u64::MAX);
671 let payment_id = PaymentId([1; 32]);
672 let refund = bob.node
673 .create_refund_builder(
674 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
679 assert_eq!(refund.payer_id(), bob_id);
680 assert!(refund.paths().is_empty());
681 expect_recent_payment!(bob, RecentPaymentDetails::AwaitingInvoice, payment_id);
683 alice.node.request_refund_payment(&refund).unwrap();
685 let onion_message = alice.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
686 bob.onion_messenger.handle_onion_message(&alice_id, &onion_message);
688 let invoice = extract_invoice(bob, &onion_message);
689 route_bolt12_payment(bob, &[alice], &invoice);
690 expect_recent_payment!(bob, RecentPaymentDetails::Pending, payment_id);
692 claim_bolt12_payment(bob, &[alice]);
693 expect_recent_payment!(bob, RecentPaymentDetails::Fulfilled, payment_id);
696 /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
698 fn fails_creating_offer_without_blinded_paths() {
699 let chanmon_cfgs = create_chanmon_cfgs(2);
700 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
701 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
702 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
704 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
706 match nodes[0].node.create_offer_builder("coffee".to_string()) {
707 Ok(_) => panic!("Expected error"),
708 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
712 /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
714 fn fails_creating_refund_without_blinded_paths() {
715 let chanmon_cfgs = create_chanmon_cfgs(2);
716 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
717 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
718 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
720 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
722 let absolute_expiry = Duration::from_secs(u64::MAX);
723 let payment_id = PaymentId([1; 32]);
725 match nodes[0].node.create_refund_builder(
726 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
728 Ok(_) => panic!("Expected error"),
729 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
732 assert!(nodes[0].node.list_recent_payments().is_empty());
735 /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
738 fn fails_creating_invoice_request_without_blinded_reply_path() {
739 let chanmon_cfgs = create_chanmon_cfgs(6);
740 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
741 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
742 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
744 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
745 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
746 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
747 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
748 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
750 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
752 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
753 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
755 let offer = alice.node
756 .create_offer_builder("coffee".to_string()).unwrap()
757 .amount_msats(10_000_000)
760 let payment_id = PaymentId([1; 32]);
762 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
763 Ok(_) => panic!("Expected error"),
764 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
767 assert!(nodes[0].node.list_recent_payments().is_empty());
771 fn fails_creating_invoice_request_with_duplicate_payment_id() {
772 let chanmon_cfgs = create_chanmon_cfgs(6);
773 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
774 let node_chanmgrs = create_node_chanmgrs(6, &node_cfgs, &[None, None, None, None, None, None]);
775 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
777 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
778 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
779 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
780 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
781 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
782 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
783 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
785 let (alice, _bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
787 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
789 let offer = alice.node
790 .create_offer_builder("coffee".to_string()).unwrap()
791 .amount_msats(10_000_000)
794 let payment_id = PaymentId([1; 32]);
796 david.node.pay_for_offer(
797 &offer, None, None, None, payment_id, Retry::Attempts(0), None
800 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
802 match david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None) {
803 Ok(_) => panic!("Expected error"),
804 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
807 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
811 fn fails_creating_refund_with_duplicate_payment_id() {
812 let chanmon_cfgs = create_chanmon_cfgs(2);
813 let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
814 let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
815 let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
817 create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
819 let absolute_expiry = Duration::from_secs(u64::MAX);
820 let payment_id = PaymentId([1; 32]);
822 nodes[0].node.create_refund_builder(
823 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
826 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
828 match nodes[0].node.create_refund_builder(
829 "refund".to_string(), 10_000, absolute_expiry, payment_id, Retry::Attempts(0), None
831 Ok(_) => panic!("Expected error"),
832 Err(e) => assert_eq!(e, Bolt12SemanticError::DuplicatePaymentId),
835 expect_recent_payment!(nodes[0], RecentPaymentDetails::AwaitingInvoice, payment_id);
839 fn fails_sending_invoice_without_blinded_payment_paths_for_offer() {
840 let mut accept_forward_cfg = test_default_channel_config();
841 accept_forward_cfg.accept_forwards_to_priv_channels = true;
843 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
844 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
845 features.set_onion_messages_optional();
846 features.clear_route_blinding();
848 let chanmon_cfgs = create_chanmon_cfgs(6);
849 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
851 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
853 let node_chanmgrs = create_node_chanmgrs(
854 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
856 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
858 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
859 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
860 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
861 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
862 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
863 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
864 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
866 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
867 let alice_id = alice.node.get_our_node_id();
868 let bob_id = bob.node.get_our_node_id();
869 let charlie_id = charlie.node.get_our_node_id();
870 let david_id = david.node.get_our_node_id();
872 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
873 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
875 let offer = alice.node
876 .create_offer_builder("coffee".to_string()).unwrap()
877 .amount_msats(10_000_000)
880 let payment_id = PaymentId([1; 32]);
881 david.node.pay_for_offer(&offer, None, None, None, payment_id, Retry::Attempts(0), None)
884 connect_peers(david, bob);
886 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
887 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
889 connect_peers(alice, charlie);
891 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
892 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
894 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
895 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
897 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
898 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
900 let invoice_error = extract_invoice_error(david, &onion_message);
901 assert_eq!(invoice_error, InvoiceError::from(Bolt12SemanticError::MissingPaths));
905 fn fails_sending_invoice_without_blinded_payment_paths_for_refund() {
906 let mut accept_forward_cfg = test_default_channel_config();
907 accept_forward_cfg.accept_forwards_to_priv_channels = true;
909 // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
910 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
911 features.set_onion_messages_optional();
912 features.clear_route_blinding();
914 let chanmon_cfgs = create_chanmon_cfgs(6);
915 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
917 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
919 let node_chanmgrs = create_node_chanmgrs(
920 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
922 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
924 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
925 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
926 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
927 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
928 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
929 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
930 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
932 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
934 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
935 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
937 let absolute_expiry = Duration::from_secs(u64::MAX);
938 let payment_id = PaymentId([1; 32]);
939 let refund = david.node
940 .create_refund_builder(
941 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
946 match alice.node.request_refund_payment(&refund) {
947 Ok(_) => panic!("Expected error"),
948 Err(e) => assert_eq!(e, Bolt12SemanticError::MissingPaths),
953 fn fails_paying_invoice_more_than_once() {
954 let mut accept_forward_cfg = test_default_channel_config();
955 accept_forward_cfg.accept_forwards_to_priv_channels = true;
957 let mut features = channelmanager::provided_init_features(&accept_forward_cfg);
958 features.set_onion_messages_optional();
959 features.set_route_blinding_optional();
961 let chanmon_cfgs = create_chanmon_cfgs(6);
962 let node_cfgs = create_node_cfgs(6, &chanmon_cfgs);
964 *node_cfgs[1].override_init_features.borrow_mut() = Some(features);
966 let node_chanmgrs = create_node_chanmgrs(
967 6, &node_cfgs, &[None, Some(accept_forward_cfg), None, None, None, None]
969 let nodes = create_network(6, &node_cfgs, &node_chanmgrs);
971 create_unannounced_chan_between_nodes_with_value(&nodes, 0, 1, 10_000_000, 1_000_000_000);
972 create_unannounced_chan_between_nodes_with_value(&nodes, 2, 3, 10_000_000, 1_000_000_000);
973 create_announced_chan_between_nodes_with_value(&nodes, 1, 2, 10_000_000, 1_000_000_000);
974 create_announced_chan_between_nodes_with_value(&nodes, 1, 4, 10_000_000, 1_000_000_000);
975 create_announced_chan_between_nodes_with_value(&nodes, 1, 5, 10_000_000, 1_000_000_000);
976 create_announced_chan_between_nodes_with_value(&nodes, 2, 4, 10_000_000, 1_000_000_000);
977 create_announced_chan_between_nodes_with_value(&nodes, 2, 5, 10_000_000, 1_000_000_000);
979 let (alice, bob, charlie, david) = (&nodes[0], &nodes[1], &nodes[2], &nodes[3]);
980 let alice_id = alice.node.get_our_node_id();
981 let bob_id = bob.node.get_our_node_id();
982 let charlie_id = charlie.node.get_our_node_id();
983 let david_id = david.node.get_our_node_id();
985 disconnect_peers(alice, &[charlie, david, &nodes[4], &nodes[5]]);
986 disconnect_peers(david, &[bob, &nodes[4], &nodes[5]]);
988 let absolute_expiry = Duration::from_secs(u64::MAX);
989 let payment_id = PaymentId([1; 32]);
990 let refund = david.node
991 .create_refund_builder(
992 "refund".to_string(), 10_000_000, absolute_expiry, payment_id, Retry::Attempts(0), None
996 expect_recent_payment!(david, RecentPaymentDetails::AwaitingInvoice, payment_id);
998 // Alice sends the first invoice
999 alice.node.request_refund_payment(&refund).unwrap();
1001 connect_peers(alice, charlie);
1003 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1004 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1006 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1007 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1009 // David pays the first invoice
1010 let invoice1 = extract_invoice(david, &onion_message);
1012 route_bolt12_payment(david, &[charlie, bob, alice], &invoice1);
1013 expect_recent_payment!(david, RecentPaymentDetails::Pending, payment_id);
1015 claim_bolt12_payment(david, &[charlie, bob, alice]);
1016 expect_recent_payment!(david, RecentPaymentDetails::Fulfilled, payment_id);
1018 disconnect_peers(alice, &[charlie]);
1020 // Alice sends the second invoice
1021 alice.node.request_refund_payment(&refund).unwrap();
1023 connect_peers(alice, charlie);
1024 connect_peers(david, bob);
1026 let onion_message = alice.onion_messenger.next_onion_message_for_peer(charlie_id).unwrap();
1027 charlie.onion_messenger.handle_onion_message(&alice_id, &onion_message);
1029 let onion_message = charlie.onion_messenger.next_onion_message_for_peer(david_id).unwrap();
1030 david.onion_messenger.handle_onion_message(&charlie_id, &onion_message);
1032 let invoice2 = extract_invoice(david, &onion_message);
1033 assert_eq!(invoice1.payer_metadata(), invoice2.payer_metadata());
1035 // David sends an error instead of paying the second invoice
1036 let onion_message = david.onion_messenger.next_onion_message_for_peer(bob_id).unwrap();
1037 bob.onion_messenger.handle_onion_message(&david_id, &onion_message);
1039 let onion_message = bob.onion_messenger.next_onion_message_for_peer(alice_id).unwrap();
1040 alice.onion_messenger.handle_onion_message(&bob_id, &onion_message);
1042 let invoice_error = extract_invoice_error(alice, &onion_message);
1043 assert_eq!(invoice_error, InvoiceError::from_string("DuplicateInvoice".to_string()));