@@ -5115,54 +5115,6 @@ where
5115
5115
}
5116
5116
}
5117
5117
5118
- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
5119
- #[cfg(splicing)]
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
- let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
5122
- if post_balance >= post_channel_reserve {
5123
- return Ok(());
5124
- }
5125
- let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
5126
- if pre_balance >= pre_channel_reserve {
5127
- // We're not allowed to dip below the reserve once we've been above.
5128
- return Err(post_channel_reserve);
5129
- }
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
- }
5136
- }
5137
-
5138
- /// Check that balances meet the channel reserve requirements or violates them (below reserve).
5139
- /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
5140
- /// to check with new channel value (before being committed to it).
5141
- #[cfg(splicing)]
5142
- pub fn check_splice_balances_meet_v2_reserve_requirements(&self, self_balance_pre: u64, self_balance_post: u64, counterparty_balance_pre: u64, counterparty_balance_post: u64, channel_value_pre: u64, channel_value_post: u64) -> Result<(), ChannelError> {
5143
- let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
5144
- self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
5145
- self.holder_dust_limit_satoshis
5146
- );
5147
- if let Err(channel_reserve_self) = is_ok_self {
5148
- return Err(ChannelError::Warn(format!(
5149
- "Balance below reserve, mandated by holder, {} vs {}",
5150
- self_balance_post, channel_reserve_self,
5151
- )));
5152
- }
5153
- let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
5154
- counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
5155
- self.counterparty_dust_limit_satoshis
5156
- );
5157
- if let Err(channel_reserve_cp) = is_ok_cp {
5158
- return Err(ChannelError::Warn(format!(
5159
- "Balance below reserve mandated by counterparty, {} vs {}",
5160
- counterparty_balance_post, channel_reserve_cp,
5161
- )));
5162
- }
5163
- Ok(())
5164
- }
5165
-
5166
5118
/// Get the commitment tx fee for the local's (i.e. our) next commitment transaction based on the
5167
5119
/// number of pending HTLCs that are on track to be in our next commitment tx.
5168
5120
///
@@ -10463,7 +10415,7 @@ where
10463
10415
let (post_balance_self_less_fees, post_balance_counterparty_less_fees) = self.compute_balances_less_fees(post_channel_value, post_balance_self, true);
10464
10416
// Pre-check for reserve requirement
10465
10417
// This will also be checked later at tx_complete
10466
- let _res = self.context. check_splice_balances_meet_v2_reserve_requirements(
10418
+ let _res = self.check_splice_balances_meet_v2_reserve_requirements(
10467
10419
pre_balance_self_less_fees, post_balance_self_less_fees,
10468
10420
pre_balance_counterparty_less_fees, post_balance_counterparty_less_fees,
10469
10421
pre_channel_value, post_channel_value
@@ -10546,6 +10498,54 @@ where
10546
10498
Ok((None, None))
10547
10499
}
10548
10500
10501
+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
10502
+ #[cfg(splicing)]
10503
+ pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(&self, pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> Result<(), u64> {
10504
+ let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
10505
+ if post_balance >= post_channel_reserve {
10506
+ return Ok(());
10507
+ }
10508
+ let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
10509
+ if pre_balance >= pre_channel_reserve {
10510
+ // We're not allowed to dip below the reserve once we've been above.
10511
+ return Err(post_channel_reserve);
10512
+ }
10513
+ // Make sure we either remain with the same balance or move towards the reserve.
10514
+ if post_balance >= pre_balance {
10515
+ Ok(())
10516
+ } else {
10517
+ Err(post_channel_reserve)
10518
+ }
10519
+ }
10520
+
10521
+ /// Check that balances meet the channel reserve requirements or violates them (below reserve).
10522
+ /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
10523
+ /// to check with new channel value (before being committed to it).
10524
+ #[cfg(splicing)]
10525
+ pub fn check_splice_balances_meet_v2_reserve_requirements(&self, self_balance_pre: u64, self_balance_post: u64, counterparty_balance_pre: u64, counterparty_balance_post: u64, channel_value_pre: u64, channel_value_post: u64) -> Result<(), ChannelError> {
10526
+ let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
10527
+ self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
10528
+ self.context.holder_dust_limit_satoshis
10529
+ );
10530
+ if let Err(channel_reserve_self) = is_ok_self {
10531
+ return Err(ChannelError::Warn(format!(
10532
+ "Balance below reserve, mandated by holder, {} vs {}",
10533
+ self_balance_post, channel_reserve_self,
10534
+ )));
10535
+ }
10536
+ let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
10537
+ counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
10538
+ self.context.counterparty_dust_limit_satoshis
10539
+ );
10540
+ if let Err(channel_reserve_cp) = is_ok_cp {
10541
+ return Err(ChannelError::Warn(format!(
10542
+ "Balance below reserve mandated by counterparty, {} vs {}",
10543
+ counterparty_balance_post, channel_reserve_cp,
10544
+ )));
10545
+ }
10546
+ Ok(())
10547
+ }
10548
+
10549
10549
// Send stuff to our remote peers:
10550
10550
10551
10551
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
0 commit comments