@@ -21,6 +21,7 @@ use crate::ln::channelmanager::{PaymentId, RecentPaymentDetails, Retry, self};
21
21
use crate :: ln:: functional_test_utils:: * ;
22
22
use crate :: ln:: msgs:: { ChannelMessageHandler , Init , OnionMessage , OnionMessageHandler } ;
23
23
use crate :: offers:: invoice:: Bolt12Invoice ;
24
+ use crate :: offers:: invoice_error:: InvoiceError ;
24
25
use crate :: offers:: invoice_request:: InvoiceRequest ;
25
26
use crate :: offers:: parse:: Bolt12SemanticError ;
26
27
use crate :: onion_message:: messenger:: PeeledOnion ;
@@ -134,6 +135,23 @@ fn extract_invoice<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, message: &OnionMessage)
134
135
}
135
136
}
136
137
138
+ fn extract_invoice_error < ' a , ' b , ' c > (
139
+ node : & Node < ' a , ' b , ' c > , message : & OnionMessage
140
+ ) -> InvoiceError {
141
+ match node. onion_messenger . peel_onion_message ( message) {
142
+ Ok ( PeeledOnion :: Receive ( message, _, _) ) => match message {
143
+ ParsedOnionMessageContents :: Offers ( offers_message) => match offers_message {
144
+ OffersMessage :: InvoiceRequest ( invoice_request) => panic ! ( "Unexpected invoice_request: {:?}" , invoice_request) ,
145
+ OffersMessage :: Invoice ( invoice) => panic ! ( "Unexpected invoice: {:?}" , invoice) ,
146
+ OffersMessage :: InvoiceError ( error) => error,
147
+ } ,
148
+ ParsedOnionMessageContents :: Custom ( message) => panic ! ( "Unexpected custom message: {:?}" , message) ,
149
+ } ,
150
+ Ok ( PeeledOnion :: Forward ( _, _) ) => panic ! ( "Unexpected onion message forward" ) ,
151
+ Err ( e) => panic ! ( "Failed to process onion message {:?}" , e) ,
152
+ }
153
+ }
154
+
137
155
/// Checks that an offer can be paid through blinded paths and that ephemeral pubkeys are used
138
156
/// rather than exposing a node's pubkey.
139
157
#[ test]
@@ -640,3 +658,117 @@ fn fails_creating_refund_with_duplicate_payment_id() {
640
658
641
659
expect_recent_payment ! ( nodes[ 0 ] , RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
642
660
}
661
+
662
+ #[ test]
663
+ fn fails_sending_invoice_without_blinded_payment_paths_for_offer ( ) {
664
+ let mut accept_forward_cfg = test_default_channel_config ( ) ;
665
+ accept_forward_cfg. accept_forwards_to_priv_channels = true ;
666
+
667
+ // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
668
+ let mut features = channelmanager:: provided_init_features ( & accept_forward_cfg) ;
669
+ features. set_onion_messages_optional ( ) ;
670
+ features. clear_route_blinding ( ) ;
671
+
672
+ let chanmon_cfgs = create_chanmon_cfgs ( 6 ) ;
673
+ let node_cfgs = create_node_cfgs ( 6 , & chanmon_cfgs) ;
674
+
675
+ * node_cfgs[ 1 ] . override_init_features . borrow_mut ( ) = Some ( features) ;
676
+
677
+ let node_chanmgrs = create_node_chanmgrs (
678
+ 6 , & node_cfgs, & [ None , Some ( accept_forward_cfg) , None , None , None , None ]
679
+ ) ;
680
+ let nodes = create_network ( 6 , & node_cfgs, & node_chanmgrs) ;
681
+
682
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
683
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 10_000_000 , 1_000_000_000 ) ;
684
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 10_000_000 , 1_000_000_000 ) ;
685
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 4 , 10_000_000 , 1_000_000_000 ) ;
686
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 5 , 10_000_000 , 1_000_000_000 ) ;
687
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 10_000_000 , 1_000_000_000 ) ;
688
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 5 , 10_000_000 , 1_000_000_000 ) ;
689
+
690
+ let ( alice, bob, charlie, david) = ( & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ) ;
691
+ let alice_id = alice. node . get_our_node_id ( ) ;
692
+ let bob_id = bob. node . get_our_node_id ( ) ;
693
+ let charlie_id = charlie. node . get_our_node_id ( ) ;
694
+ let david_id = david. node . get_our_node_id ( ) ;
695
+
696
+ disconnect_peers ( alice, & [ charlie, david, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
697
+ disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
698
+
699
+ let offer = alice. node
700
+ . create_offer_builder ( "coffee" . to_string ( ) ) . unwrap ( )
701
+ . amount_msats ( 10_000_000 )
702
+ . build ( ) . unwrap ( ) ;
703
+
704
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
705
+ david. node . pay_for_offer ( & offer, None , None , None , payment_id, Retry :: Attempts ( 0 ) , None )
706
+ . unwrap ( ) ;
707
+
708
+ connect_peers ( david, bob) ;
709
+
710
+ let onion_message = david. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
711
+ bob. onion_messenger . handle_onion_message ( & david_id, & onion_message) ;
712
+
713
+ connect_peers ( alice, charlie) ;
714
+
715
+ let onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
716
+ alice. onion_messenger . handle_onion_message ( & bob_id, & onion_message) ;
717
+
718
+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( charlie_id) . unwrap ( ) ;
719
+ charlie. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
720
+
721
+ let onion_message = charlie. onion_messenger . next_onion_message_for_peer ( david_id) . unwrap ( ) ;
722
+ david. onion_messenger . handle_onion_message ( & charlie_id, & onion_message) ;
723
+
724
+ let invoice_error = extract_invoice_error ( david, & onion_message) ;
725
+ assert_eq ! ( invoice_error, InvoiceError :: from( Bolt12SemanticError :: MissingPaths ) ) ;
726
+ }
727
+
728
+ #[ test]
729
+ fn fails_sending_invoice_without_blinded_payment_paths_for_refund ( ) {
730
+ let mut accept_forward_cfg = test_default_channel_config ( ) ;
731
+ accept_forward_cfg. accept_forwards_to_priv_channels = true ;
732
+
733
+ // Clearing route_blinding prevents forming any payment paths since the node is unannounced.
734
+ let mut features = channelmanager:: provided_init_features ( & accept_forward_cfg) ;
735
+ features. set_onion_messages_optional ( ) ;
736
+ features. clear_route_blinding ( ) ;
737
+
738
+ let chanmon_cfgs = create_chanmon_cfgs ( 6 ) ;
739
+ let node_cfgs = create_node_cfgs ( 6 , & chanmon_cfgs) ;
740
+
741
+ * node_cfgs[ 1 ] . override_init_features . borrow_mut ( ) = Some ( features) ;
742
+
743
+ let node_chanmgrs = create_node_chanmgrs (
744
+ 6 , & node_cfgs, & [ None , Some ( accept_forward_cfg) , None , None , None , None ]
745
+ ) ;
746
+ let nodes = create_network ( 6 , & node_cfgs, & node_chanmgrs) ;
747
+
748
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
749
+ create_unannounced_chan_between_nodes_with_value ( & nodes, 2 , 3 , 10_000_000 , 1_000_000_000 ) ;
750
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 2 , 10_000_000 , 1_000_000_000 ) ;
751
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 4 , 10_000_000 , 1_000_000_000 ) ;
752
+ create_announced_chan_between_nodes_with_value ( & nodes, 1 , 5 , 10_000_000 , 1_000_000_000 ) ;
753
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 4 , 10_000_000 , 1_000_000_000 ) ;
754
+ create_announced_chan_between_nodes_with_value ( & nodes, 2 , 5 , 10_000_000 , 1_000_000_000 ) ;
755
+
756
+ let ( alice, bob, charlie, david) = ( & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ) ;
757
+
758
+ disconnect_peers ( alice, & [ charlie, david, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
759
+ disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
760
+
761
+ let absolute_expiry = Duration :: from_secs ( u64:: MAX ) ;
762
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
763
+ let refund = david. node
764
+ . create_refund_builder (
765
+ "refund" . to_string ( ) , 10_000_000 , absolute_expiry, payment_id, Retry :: Attempts ( 0 ) , None
766
+ )
767
+ . unwrap ( )
768
+ . build ( ) . unwrap ( ) ;
769
+
770
+ match alice. node . request_refund_payment ( & refund) {
771
+ Ok ( _) => panic ! ( "Expected error" ) ,
772
+ Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: MissingPaths ) ,
773
+ }
774
+ }
0 commit comments