@@ -5079,26 +5079,21 @@ where
5079
5079
pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64,
5080
5080
dust_limit: u64,
5081
5081
) -> Result<(), u64> {
5082
- if post_balance == 0 {
5083
- // 0 balance is fine
5084
- return Ok(());
5085
- }
5086
5082
let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
5087
5083
if post_balance >= post_channel_reserve {
5088
5084
return Ok(());
5089
5085
}
5090
- // post is not OK, check pre
5091
- if pre_balance == 0 {
5092
- // pre OK, post not -> not
5093
- return Err(post_channel_reserve);
5094
- }
5095
5086
let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
5096
5087
if pre_balance >= pre_channel_reserve {
5097
- // pre OK, post not -> not
5088
+ // We're not allowed to dip below the reserve once we've been above.
5098
5089
return Err(post_channel_reserve);
5099
5090
}
5100
- // post not OK, but so was pre -> OK
5101
- Ok(())
5091
+ // Make sure we either remain with the same balance or move towards the reserve.
5092
+ if post_balance >= pre_balance {
5093
+ Ok(())
5094
+ } else {
5095
+ Err(post_channel_reserve)
5096
+ }
5102
5097
}
5103
5098
5104
5099
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -10603,10 +10598,16 @@ where
10603
10598
}
10604
10599
10605
10600
/// Compute the channel balances (local & remote) by taking into account fees, anchor values, and dust limits.
10601
+ /// Pending HTLCs are not taken into account, this method should be used when there is no such,
10602
+ /// e.g. in quiscence state
10606
10603
#[cfg(splicing)]
10607
10604
fn compute_balances_less_fees(
10608
10605
&self, channel_value_sats: u64, value_to_self_msat: u64, is_local: bool,
10609
10606
) -> (u64, u64) {
10607
+ // We should get here only when there are no pending HTLCs, as they are not taken into account
10608
+ debug_assert!(self.context.pending_inbound_htlcs.is_empty());
10609
+ debug_assert!(self.context.pending_outbound_htlcs.is_empty());
10610
+
10610
10611
let feerate_per_kw = self.context.feerate_per_kw;
10611
10612
10612
10613
// compute 'raw' counterparty balance
0 commit comments