@@ -5079,26 +5079,21 @@ where
50795079 pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64,
50805080 dust_limit: u64,
50815081 ) -> Result<(), u64> {
5082- if post_balance == 0 {
5083- // 0 balance is fine
5084- return Ok(());
5085- }
50865082 let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
50875083 if post_balance >= post_channel_reserve {
50885084 return Ok(());
50895085 }
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- }
50955086 let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
50965087 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.
50985089 return Err(post_channel_reserve);
50995090 }
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+ }
51025097 }
51035098
51045099 /// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -10603,10 +10598,16 @@ where
1060310598 }
1060410599
1060510600 /// 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
1060610603 #[cfg(splicing)]
1060710604 fn compute_balances_less_fees(
1060810605 &self, channel_value_sats: u64, value_to_self_msat: u64, is_local: bool,
1060910606 ) -> (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+
1061010611 let feerate_per_kw = self.context.feerate_per_kw;
1061110612
1061210613 // compute 'raw' counterparty balance
0 commit comments