@@ -181,16 +181,19 @@ fn construct_metadata_bytes(min_value_msat: Option<u64>, payment_type: Method,
181
181
182
182
if min_final_cltv_expiry_delta. is_some ( ) {
183
183
if {
184
- // `min_value_msat` should fit in 61 bits as an unsigned integer.
185
- min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > ( ( 1 << 61 ) - 1 ) ||
186
- // `expiry_timestamp` should fit in 48 bits as an unsigned integer.
187
- expiry_timestamp > ( ( 1 << 48 ) - 1 )
184
+ // `min_value_msat` should fit in (64 bits - 3 payment type bits =) 61 bits as an unsigned integer.
185
+ // This should leave us with a maximum value greater than the 21M BTC supply cap anyway.
186
+ min_value_msat. is_some ( ) && min_value_msat. unwrap ( ) > ( ( 1u64 << 61 ) - 1 ) ||
187
+ // `expiry_timestamp` should fit in (64 bits - 2 delta bytes =) 48 bits as an unsigned integer.
188
+ // Bitcoin's block header timestamps are actually `u32`s, so we're technically already limited to
189
+ // the much smaller maximum timestamp of `u32::MAX` for now, but we check the u64 `expiry_timestamp`
190
+ // for future-proofing.
191
+ expiry_timestamp > ( ( 1u64 << 48 ) - 1 )
188
192
} { return Err ( ( ) ) ; }
189
193
}
190
194
191
- // Pack the 16 `min_final_cltv_expiry_delta` bits into the first two bytes of invoice expiry
192
195
if let Some ( min_final_cltv_expiry_delta) = min_final_cltv_expiry_delta {
193
- let bytes = ( min_final_cltv_expiry_delta as u16 ) . to_be_bytes ( ) ;
196
+ let bytes = min_final_cltv_expiry_delta. to_be_bytes ( ) ;
194
197
expiry_bytes[ 0 ] |= bytes[ 0 ] ;
195
198
expiry_bytes[ 1 ] |= bytes[ 1 ] ;
196
199
}
@@ -294,7 +297,6 @@ pub(super) fn verify<L: Deref>(payment_hash: PaymentHash, payment_data: &msgs::F
294
297
}
295
298
}
296
299
297
- // Match again to check for custom `min_final_cltv_expiry_delta`.
298
300
match payment_type_res {
299
301
Ok ( Method :: UserPaymentHashCustomFinalCltv ) | Ok ( Method :: LdkPaymentHashCustomFinalCltv ) => {
300
302
min_final_cltv_expiry_delta = Some ( min_final_cltv_expiry_delta_from_metadata ( metadata_bytes) ) ;
0 commit comments