@@ -154,11 +154,11 @@ pub const DEFAULT_EXPIRY_TIME: u64 = 3600;
154154/// Default minimum final CLTV expiry as defined by [BOLT 11].
155155///
156156/// Note that this is *not* the same value as rust-lightning's minimum CLTV expiry, which is
157- /// provided in [`MIN_FINAL_CLTV_EXPIRY `].
157+ /// provided in [`MIN_FINAL_CLTV_EXPIRY_DELTA `].
158158///
159159/// [BOLT 11]: https://github.com/lightning/bolts/blob/master/11-payment-encoding.md
160- /// [`MIN_FINAL_CLTV_EXPIRY `]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY
161- pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY : u64 = 18 ;
160+ /// [`MIN_FINAL_CLTV_EXPIRY_DELTA `]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
161+ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA : u64 = 18 ;
162162
163163/// Builder for `Invoice`s. It's the most convenient and advised way to use this library. It ensures
164164/// that only a semantically and syntactically correct Invoice can be built using it.
@@ -199,7 +199,7 @@ pub const DEFAULT_MIN_FINAL_CLTV_EXPIRY: u64 = 18;
199199/// .payment_hash(payment_hash)
200200/// .payment_secret(payment_secret)
201201/// .current_timestamp()
202- /// .min_final_cltv_expiry (144)
202+ /// .min_final_cltv_expiry_delta (144)
203203/// .build_signed(|hash| {
204204/// Secp256k1::new().sign_ecdsa_recoverable(hash, &private_key)
205205/// })
@@ -410,7 +410,7 @@ pub enum TaggedField {
410410 PayeePubKey ( PayeePubKey ) ,
411411 DescriptionHash ( Sha256 ) ,
412412 ExpiryTime ( ExpiryTime ) ,
413- MinFinalCltvExpiry ( MinFinalCltvExpiry ) ,
413+ MinFinalCltvExpiryDelta ( MinFinalCltvExpiryDelta ) ,
414414 Fallback ( Fallback ) ,
415415 PrivateRoute ( PrivateRoute ) ,
416416 PaymentSecret ( PaymentSecret ) ,
@@ -438,9 +438,9 @@ pub struct PayeePubKey(pub PublicKey);
438438#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
439439pub struct ExpiryTime ( Duration ) ;
440440
441- /// `min_final_cltv_expiry ` to use for the last HTLC in the route
441+ /// `min_final_cltv_expiry_delta ` to use for the last HTLC in the route
442442#[ derive( Clone , Debug , Hash , Eq , PartialEq ) ]
443- pub struct MinFinalCltvExpiry ( pub u64 ) ;
443+ pub struct MinFinalCltvExpiryDelta ( pub u64 ) ;
444444
445445// TODO: better types instead onf byte arrays
446446/// Fallback address in case no LN payment is possible
@@ -475,7 +475,7 @@ pub mod constants {
475475 pub const TAG_PAYEE_PUB_KEY : u8 = 19 ;
476476 pub const TAG_DESCRIPTION_HASH : u8 = 23 ;
477477 pub const TAG_EXPIRY_TIME : u8 = 6 ;
478- pub const TAG_MIN_FINAL_CLTV_EXPIRY : u8 = 24 ;
478+ pub const TAG_MIN_FINAL_CLTV_EXPIRY_DELTA : u8 = 24 ;
479479 pub const TAG_FALLBACK : u8 = 9 ;
480480 pub const TAG_PRIVATE_ROUTE : u8 = 3 ;
481481 pub const TAG_PAYMENT_SECRET : u8 = 16 ;
@@ -654,9 +654,9 @@ impl<D: tb::Bool, H: tb::Bool, C: tb::Bool, S: tb::Bool> InvoiceBuilder<D, H, tb
654654}
655655
656656impl < D : tb:: Bool , H : tb:: Bool , T : tb:: Bool , S : tb:: Bool > InvoiceBuilder < D , H , T , tb:: False , S > {
657- /// Sets `min_final_cltv_expiry `.
658- pub fn min_final_cltv_expiry ( mut self , min_final_cltv_expiry : u64 ) -> InvoiceBuilder < D , H , T , tb:: True , S > {
659- self . tagged_fields . push ( TaggedField :: MinFinalCltvExpiry ( MinFinalCltvExpiry ( min_final_cltv_expiry ) ) ) ;
657+ /// Sets `min_final_cltv_expiry_delta `.
658+ pub fn min_final_cltv_expiry_delta ( mut self , min_final_cltv_expiry_delta : u64 ) -> InvoiceBuilder < D , H , T , tb:: True , S > {
659+ self . tagged_fields . push ( TaggedField :: MinFinalCltvExpiryDelta ( MinFinalCltvExpiryDelta ( min_final_cltv_expiry_delta ) ) ) ;
660660 self . set_flags ( )
661661 }
662662}
@@ -929,8 +929,8 @@ impl RawInvoice {
929929 find_extract ! ( self . known_tagged_fields( ) , TaggedField :: ExpiryTime ( ref x) , x)
930930 }
931931
932- pub fn min_final_cltv_expiry ( & self ) -> Option < & MinFinalCltvExpiry > {
933- find_extract ! ( self . known_tagged_fields( ) , TaggedField :: MinFinalCltvExpiry ( ref x) , x)
932+ pub fn min_final_cltv_expiry_delta ( & self ) -> Option < & MinFinalCltvExpiryDelta > {
933+ find_extract ! ( self . known_tagged_fields( ) , TaggedField :: MinFinalCltvExpiryDelta ( ref x) , x)
934934 }
935935
936936 pub fn payment_secret ( & self ) -> Option < & PaymentSecret > {
@@ -1243,12 +1243,12 @@ impl Invoice {
12431243 . unwrap_or_else ( || Duration :: new ( u64:: max_value ( ) , 1_000_000_000 - 1 ) ) < at_time
12441244 }
12451245
1246- /// Returns the invoice's `min_final_cltv_expiry ` time, if present, otherwise
1247- /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY `].
1248- pub fn min_final_cltv_expiry ( & self ) -> u64 {
1249- self . signed_invoice . min_final_cltv_expiry ( )
1246+ /// Returns the invoice's `min_final_cltv_expiry_delta ` time, if present, otherwise
1247+ /// [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA `].
1248+ pub fn min_final_cltv_expiry_delta ( & self ) -> u64 {
1249+ self . signed_invoice . min_final_cltv_expiry_delta ( )
12501250 . map ( |x| x. 0 )
1251- . unwrap_or ( DEFAULT_MIN_FINAL_CLTV_EXPIRY )
1251+ . unwrap_or ( DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA )
12521252 }
12531253
12541254 /// Returns a list of all fallback addresses
@@ -1301,7 +1301,7 @@ impl TaggedField {
13011301 TaggedField :: PayeePubKey ( _) => constants:: TAG_PAYEE_PUB_KEY ,
13021302 TaggedField :: DescriptionHash ( _) => constants:: TAG_DESCRIPTION_HASH ,
13031303 TaggedField :: ExpiryTime ( _) => constants:: TAG_EXPIRY_TIME ,
1304- TaggedField :: MinFinalCltvExpiry ( _) => constants:: TAG_MIN_FINAL_CLTV_EXPIRY ,
1304+ TaggedField :: MinFinalCltvExpiryDelta ( _) => constants:: TAG_MIN_FINAL_CLTV_EXPIRY_DELTA ,
13051305 TaggedField :: Fallback ( _) => constants:: TAG_FALLBACK ,
13061306 TaggedField :: PrivateRoute ( _) => constants:: TAG_PRIVATE_ROUTE ,
13071307 TaggedField :: PaymentSecret ( _) => constants:: TAG_PAYMENT_SECRET ,
@@ -1448,6 +1448,11 @@ pub enum CreationError {
14481448 ///
14491449 /// [phantom invoices]: crate::utils::create_phantom_invoice
14501450 MissingRouteHints ,
1451+
1452+ /// The provided `min_final_cltv_expiry_delta` was less than [`MIN_FINAL_CLTV_EXPIRY_DELTA`].
1453+ ///
1454+ /// [`MIN_FINAL_CLTV_EXPIRY_DELTA`]: lightning::ln::channelmanager::MIN_FINAL_CLTV_EXPIRY_DELTA
1455+ MinFinalCltvExpiryDeltaTooShort ,
14511456}
14521457
14531458impl Display for CreationError {
@@ -1458,6 +1463,8 @@ impl Display for CreationError {
14581463 CreationError :: TimestampOutOfBounds => f. write_str ( "The Unix timestamp of the supplied date is less than zero or greater than 35-bits" ) ,
14591464 CreationError :: InvalidAmount => f. write_str ( "The supplied millisatoshi amount was greater than the total bitcoin supply" ) ,
14601465 CreationError :: MissingRouteHints => f. write_str ( "The invoice required route hints and they weren't provided" ) ,
1466+ CreationError :: MinFinalCltvExpiryDeltaTooShort => f. write_str (
1467+ "The supplied final CLTV expiry delta was less than LDK's `MIN_FINAL_CLTV_EXPIRY_DELTA`" ) ,
14611468 }
14621469 }
14631470}
@@ -1804,7 +1811,7 @@ mod test {
18041811 let builder = InvoiceBuilder :: new ( Currency :: Bitcoin )
18051812 . payment_hash ( sha256:: Hash :: from_slice ( & [ 0 ; 32 ] [ ..] ) . unwrap ( ) )
18061813 . duration_since_epoch ( Duration :: from_secs ( 1234567 ) )
1807- . min_final_cltv_expiry ( 144 ) ;
1814+ . min_final_cltv_expiry_delta ( 144 ) ;
18081815
18091816 let too_long_string = String :: from_iter (
18101817 ( 0 ..1024 ) . map ( |_| '?' )
@@ -1922,7 +1929,7 @@ mod test {
19221929 . duration_since_epoch ( Duration :: from_secs ( 1234567 ) )
19231930 . payee_pub_key ( public_key. clone ( ) )
19241931 . expiry_time ( Duration :: from_secs ( 54321 ) )
1925- . min_final_cltv_expiry ( 144 )
1932+ . min_final_cltv_expiry_delta ( 144 )
19261933 . fallback ( Fallback :: PubKeyHash ( [ 0 ; 20 ] ) )
19271934 . private_route ( route_1. clone ( ) )
19281935 . private_route ( route_2. clone ( ) )
@@ -1948,7 +1955,7 @@ mod test {
19481955 ) ;
19491956 assert_eq ! ( invoice. payee_pub_key( ) , Some ( & public_key) ) ;
19501957 assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( 54321 ) ) ;
1951- assert_eq ! ( invoice. min_final_cltv_expiry ( ) , 144 ) ;
1958+ assert_eq ! ( invoice. min_final_cltv_expiry_delta ( ) , 144 ) ;
19521959 assert_eq ! ( invoice. fallbacks( ) , vec![ & Fallback :: PubKeyHash ( [ 0 ; 20 ] ) ] ) ;
19531960 assert_eq ! ( invoice. private_routes( ) , vec![ & PrivateRoute ( route_1) , & PrivateRoute ( route_2) ] ) ;
19541961 assert_eq ! (
@@ -1989,7 +1996,7 @@ mod test {
19891996 . unwrap ( ) ;
19901997 let invoice = Invoice :: from_signed ( signed_invoice) . unwrap ( ) ;
19911998
1992- assert_eq ! ( invoice. min_final_cltv_expiry ( ) , DEFAULT_MIN_FINAL_CLTV_EXPIRY ) ;
1999+ assert_eq ! ( invoice. min_final_cltv_expiry_delta ( ) , DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA ) ;
19932000 assert_eq ! ( invoice. expiry_time( ) , Duration :: from_secs( DEFAULT_EXPIRY_TIME ) ) ;
19942001 assert ! ( !invoice. would_expire( Duration :: from_secs( 1234568 ) ) ) ;
19952002 }
0 commit comments