@@ -950,43 +950,112 @@ fn pays_bolt12_invoice_asynchronously() {
950
950
) ;
951
951
}
952
952
953
- /// Fails creating an offer when a blinded path cannot be created without exposing the node's id.
953
+ /// Checks that an offer can be created using an unannounced node as a blinded path's introduction
954
+ /// node. This is only preferred if there are no other options which may indicated either the offer
955
+ /// is intended for the unannounced node or that the node is actually announced (e.g., an LSP) but
956
+ /// the recipient doesn't have a network graph.
954
957
#[ test]
955
- fn fails_creating_offer_without_blinded_paths ( ) {
958
+ fn creates_offer_with_blinded_path_using_unannounced_introduction_node ( ) {
956
959
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
957
960
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
958
961
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
959
962
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
960
963
961
964
create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
962
965
963
- match nodes[ 0 ] . node . create_offer_builder ( None ) {
964
- Ok ( _) => panic ! ( "Expected error" ) ,
965
- Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: MissingPaths ) ,
966
+ let alice = & nodes[ 0 ] ;
967
+ let alice_id = alice. node . get_our_node_id ( ) ;
968
+ let bob = & nodes[ 1 ] ;
969
+ let bob_id = bob. node . get_our_node_id ( ) ;
970
+
971
+ let offer = alice. node
972
+ . create_offer_builder ( None ) . unwrap ( )
973
+ . amount_msats ( 10_000_000 )
974
+ . build ( ) . unwrap ( ) ;
975
+ assert_ne ! ( offer. signing_pubkey( ) , Some ( alice_id) ) ;
976
+ assert ! ( !offer. paths( ) . is_empty( ) ) ;
977
+ for path in offer. paths ( ) {
978
+ assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
966
979
}
980
+
981
+ let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
982
+ bob. node . pay_for_offer ( & offer, None , None , None , payment_id, Retry :: Attempts ( 0 ) , None ) . unwrap ( ) ;
983
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
984
+
985
+ let onion_message = bob. onion_messenger . next_onion_message_for_peer ( alice_id) . unwrap ( ) ;
986
+ alice. onion_messenger . handle_onion_message ( & bob_id, & onion_message) ;
987
+
988
+ let ( invoice_request, reply_path) = extract_invoice_request ( alice, & onion_message) ;
989
+ let payment_context = PaymentContext :: Bolt12Offer ( Bolt12OfferContext {
990
+ offer_id : offer. id ( ) ,
991
+ invoice_request : InvoiceRequestFields {
992
+ payer_id : invoice_request. payer_id ( ) ,
993
+ quantity : None ,
994
+ payer_note_truncated : None ,
995
+ } ,
996
+ } ) ;
997
+ assert_ne ! ( invoice_request. payer_id( ) , bob_id) ;
998
+ assert_eq ! ( reply_path. introduction_node, IntroductionNode :: NodeId ( alice_id) ) ;
999
+
1000
+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
1001
+ bob. onion_messenger . handle_onion_message ( & alice_id, & onion_message) ;
1002
+
1003
+ let invoice = extract_invoice ( bob, & onion_message) ;
1004
+ assert_ne ! ( invoice. signing_pubkey( ) , alice_id) ;
1005
+ assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ;
1006
+ for ( _, path) in invoice. payment_paths ( ) {
1007
+ assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
1008
+ }
1009
+
1010
+ route_bolt12_payment ( bob, & [ alice] , & invoice) ;
1011
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Pending , payment_id) ;
1012
+
1013
+ claim_bolt12_payment ( bob, & [ alice] , payment_context) ;
1014
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: Fulfilled , payment_id) ;
967
1015
}
968
1016
969
- /// Fails creating a refund when a blinded path cannot be created without exposing the node's id.
1017
+ /// Checks that a refund can be created using an unannounced node as a blinded path's introduction
1018
+ /// node. This is only preferred if there are no other options which may indicated either the refund
1019
+ /// is intended for the unannounced node or that the node is actually announced (e.g., an LSP) but
1020
+ /// the sender doesn't have a network graph.
970
1021
#[ test]
971
- fn fails_creating_refund_without_blinded_paths ( ) {
1022
+ fn creates_refund_with_blinded_path_using_unannounced_introduction_node ( ) {
972
1023
let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
973
1024
let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
974
1025
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
975
1026
let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
976
1027
977
1028
create_unannounced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 10_000_000 , 1_000_000_000 ) ;
978
1029
1030
+ let alice = & nodes[ 0 ] ;
1031
+ let alice_id = alice. node . get_our_node_id ( ) ;
1032
+ let bob = & nodes[ 1 ] ;
1033
+ let bob_id = bob. node . get_our_node_id ( ) ;
1034
+
979
1035
let absolute_expiry = Duration :: from_secs ( u64:: MAX ) ;
980
1036
let payment_id = PaymentId ( [ 1 ; 32 ] ) ;
981
-
982
- match nodes[ 0 ] . node . create_refund_builder (
983
- 10_000 , absolute_expiry, payment_id, Retry :: Attempts ( 0 ) , None
984
- ) {
985
- Ok ( _) => panic ! ( "Expected error" ) ,
986
- Err ( e) => assert_eq ! ( e, Bolt12SemanticError :: MissingPaths ) ,
1037
+ let refund = bob. node
1038
+ . create_refund_builder ( 10_000_000 , absolute_expiry, payment_id, Retry :: Attempts ( 0 ) , None )
1039
+ . unwrap ( )
1040
+ . build ( ) . unwrap ( ) ;
1041
+ assert_ne ! ( refund. payer_id( ) , bob_id) ;
1042
+ assert ! ( !refund. paths( ) . is_empty( ) ) ;
1043
+ for path in refund. paths ( ) {
1044
+ assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( alice_id) ) ;
987
1045
}
1046
+ expect_recent_payment ! ( bob, RecentPaymentDetails :: AwaitingInvoice , payment_id) ;
988
1047
989
- assert ! ( nodes[ 0 ] . node. list_recent_payments( ) . is_empty( ) ) ;
1048
+ let expected_invoice = alice. node . request_refund_payment ( & refund) . unwrap ( ) ;
1049
+
1050
+ let onion_message = alice. onion_messenger . next_onion_message_for_peer ( bob_id) . unwrap ( ) ;
1051
+
1052
+ let invoice = extract_invoice ( bob, & onion_message) ;
1053
+ assert_eq ! ( invoice, expected_invoice) ;
1054
+ assert_ne ! ( invoice. signing_pubkey( ) , alice_id) ;
1055
+ assert ! ( !invoice. payment_paths( ) . is_empty( ) ) ;
1056
+ for ( _, path) in invoice. payment_paths ( ) {
1057
+ assert_eq ! ( path. introduction_node, IntroductionNode :: NodeId ( bob_id) ) ;
1058
+ }
990
1059
}
991
1060
992
1061
/// Fails creating or paying an offer when a blinded path cannot be created because no peers are
@@ -1165,8 +1234,7 @@ fn fails_sending_invoice_with_unsupported_chain_for_refund() {
1165
1234
}
1166
1235
}
1167
1236
1168
- /// Fails creating an invoice request when a blinded reply path cannot be created without exposing
1169
- /// the node's id.
1237
+ /// Fails creating an invoice request when a blinded reply path cannot be created.
1170
1238
#[ test]
1171
1239
fn fails_creating_invoice_request_without_blinded_reply_path ( ) {
1172
1240
let chanmon_cfgs = create_chanmon_cfgs ( 6 ) ;
@@ -1183,7 +1251,7 @@ fn fails_creating_invoice_request_without_blinded_reply_path() {
1183
1251
let ( alice, bob, charlie, david) = ( & nodes[ 0 ] , & nodes[ 1 ] , & nodes[ 2 ] , & nodes[ 3 ] ) ;
1184
1252
1185
1253
disconnect_peers ( alice, & [ charlie, david, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
1186
- disconnect_peers ( david, & [ bob, & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
1254
+ disconnect_peers ( david, & [ bob, charlie , & nodes[ 4 ] , & nodes[ 5 ] ] ) ;
1187
1255
1188
1256
let offer = alice. node
1189
1257
. create_offer_builder ( None ) . unwrap ( )
0 commit comments