@@ -5084,26 +5084,21 @@ where
5084
5084
pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64,
5085
5085
dust_limit: u64,
5086
5086
) -> Result<(), u64> {
5087
- if post_balance == 0 {
5088
- // 0 balance is fine
5089
- return Ok(());
5090
- }
5091
5087
let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
5092
5088
if post_balance >= post_channel_reserve {
5093
5089
return Ok(());
5094
5090
}
5095
- // post is not OK, check pre
5096
- if pre_balance == 0 {
5097
- // pre OK, post not -> not
5098
- return Err(post_channel_reserve);
5099
- }
5100
5091
let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
5101
5092
if pre_balance >= pre_channel_reserve {
5102
- // pre OK, post not -> not
5093
+ // We're not allowed to dip below the reserve once we've been above.
5103
5094
return Err(post_channel_reserve);
5104
5095
}
5105
- // post not OK, but so was pre -> OK
5106
- Ok(())
5096
+ // Make sure we either remain with the same balance or move towards the reserve.
5097
+ if post_balance >= pre_balance {
5098
+ Ok(())
5099
+ } else {
5100
+ Err(post_channel_reserve)
5101
+ }
5107
5102
}
5108
5103
5109
5104
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -10917,10 +10912,16 @@ where
10917
10912
}
10918
10913
10919
10914
/// Compute the channel balances (local & remote) by taking into account fees, anchor values, and dust limits.
10915
+ /// Pending HTLCs are not taken into account, this method should be used when there is no such,
10916
+ /// e.g. in quiscence state
10920
10917
#[cfg(splicing)]
10921
10918
fn compute_balances_less_fees(
10922
10919
&self, channel_value_sats: u64, value_to_self_msat: u64, is_local: bool,
10923
10920
) -> (u64, u64) {
10921
+ // We should get here only when there are no pending HTLCs, as they are not taken into account
10922
+ debug_assert!(self.context.pending_inbound_htlcs.is_empty());
10923
+ debug_assert!(self.context.pending_outbound_htlcs.is_empty());
10924
+
10924
10925
let feerate_per_kw = self.context.feerate_per_kw;
10925
10926
10926
10927
// compute 'raw' counterparty balance
0 commit comments