@@ -5118,26 +5118,21 @@ where
51185118 /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
51195119 #[cfg(splicing)]
51205120 pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> Result<(), u64> {
5121- if post_balance == 0 {
5122- // 0 balance is fine
5123- return Ok(());
5124- }
51255121 let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
51265122 if post_balance >= post_channel_reserve {
51275123 return Ok(());
51285124 }
5129- // post is not OK, check pre
5130- if pre_balance == 0 {
5131- // pre OK, post not -> not
5132- return Err(post_channel_reserve);
5133- }
51345125 let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
51355126 if pre_balance >= pre_channel_reserve {
5136- // pre OK, post not -> not
5127+ // We're not allowed to dip below the reserve once we've been above.
51375128 return Err(post_channel_reserve);
51385129 }
5139- // post not OK, but so was pre -> OK
5140- Ok(())
5130+ // Make sure we either remain with the same balance or move towards the reserve.
5131+ if post_balance >= pre_balance {
5132+ Ok(())
5133+ } else {
5134+ Err(post_channel_reserve)
5135+ }
51415136 }
51425137
51435138 /// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -10403,8 +10398,14 @@ where
1040310398 }
1040410399
1040510400 /// Compute the channel balances (local & remote) by taking into account fees, anchor values, and dust limits.
10401+ /// Pending HTLCs are not taken into account, this method should be used when there is no such,
10402+ /// e.g. in quiscence state
1040610403 #[cfg(splicing)]
1040710404 fn compute_balances_less_fees(&self, channel_value_sats: u64, value_to_self_msat: u64, is_local: bool) -> (u64, u64) {
10405+ // We should get here only when there are no pending HTLCs, as they are not taken into account
10406+ debug_assert!(self.context.pending_inbound_htlcs.is_empty());
10407+ debug_assert!(self.context.pending_outbound_htlcs.is_empty());
10408+
1040810409 let feerate_per_kw = self.context.feerate_per_kw;
1040910410
1041010411 // compute 'raw' counterparty balance
0 commit comments