@@ -5126,26 +5126,21 @@ where
5126
5126
pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64,
5127
5127
dust_limit: u64,
5128
5128
) -> Result<(), u64> {
5129
- if post_balance == 0 {
5130
- // 0 balance is fine
5131
- return Ok(());
5132
- }
5133
5129
let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
5134
5130
if post_balance >= post_channel_reserve {
5135
5131
return Ok(());
5136
5132
}
5137
- // post is not OK, check pre
5138
- if pre_balance == 0 {
5139
- // pre OK, post not -> not
5140
- return Err(post_channel_reserve);
5141
- }
5142
5133
let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
5143
5134
if pre_balance >= pre_channel_reserve {
5144
- // pre OK, post not -> not
5135
+ // We're not allowed to dip below the reserve once we've been above.
5145
5136
return Err(post_channel_reserve);
5146
5137
}
5147
- // post not OK, but so was pre -> OK
5148
- Ok(())
5138
+ // Make sure we either remain with the same balance or move towards the reserve.
5139
+ if post_balance >= pre_balance {
5140
+ Ok(())
5141
+ } else {
5142
+ Err(post_channel_reserve)
5143
+ }
5149
5144
}
5150
5145
5151
5146
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
@@ -10420,10 +10415,16 @@ where
10420
10415
}
10421
10416
10422
10417
/// Compute the channel balances (local & remote) by taking into account fees, anchor values, and dust limits.
10418
+ /// Pending HTLCs are not taken into account, this method should be used when there is no such,
10419
+ /// e.g. in quiscence state
10423
10420
#[cfg(splicing)]
10424
10421
fn compute_balances_less_fees(
10425
10422
&self, channel_value_sats: u64, value_to_self_msat: u64, is_local: bool,
10426
10423
) -> (u64, u64) {
10424
+ // We should get here only when there are no pending HTLCs, as they are not taken into account
10425
+ debug_assert!(self.context.pending_inbound_htlcs.is_empty());
10426
+ debug_assert!(self.context.pending_outbound_htlcs.is_empty());
10427
+
10427
10428
let feerate_per_kw = self.context.feerate_per_kw;
10428
10429
10429
10430
// compute 'raw' counterparty balance
0 commit comments