@@ -4269,26 +4269,21 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
4269
4269
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
4270
4270
#[cfg(splicing)]
4271
4271
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> {
4272
- if post_balance == 0 {
4273
- // 0 balance is fine
4274
- return Ok(());
4275
- }
4276
4272
let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
4277
4273
if post_balance >= post_channel_reserve {
4278
4274
return Ok(());
4279
4275
}
4280
- // post is not OK, check pre
4281
- if pre_balance == 0 {
4282
- // pre OK, post not -> not
4283
- return Err(post_channel_reserve);
4284
- }
4285
4276
let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
4286
4277
if pre_balance >= pre_channel_reserve {
4287
- // pre OK, post not -> not
4278
+ // We're not allowed to dip below the reserve once we've been above.
4288
4279
return Err(post_channel_reserve);
4289
4280
}
4290
- // post not OK, but so was pre -> OK
4291
- Ok(())
4281
+ // Make sure we either remain with the same balance or move towards the reserve.
4282
+ if post_balance >= pre_balance {
4283
+ Ok(())
4284
+ } else {
4285
+ Err(post_channel_reserve)
4286
+ }
4292
4287
}
4293
4288
4294
4289
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -8611,8 +8606,14 @@ impl<SP: Deref> FundedChannel<SP> where
8611
8606
}
8612
8607
8613
8608
/// Compute the channel balances (local & remote) by taking into account fees, anchor values, and dust limits.
8609
+ /// Pending HTLCs are not taken into account, this method should be used when there is no such,
8610
+ /// e.g. in quiscence state
8614
8611
#[cfg(splicing)]
8615
8612
fn compute_balances_less_fees(&self, channel_value_sats: u64, value_to_self_msat: u64, is_local: bool) -> (u64, u64) {
8613
+ // We should get here only when there are no pending HTLCs, as they are not taken into account
8614
+ debug_assert!(self.context.pending_inbound_htlcs.is_empty());
8615
+ debug_assert!(self.context.pending_outbound_htlcs.is_empty());
8616
+
8616
8617
let feerate_per_kw = self.context.feerate_per_kw;
8617
8618
8618
8619
// compute 'raw' counterparty balance
0 commit comments