@@ -5084,26 +5084,21 @@ where
50845084 pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64,
50855085 dust_limit: u64,
50865086 ) -> Result<(), u64> {
5087- if post_balance == 0 {
5088- // 0 balance is fine
5089- return Ok(());
5090- }
50915087 let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
50925088 if post_balance >= post_channel_reserve {
50935089 return Ok(());
50945090 }
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- }
51005091 let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
51015092 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.
51035094 return Err(post_channel_reserve);
51045095 }
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+ }
51075102 }
51085103
51095104 /// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -10917,10 +10912,16 @@ where
1091710912 }
1091810913
1091910914 /// 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
1092010917 #[cfg(splicing)]
1092110918 fn compute_balances_less_fees(
1092210919 &self, channel_value_sats: u64, value_to_self_msat: u64, is_local: bool,
1092310920 ) -> (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+
1092410925 let feerate_per_kw = self.context.feerate_per_kw;
1092510926
1092610927 // compute 'raw' counterparty balance
0 commit comments