@@ -19,6 +19,7 @@ use crate::events::{self, PaymentFailureReason};
19
19
use crate :: ln:: types:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
20
20
use crate :: ln:: channel_state:: ChannelDetails ;
21
21
use crate :: ln:: channelmanager:: { EventCompletionAction , HTLCSource , PaymentId } ;
22
+ use crate :: ln:: features:: Bolt12InvoiceFeatures ;
22
23
use crate :: ln:: onion_utils;
23
24
use crate :: ln:: onion_utils:: { DecodedOnionFailure , HTLCFailReason } ;
24
25
use crate :: offers:: invoice:: Bolt12Invoice ;
@@ -510,6 +511,8 @@ pub enum Bolt12PaymentError {
510
511
UnexpectedInvoice ,
511
512
/// Payment for an invoice with the corresponding [`PaymentId`] was already initiated.
512
513
DuplicateInvoice ,
514
+ /// The invoice was valid for the corresponding [`PaymentId`], but required unknown features.
515
+ UnknownRequiredFeatures ,
513
516
/// The invoice was valid for the corresponding [`PaymentId`], but sending the payment failed.
514
517
SendingFailed ( RetryableSendFailure ) ,
515
518
}
@@ -783,9 +786,9 @@ impl OutboundPayments {
783
786
R : Deref , ES : Deref , NS : Deref , NL : Deref , IH , SP , L : Deref
784
787
> (
785
788
& 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 ,
789
792
pending_events : & Mutex < VecDeque < ( events:: Event , Option < EventCompletionAction > ) > > ,
790
793
send_payment_along_path : SP ,
791
794
) -> Result < ( ) , Bolt12PaymentError >
@@ -819,6 +822,13 @@ impl OutboundPayments {
819
822
hash_map:: Entry :: Vacant ( _) => return Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
820
823
}
821
824
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
+
822
832
let mut payment_params = PaymentParameters :: from_bolt12_invoice ( & invoice) ;
823
833
824
834
// Advance any blinded path where the introduction node is our node.
@@ -1951,7 +1961,7 @@ mod tests {
1951
1961
use crate :: events:: { Event , PathFailure , PaymentFailureReason } ;
1952
1962
use crate :: ln:: types:: PaymentHash ;
1953
1963
use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
1954
- use crate :: ln:: features:: { ChannelFeatures , NodeFeatures } ;
1964
+ use crate :: ln:: features:: { Bolt12InvoiceFeatures , ChannelFeatures , NodeFeatures } ;
1955
1965
use crate :: ln:: msgs:: { ErrorAction , LightningError } ;
1956
1966
use crate :: ln:: outbound_payment:: { Bolt12PaymentError , OutboundPayments , Retry , RetryableSendFailure , StaleExpiration } ;
1957
1967
#[ cfg( feature = "std" ) ]
@@ -2319,9 +2329,9 @@ mod tests {
2319
2329
2320
2330
assert_eq ! (
2321
2331
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!( )
2325
2335
) ,
2326
2336
Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: PaymentExpired ) ) ,
2327
2337
) ;
@@ -2380,9 +2390,9 @@ mod tests {
2380
2390
2381
2391
assert_eq ! (
2382
2392
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!( )
2386
2396
) ,
2387
2397
Err ( Bolt12PaymentError :: SendingFailed ( RetryableSendFailure :: RouteNotFound ) ) ,
2388
2398
) ;
@@ -2454,9 +2464,9 @@ mod tests {
2454
2464
assert ! ( !outbound_payments. has_pending_payments( ) ) ;
2455
2465
assert_eq ! (
2456
2466
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!( )
2460
2470
) ,
2461
2471
Err ( Bolt12PaymentError :: UnexpectedInvoice ) ,
2462
2472
) ;
@@ -2472,9 +2482,9 @@ mod tests {
2472
2482
2473
2483
assert_eq ! (
2474
2484
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 ( ( ) )
2478
2488
) ,
2479
2489
Ok ( ( ) ) ,
2480
2490
) ;
@@ -2483,9 +2493,9 @@ mod tests {
2483
2493
2484
2494
assert_eq ! (
2485
2495
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!( )
2489
2499
) ,
2490
2500
Err ( Bolt12PaymentError :: DuplicateInvoice ) ,
2491
2501
) ;
0 commit comments