Skip to content

Commit dbc2210

Browse files
committed
fix Handle originally-v1 channel pre-splice reserve specially
1 parent 64e381b commit dbc2210

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
@@ -11099,11 +11099,23 @@ where
1109911099
if post_balance >= post_channel_reserve_sats * 1000 {
1110011100
return Ok(());
1110111101
}
11102-
let pre_channel_reserve_sats =
11103-
get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
11104-
if pre_balance >= pre_channel_reserve_sats * 1000 {
11105-
// We're not allowed to dip below the reserve once we've been above.
11106-
return Err(post_channel_reserve_sats);
11102+
// We're not allowed to dip below the reserve once we've been above,
11103+
// check differently for originally v1 and v2 channels
11104+
if self.is_v2_established() {
11105+
let pre_channel_reserve_sats =
11106+
get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
11107+
if pre_balance >= pre_channel_reserve_sats * 1000 {
11108+
return Err(post_channel_reserve_sats);
11109+
}
11110+
} else {
11111+
if pre_balance >= self.funding.holder_selected_channel_reserve_satoshis * 1000 {
11112+
return Err(post_channel_reserve_sats);
11113+
}
11114+
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
11115+
if pre_balance >= cp_reserve * 1000 {
11116+
return Err(post_channel_reserve_sats);
11117+
}
11118+
}
1110711119
}
1110811120
// Make sure we either remain with the same balance or move towards the reserve.
1110911121
if post_balance >= pre_balance {

0 commit comments

Comments
 (0)