Skip to content

Commit 7ec3073

Browse files
committed
Fix in checking incoming cltv_expry bounds
1 parent 28603ed commit 7ec3073

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/ln/channelmanager.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,9 @@ impl ChannelManager {
906906
}
907907
};
908908

909-
//TODO: Check that msg.cltv_expiry is within acceptable bounds!
910-
911909
let pending_forward_info = if next_hop_data.hmac == [0; 32] {
912910
// OUR PAYMENT!
913-
if (msg.cltv_expiry as u64) < self.latest_block_height.load(Ordering::Acquire) as u64 + FINAL_NODE_TIMEOUT as u64 { // final_expiry_too_soon
911+
if (msg.cltv_expiry as u64) < self.latest_block_height.load(Ordering::Acquire) as u64 + (CLTV_CLAIM_BUFFER + HTLC_FAIL_TIMEOUT_BLOCKS) as u64 { // final_expiry_too_soon
914912
return_err!("The CLTV expiry is too soon to handle", 17, &[0;0]);
915913
}
916914
if next_hop_data.data.outgoing_cltv_value != msg.cltv_expiry {
@@ -1002,7 +1000,8 @@ impl ChannelManager {
10021000
break Some(("Forwarding node has tampered with the intended HTLC values or origin node has an obsolete cltv_expiry_delta", 0x1000 | 13, self.get_channel_update(chan).unwrap()));
10031001
}
10041002
let cur_height = self.latest_block_height.load(Ordering::Acquire) as u32 + 1;
1005-
if msg.cltv_expiry <= cur_height + 3 as u32 { // expiry_too_soon
1003+
// We want to have at least HTLC_FAIL_TIMEOUT_BLOCKS to fail prior to going on chain CLAIM_BUFFER blocks before expiration
1004+
if msg.cltv_expiry <= cur_height + CLTV_CLAIM_BUFFER + HTLC_FAIL_TIMEOUT_BLOCKS as u32 { // expiry_too_soon
10061005
break Some(("CLTV expiry is too close", 0x1000 | 14, self.get_channel_update(chan).unwrap()));
10071006
}
10081007
if msg.cltv_expiry > cur_height + CLTV_FAR_FAR_AWAY as u32 { // expiry_too_far

0 commit comments

Comments
 (0)