Skip to content

Commit 0eb4550

Browse files
committed
f misc fixes
1 parent 9484a1e commit 0eb4550

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9583,13 +9583,13 @@ fn accept_busted_but_better_fee() {
95839583
};
95849584
}
95859585

9586-
fn do_payment_with_custom_min_final_cltv_expiry(valid: bool, use_user_hash: bool) {
9586+
fn do_payment_with_custom_min_final_cltv_expiry(valid_delta: bool, use_user_hash: bool) {
95879587
let mut chanmon_cfgs = create_chanmon_cfgs(2);
95889588
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
95899589
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None]);
95909590
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
95919591
let min_final_cltv_expiry_delta = 120;
9592-
let final_cltv_expiry_delta = if valid { min_final_cltv_expiry_delta + 2 } else {
9592+
let final_cltv_expiry_delta = if valid_delta { min_final_cltv_expiry_delta + 2 } else {
95939593
min_final_cltv_expiry_delta - 2 };
95949594
let recv_value = 100_000;
95959595

@@ -9614,7 +9614,7 @@ fn do_payment_with_custom_min_final_cltv_expiry(valid: bool, use_user_hash: bool
96149614
commitment_signed_dance!(nodes[1], nodes[0], payment_event.commitment_msg, false);
96159615
expect_pending_htlcs_forwardable!(nodes[1]);
96169616

9617-
if valid {
9617+
if valid_delta {
96189618
expect_payment_claimable!(nodes[1], payment_hash, payment_secret, recv_value, if use_user_hash {
96199619
None } else { Some(payment_preimage) }, nodes[1].node.get_our_node_id());
96209620

lightning/src/ln/inbound_payment.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,19 @@ fn construct_metadata_bytes(min_value_msat: Option<u64>, payment_type: Method,
181181

182182
if min_final_cltv_expiry_delta.is_some() {
183183
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)
188192
} { return Err(()); }
189193
}
190194

191-
// Pack the 16 `min_final_cltv_expiry_delta` bits into the first two bytes of invoice expiry
192195
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();
194197
expiry_bytes[0] |= bytes[0];
195198
expiry_bytes[1] |= bytes[1];
196199
}
@@ -294,7 +297,6 @@ pub(super) fn verify<L: Deref>(payment_hash: PaymentHash, payment_data: &msgs::F
294297
}
295298
}
296299

297-
// Match again to check for custom `min_final_cltv_expiry_delta`.
298300
match payment_type_res {
299301
Ok(Method::UserPaymentHashCustomFinalCltv) | Ok(Method::LdkPaymentHashCustomFinalCltv) => {
300302
min_final_cltv_expiry_delta = Some(min_final_cltv_expiry_delta_from_metadata(metadata_bytes));

0 commit comments

Comments
 (0)