@@ -19,6 +19,7 @@ use crate::events::{self, PaymentFailureReason};
1919use crate :: ln:: types:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
2020use crate :: ln:: channel_state:: ChannelDetails ;
2121use crate :: ln:: channelmanager:: { EventCompletionAction , HTLCSource , PaymentId } ;
22+ use crate :: ln:: features:: Bolt12InvoiceFeatures ;
2223use crate :: ln:: onion_utils;
2324use crate :: ln:: onion_utils:: { DecodedOnionFailure , HTLCFailReason } ;
2425use crate :: offers:: invoice:: Bolt12Invoice ;
@@ -510,6 +511,8 @@ pub enum Bolt12PaymentError {
510511 UnexpectedInvoice ,
511512 /// Payment for an invoice with the corresponding [`PaymentId`] was already initiated.
512513 DuplicateInvoice ,
514+ /// The invoice was valid for the corresponding [`PaymentId`], but required unknown features.
515+ UnknownRequiredFeatures ,
513516 /// The invoice was valid for the corresponding [`PaymentId`], but sending the payment failed.
514517 SendingFailed ( RetryableSendFailure ) ,
515518}
@@ -783,9 +786,9 @@ impl OutboundPayments {
783786 R : Deref , ES : Deref , NS : Deref , NL : Deref , IH , SP , L : Deref
784787 > (
785788 & self , invoice : & Bolt12Invoice , payment_id : PaymentId , router : & R ,
786- first_hops : Vec < ChannelDetails > , inflight_htlcs : IH , entropy_source : & ES , node_signer : & NS ,
787- node_id_lookup : & NL , secp_ctx : & Secp256k1 < secp256k1 :: All > , best_block_height : u32 ,
788- logger : & L ,
789+ first_hops : Vec < ChannelDetails > , features : Bolt12InvoiceFeatures , inflight_htlcs : IH ,
790+ entropy_source : & ES , node_signer : & NS , node_id_lookup : & NL ,
791+ secp_ctx : & Secp256k1 < secp256k1 :: All > , best_block_height : u32 , logger : & L ,
789792 pending_events : & Mutex < VecDeque < ( events:: Event , Option < EventCompletionAction > ) > > ,
790793 send_payment_along_path : SP ,
791794 ) -> Result < ( ) , Bolt12PaymentError >
@@ -819,6 +822,13 @@ impl OutboundPayments {
819822 hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
820823 }
821824
825+ if invoice. invoice_features ( ) . requires_unknown_bits_from ( & features) {
826+ self . abandon_payment (
827+ payment_id, PaymentFailureReason :: UnknownRequiredFeatures , pending_events,
828+ ) ;
829+ return Err ( Bolt12PaymentError :: UnknownRequiredFeatures ) ;
830+ }
831+
822832 let mut payment_params = PaymentParameters :: from_bolt12_invoice ( & invoice) ;
823833
824834 // Advance any blinded path where the introduction node is our node.
@@ -1951,7 +1961,7 @@ mod tests {
19511961 use crate :: events:: { Event , PathFailure , PaymentFailureReason } ;
19521962 use crate :: ln:: types:: PaymentHash ;
19531963 use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
1954- use crate :: ln:: features:: { ChannelFeatures , NodeFeatures } ;
1964+ use crate :: ln:: features:: { Bolt12InvoiceFeatures , ChannelFeatures , NodeFeatures } ;
19551965 use crate :: ln:: msgs:: { ErrorAction , LightningError } ;
19561966 use crate :: ln:: outbound_payment:: { Bolt12PaymentError , OutboundPayments , Retry , RetryableSendFailure , StaleExpiration } ;
19571967 #[ cfg( feature = "std" ) ]
@@ -2319,9 +2329,9 @@ mod tests {
23192329
23202330 assert_eq ! (
23212331 outbound_payments. send_payment_for_bolt12_invoice(
2322- & invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new ( ) , &&keys_manager ,
2323- &&keys_manager , & EmptyNodeIdLookUp { } , & secp_ctx , 0 , &&logger , & pending_events ,
2324- |_| panic!( )
2332+ & invoice, payment_id, &&router, vec![ ] , Bolt12InvoiceFeatures :: empty ( ) ,
2333+ || InFlightHtlcs :: new ( ) , &&keys_manager , &&keys_manager , & EmptyNodeIdLookUp { } ,
2334+ & secp_ctx , 0 , &&logger , & pending_events , |_| panic!( )
23252335 ) ,
23262336 Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: PaymentExpired ) ) ,
23272337 ) ;
@@ -2380,9 +2390,9 @@ mod tests {
23802390
23812391 assert_eq ! (
23822392 outbound_payments. send_payment_for_bolt12_invoice(
2383- & invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new ( ) , &&keys_manager ,
2384- &&keys_manager , & EmptyNodeIdLookUp { } , & secp_ctx , 0 , &&logger , & pending_events ,
2385- |_| panic!( )
2393+ & invoice, payment_id, &&router, vec![ ] , Bolt12InvoiceFeatures :: empty ( ) ,
2394+ || InFlightHtlcs :: new ( ) , &&keys_manager , &&keys_manager , & EmptyNodeIdLookUp { } ,
2395+ & secp_ctx , 0 , &&logger , & pending_events , |_| panic!( )
23862396 ) ,
23872397 Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: RouteNotFound ) ) ,
23882398 ) ;
@@ -2454,9 +2464,9 @@ mod tests {
24542464 assert ! ( !outbound_payments. has_pending_payments( ) ) ;
24552465 assert_eq ! (
24562466 outbound_payments. send_payment_for_bolt12_invoice(
2457- & invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new ( ) , &&keys_manager ,
2458- &&keys_manager , & EmptyNodeIdLookUp { } , & secp_ctx , 0 , &&logger , & pending_events ,
2459- |_| panic!( )
2467+ & invoice, payment_id, &&router, vec![ ] , Bolt12InvoiceFeatures :: empty ( ) ,
2468+ || InFlightHtlcs :: new ( ) , &&keys_manager , &&keys_manager , & EmptyNodeIdLookUp { } ,
2469+ & secp_ctx , 0 , &&logger , & pending_events , |_| panic!( )
24602470 ) ,
24612471 Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
24622472 ) ;
@@ -2472,9 +2482,9 @@ mod tests {
24722482
24732483 assert_eq ! (
24742484 outbound_payments. send_payment_for_bolt12_invoice(
2475- & invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new ( ) , &&keys_manager ,
2476- &&keys_manager , & EmptyNodeIdLookUp { } , & secp_ctx , 0 , &&logger , & pending_events ,
2477- |_| Ok ( ( ) )
2485+ & invoice, payment_id, &&router, vec![ ] , Bolt12InvoiceFeatures :: empty ( ) ,
2486+ || InFlightHtlcs :: new ( ) , &&keys_manager , &&keys_manager , & EmptyNodeIdLookUp { } ,
2487+ & secp_ctx , 0 , &&logger , & pending_events , |_| Ok ( ( ) )
24782488 ) ,
24792489 Ok ( ( ) ) ,
24802490 ) ;
@@ -2483,9 +2493,9 @@ mod tests {
24832493
24842494 assert_eq ! (
24852495 outbound_payments. send_payment_for_bolt12_invoice(
2486- & invoice, payment_id, &&router, vec![ ] , || InFlightHtlcs :: new ( ) , &&keys_manager ,
2487- &&keys_manager , & EmptyNodeIdLookUp { } , & secp_ctx , 0 , &&logger , & pending_events ,
2488- |_| panic!( )
2496+ & invoice, payment_id, &&router, vec![ ] , Bolt12InvoiceFeatures :: empty ( ) ,
2497+ || InFlightHtlcs :: new ( ) , &&keys_manager , &&keys_manager , & EmptyNodeIdLookUp { } ,
2498+ & secp_ctx , 0 , &&logger , & pending_events , |_| panic!( )
24892499 ) ,
24902500 Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
24912501 ) ;
0 commit comments