@@ -5118,26 +5118,21 @@ where
5118
5118
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
5119
5119
#[cfg(splicing)]
5120
5120
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
- }
5125
5121
let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
5126
5122
if post_balance >= post_channel_reserve {
5127
5123
return Ok(());
5128
5124
}
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
- }
5134
5125
let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
5135
5126
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.
5137
5128
return Err(post_channel_reserve);
5138
5129
}
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
+ }
5141
5136
}
5142
5137
5143
5138
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -10403,8 +10398,14 @@ where
10403
10398
}
10404
10399
10405
10400
/// 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
10406
10403
#[cfg(splicing)]
10407
10404
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
+
10408
10409
let feerate_per_kw = self.context.feerate_per_kw;
10409
10410
10410
10411
// compute 'raw' counterparty balance
0 commit comments