Skip to content

Commit a0fe395

Browse files
committed
fix Handle originally-v1 channel pre-splice reserve specially
1 parent f048d8c commit a0fe395

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10548,11 +10548,23 @@ where
1054810548
if post_balance >= post_channel_reserve_sats * 1000 {
1054910549
return Ok(());
1055010550
}
10551-
let pre_channel_reserve_sats =
10552-
get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
10553-
if pre_balance >= pre_channel_reserve_sats * 1000 {
10554-
// We're not allowed to dip below the reserve once we've been above.
10555-
return Err(post_channel_reserve_sats);
10551+
// We're not allowed to dip below the reserve once we've been above,
10552+
// check differently for originally v1 and v2 channels
10553+
if self.is_v2_established() {
10554+
let pre_channel_reserve_sats =
10555+
get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
10556+
if pre_balance >= pre_channel_reserve_sats * 1000 {
10557+
return Err(post_channel_reserve_sats);
10558+
}
10559+
} else {
10560+
if pre_balance >= self.funding.holder_selected_channel_reserve_satoshis * 1000 {
10561+
return Err(post_channel_reserve_sats);
10562+
}
10563+
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
10564+
if pre_balance >= cp_reserve * 1000 {
10565+
return Err(post_channel_reserve_sats);
10566+
}
10567+
}
1055610568
}
1055710569
// Make sure we either remain with the same balance or move towards the reserve.
1055810570
if post_balance >= pre_balance {

0 commit comments

Comments
 (0)