Skip to content

Commit ead89eb

Browse files
author
Antoine Riard
committed
Sanitize outgoing HTLC cltv_value
1 parent 9342ed3 commit ead89eb

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,8 +3538,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
35383538
return Err(ChannelError::Ignore("Cannot send value that would put us over their reserve value"));
35393539
}
35403540

3541-
//TODO: Check cltv_expiry? Do this in channel manager?
3542-
35433541
// Now update local state:
35443542
if (self.channel_state & (ChannelState::AwaitingRemoteRevoke as u32)) == (ChannelState::AwaitingRemoteRevoke as u32) {
35453543
self.holding_cell_htlc_updates.push(HTLCUpdateAwaitingACK::AddHTLC {

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,13 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref> ChannelMan
11101110
if msg.cltv_expiry > cur_height + CLTV_FAR_FAR_AWAY as u32 { // expiry_too_far
11111111
break Some(("CLTV expiry is too far in the future", 21, None));
11121112
}
1113+
// We should be safe against unintentional channel-closure by our onchain logic due to this later
1114+
// offering a LATENCY_GRACE_PERIOD_BLOCKS. But to make our policy coherent with reception, apply
1115+
// same delay.
1116+
if (*outgoing_cltv_value) as u64 <= (cur_height + CLTV_CLAIM_BUFFER + LATENCY_GRACE_PERIOD_BLOCKS) as u64 {
1117+
break Some(("Outgoing CLTV value is too close", 0x1000 | 14, Some(self.get_channel_update(chan).unwrap())));
1118+
}
1119+
11131120
break None;
11141121
}
11151122
{

0 commit comments

Comments
 (0)