|
10 | 10 | //! Tests for calculating the maximum length of a path based on the payment metadata, custom TLVs,
|
11 | 11 | //! and/or blinded paths present.
|
12 | 12 |
|
13 |
| -use bitcoin::secp256k1::Secp256k1; |
14 |
| -use crate::blinded_path::BlindedPath; |
| 13 | +use bitcoin::secp256k1::{Secp256k1, PublicKey}; |
| 14 | +use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode}; |
15 | 15 | use crate::blinded_path::payment::{PaymentConstraints, PaymentContext, ReceiveTlvs};
|
16 | 16 | use crate::events::MessageSendEventsProvider;
|
17 | 17 | use crate::ln::PaymentSecret;
|
18 | 18 | use crate::ln::blinded_payment_tests::get_blinded_route_parameters;
|
19 | 19 | use crate::ln::channelmanager::PaymentId;
|
| 20 | +use crate::ln::features::BlindedHopFeatures; |
20 | 21 | use crate::ln::functional_test_utils::*;
|
21 | 22 | use crate::ln::msgs;
|
| 23 | +use crate::ln::msgs::OnionMessageHandler; |
22 | 24 | use crate::ln::onion_utils;
|
23 | 25 | use crate::ln::onion_utils::MIN_FINAL_VALUE_ESTIMATE_WITH_OVERPAY;
|
24 | 26 | use crate::ln::outbound_payment::{RecipientOnionFields, Retry, RetryableSendFailure};
|
| 27 | +use crate::offers::invoice::BlindedPayInfo; |
25 | 28 | use crate::prelude::*;
|
26 | 29 | use crate::routing::router::{DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, PaymentParameters, RouteParameters};
|
27 | 30 | use crate::util::errors::APIError;
|
@@ -340,3 +343,50 @@ fn blinded_path_with_custom_tlv() {
|
340 | 343 | .with_custom_tlvs(recipient_onion_allows_2_hops.custom_tlvs)
|
341 | 344 | );
|
342 | 345 | }
|
| 346 | + |
| 347 | +#[test] |
| 348 | +fn bolt12_invoice_too_large_blinded_paths() { |
| 349 | + // Check that we'll fail paying BOLT 12 invoices with too-large blinded paths prior to |
| 350 | + // pathfinding. |
| 351 | + let chanmon_cfgs = create_chanmon_cfgs(2); |
| 352 | + let node_cfgs = create_node_cfgs(2, &chanmon_cfgs); |
| 353 | + let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]); |
| 354 | + let nodes = create_network(2, &node_cfgs, &node_chanmgrs); |
| 355 | + create_announced_chan_between_nodes(&nodes, 0, 1); |
| 356 | + |
| 357 | + nodes[1].router.expect_blinded_payment_paths(vec![( |
| 358 | + BlindedPayInfo { |
| 359 | + fee_base_msat: 42, |
| 360 | + fee_proportional_millionths: 42, |
| 361 | + cltv_expiry_delta: 42, |
| 362 | + htlc_minimum_msat: 42, |
| 363 | + htlc_maximum_msat: 42_000_000, |
| 364 | + features: BlindedHopFeatures::empty(), |
| 365 | + }, |
| 366 | + BlindedPath { |
| 367 | + introduction_node: IntroductionNode::NodeId(PublicKey::from_slice(&[2; 33]).unwrap()), |
| 368 | + blinding_point: PublicKey::from_slice(&[2; 33]).unwrap(), |
| 369 | + blinded_hops: vec![ |
| 370 | + BlindedHop { |
| 371 | + blinded_node_id: PublicKey::from_slice(&[2; 33]).unwrap(), |
| 372 | + encrypted_payload: vec![42; 1300], |
| 373 | + }, |
| 374 | + BlindedHop { |
| 375 | + blinded_node_id: PublicKey::from_slice(&[2; 33]).unwrap(), |
| 376 | + encrypted_payload: vec![42; 1300], |
| 377 | + }, |
| 378 | + ], |
| 379 | + } |
| 380 | + )]); |
| 381 | + |
| 382 | + let offer = nodes[1].node.create_offer_builder(None).unwrap().build().unwrap(); |
| 383 | + let payment_id = PaymentId([1; 32]); |
| 384 | + nodes[0].node.pay_for_offer(&offer, None, Some(5000), None, payment_id, Retry::Attempts(0), None).unwrap(); |
| 385 | + let invreq_om = nodes[0].onion_messenger.next_onion_message_for_peer(nodes[1].node.get_our_node_id()).unwrap(); |
| 386 | + nodes[1].onion_messenger.handle_onion_message(&nodes[0].node.get_our_node_id(), &invreq_om); |
| 387 | + |
| 388 | + let invoice_om = nodes[1].onion_messenger.next_onion_message_for_peer(nodes[0].node.get_our_node_id()).unwrap(); |
| 389 | + nodes[0].onion_messenger.handle_onion_message(&nodes[1].node.get_our_node_id(), &invoice_om); |
| 390 | + // TODO: assert on the invoice error once we support replying to invoice OMs with failure info |
| 391 | + nodes[0].logger.assert_log_contains("lightning::ln::channelmanager", "Failed paying invoice: OnionPacketSizeExceeded", 1); |
| 392 | +} |
0 commit comments