@@ -5073,66 +5073,6 @@ where
50735073 }
50745074 }
50755075
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-
51365076 /// Get the commitment tx fee for the local's (i.e. our) next commitment transaction based on the
51375077 /// number of pending HTLCs that are on track to be in our next commitment tx.
51385078 ///
@@ -10692,7 +10632,7 @@ where
1069210632 self.compute_balances_less_fees(post_channel_value, post_balance_self, true);
1069310633 // Pre-check for reserve requirement
1069410634 // 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(
1069610636 pre_balance_self_less_fees,
1069710637 post_balance_self_less_fees,
1069810638 pre_balance_counterparty_less_fees,
@@ -10755,6 +10695,68 @@ where
1075510695 ))
1075610696 }
1075710697
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+
1075810760 /// Queues up an outbound HTLC to send by placing it in the holding cell. You should call
1075910761 /// [`Self::maybe_free_holding_cell_htlcs`] in order to actually generate and send the
1076010762 /// commitment update.
0 commit comments