Skip to content

Commit 1bb4f44

Browse files
committed
Fix reserve check on HTLC receive/send
1 parent 298557c commit 1bb4f44

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/ln/channel.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,8 +1012,10 @@ impl Channel {
10121012
if htlc_inbound_value_msat + msg.amount_msat > Channel::get_our_max_htlc_value_in_flight_msat(self.channel_value_satoshis) {
10131013
return Err(HandleError{err: "Remote HTLC add would put them over their max HTLC value in flight", msg: None});
10141014
}
1015-
// Check our_channel_reserve_satoshis:
1016-
if htlc_inbound_value_msat + htlc_outbound_value_msat + msg.amount_msat > (self.channel_value_satoshis - Channel::get_our_channel_reserve_satoshis(self.channel_value_satoshis)) * 1000 {
1015+
// Check our_channel_reserve_satoshis (we're getting paid, so they have to at least meet
1016+
// the reserve_satoshis we told them to always have as direct payment so that they lose
1017+
// something if we punish them for broadcasting an old state).
1018+
if htlc_inbound_value_msat + htlc_outbound_value_msat + msg.amount_msat + self.value_to_self_msat > (self.channel_value_satoshis - Channel::get_our_channel_reserve_satoshis(self.channel_value_satoshis)) * 1000 {
10171019
return Err(HandleError{err: "Remote HTLC add would put them over their reserve value", msg: None});
10181020
}
10191021
if self.next_remote_htlc_id != msg.htlc_id {
@@ -1591,7 +1593,7 @@ impl Channel {
15911593
return Err(HandleError{err: "Cannot send value that would put us over our max HTLC value in flight", msg: None});
15921594
}
15931595
// Check their_channel_reserve_satoshis:
1594-
if htlc_outbound_value_msat + amount_msat > (self.channel_value_satoshis - self.their_channel_reserve_satoshis) * 1000 - htlc_inbound_value_msat {
1596+
if htlc_inbound_value_msat + htlc_outbound_value_msat + amount_msat + (self.channel_value_satoshis * 1000 - self.value_to_self_msat) > (self.channel_value_satoshis - self.their_channel_reserve_satoshis) * 1000 {
15951597
return Err(HandleError{err: "Cannot send value that would put us over our reserve value", msg: None});
15961598
}
15971599

0 commit comments

Comments
 (0)