@@ -5073,66 +5073,6 @@ where
5073
5073
}
5074
5074
}
5075
5075
5076
- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
5077
- #[cfg(splicing)]
5078
- pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(
5079
- pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64,
5080
- dust_limit: u64,
5081
- ) -> Result<(), u64> {
5082
- let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
5083
- if post_balance >= post_channel_reserve {
5084
- return Ok(());
5085
- }
5086
- let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
5087
- if pre_balance >= pre_channel_reserve {
5088
- // We're not allowed to dip below the reserve once we've been above.
5089
- return Err(post_channel_reserve);
5090
- }
5091
- // Make sure we either remain with the same balance or move towards the reserve.
5092
- if post_balance >= pre_balance {
5093
- Ok(())
5094
- } else {
5095
- Err(post_channel_reserve)
5096
- }
5097
- }
5098
-
5099
- /// Check that balances meet the channel reserve requirements or violates them (below reserve).
5100
- /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
5101
- /// to check with new channel value (before being committed to it).
5102
- #[cfg(splicing)]
5103
- pub fn check_splice_balances_meet_v2_reserve_requirements(
5104
- &self, self_balance_pre: u64, self_balance_post: u64, counterparty_balance_pre: u64,
5105
- counterparty_balance_post: u64, channel_value_pre: u64, channel_value_post: u64,
5106
- ) -> Result<(), ChannelError> {
5107
- let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
5108
- self_balance_pre,
5109
- self_balance_post,
5110
- channel_value_pre,
5111
- channel_value_post,
5112
- self.holder_dust_limit_satoshis,
5113
- );
5114
- if let Err(channel_reserve_self) = is_ok_self {
5115
- return Err(ChannelError::Warn(format!(
5116
- "Balance below reserve, mandated by holder, {} vs {}",
5117
- self_balance_post, channel_reserve_self,
5118
- )));
5119
- }
5120
- let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
5121
- counterparty_balance_pre,
5122
- counterparty_balance_post,
5123
- channel_value_pre,
5124
- channel_value_post,
5125
- self.counterparty_dust_limit_satoshis,
5126
- );
5127
- if let Err(channel_reserve_cp) = is_ok_cp {
5128
- return Err(ChannelError::Warn(format!(
5129
- "Balance below reserve mandated by counterparty, {} vs {}",
5130
- counterparty_balance_post, channel_reserve_cp,
5131
- )));
5132
- }
5133
- Ok(())
5134
- }
5135
-
5136
5076
/// Get the commitment tx fee for the local's (i.e. our) next commitment transaction based on the
5137
5077
/// number of pending HTLCs that are on track to be in our next commitment tx.
5138
5078
///
@@ -10692,7 +10632,7 @@ where
10692
10632
self.compute_balances_less_fees(post_channel_value, post_balance_self, true);
10693
10633
// Pre-check for reserve requirement
10694
10634
// This will also be checked later at tx_complete
10695
- let _res = self.context. check_splice_balances_meet_v2_reserve_requirements(
10635
+ let _res = self.check_splice_balances_meet_v2_reserve_requirements(
10696
10636
pre_balance_self_less_fees,
10697
10637
post_balance_self_less_fees,
10698
10638
pre_balance_counterparty_less_fees,
@@ -10755,6 +10695,68 @@ where
10755
10695
))
10756
10696
}
10757
10697
10698
+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
10699
+ #[cfg(splicing)]
10700
+ pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(
10701
+ &self, pre_balance: u64, post_balance: u64, pre_channel_value: u64,
10702
+ post_channel_value: u64, dust_limit: u64,
10703
+ ) -> Result<(), u64> {
10704
+ let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
10705
+ if post_balance >= post_channel_reserve {
10706
+ return Ok(());
10707
+ }
10708
+ let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
10709
+ if pre_balance >= pre_channel_reserve {
10710
+ // We're not allowed to dip below the reserve once we've been above.
10711
+ return Err(post_channel_reserve);
10712
+ }
10713
+ // Make sure we either remain with the same balance or move towards the reserve.
10714
+ if post_balance >= pre_balance {
10715
+ Ok(())
10716
+ } else {
10717
+ Err(post_channel_reserve)
10718
+ }
10719
+ }
10720
+
10721
+ /// Check that balances meet the channel reserve requirements or violates them (below reserve).
10722
+ /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
10723
+ /// to check with new channel value (before being committed to it).
10724
+ #[cfg(splicing)]
10725
+ pub fn check_splice_balances_meet_v2_reserve_requirements(
10726
+ &self, self_balance_pre: u64, self_balance_post: u64, counterparty_balance_pre: u64,
10727
+ counterparty_balance_post: u64, channel_value_pre: u64, channel_value_post: u64,
10728
+ ) -> Result<(), ChannelError> {
10729
+ let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
10730
+ self_balance_pre,
10731
+ self_balance_post,
10732
+ channel_value_pre,
10733
+ channel_value_post,
10734
+ self.context.holder_dust_limit_satoshis,
10735
+ );
10736
+ if let Err(channel_reserve_self) = is_ok_self {
10737
+ return Err(ChannelError::Warn(format!(
10738
+ "Balance below reserve, mandated by holder, {} vs {}",
10739
+ self_balance_post, channel_reserve_self,
10740
+ )));
10741
+ }
10742
+ let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
10743
+ counterparty_balance_pre,
10744
+ counterparty_balance_post,
10745
+ channel_value_pre,
10746
+ channel_value_post,
10747
+ self.context.counterparty_dust_limit_satoshis,
10748
+ );
10749
+ if let Err(channel_reserve_cp) = is_ok_cp {
10750
+ return Err(ChannelError::Warn(format!(
10751
+ "Balance below reserve mandated by counterparty, {} vs {}",
10752
+ counterparty_balance_post, channel_reserve_cp,
10753
+ )));
10754
+ }
10755
+ Ok(())
10756
+ }
10757
+
10758
+ // Send stuff to our remote peers:
10759
+
10758
10760
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
10759
10761
/// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
10760
10762
/// commitment update.
0 commit comments