@@ -10853,6 +10853,7 @@ where
1085310853
1085410854 /// Compute the channel balances (local & remote, in msats) by taking into account fees,
1085510855 /// anchor values, and dust limits.
10856+ /// Pending HTLCs are not taken into account, this method should be used when there is no such,
1085610857 /// e.g. in quiescence state
1085710858 #[cfg(splicing)]
1085810859 fn compute_balances_less_fees(
@@ -11091,59 +11092,58 @@ where
1109111092 ))
1109211093 }
1109311094
11094- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
1109511095 /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
11096- /// Returns the minimum channel reserve ( sats)
11096+ /// In case of error, it returns the minimum channel reserve that was violated (in sats)
1109711097 #[cfg(splicing)]
11098- pub fn check_splice_balance_meets_v2_reserve_requirement_noerr (
11099- &self, pre_balance : u64, post_balance : u64, pre_channel_value : u64,
11100- post_channel_value : u64, dust_limit : u64,
11098+ pub fn check_splice_balance_meets_v2_reserve_requirement (
11099+ &self, pre_balance_msat : u64, post_balance_msat : u64, pre_channel_value_sats : u64,
11100+ post_channel_value_sats : u64, dust_limit_sats : u64,
1110111101 ) -> Result<(), u64> {
1110211102 let post_channel_reserve_sats =
11103- get_v2_channel_reserve_satoshis(post_channel_value, dust_limit );
11104- if post_balance >= post_channel_reserve_sats * 1000 {
11103+ get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats );
11104+ if post_balance_msat >= ( post_channel_reserve_sats * 1000) {
1110511105 return Ok(());
1110611106 }
1110711107 // We're not allowed to dip below the reserve once we've been above,
1110811108 // check differently for originally v1 and v2 channels
1110911109 if self.is_v2_established() {
1111011110 let pre_channel_reserve_sats =
11111- get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit );
11112- if pre_balance >= pre_channel_reserve_sats * 1000 {
11111+ get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats );
11112+ if pre_balance_msat >= ( pre_channel_reserve_sats * 1000) {
1111311113 return Err(post_channel_reserve_sats);
1111411114 }
1111511115 } else {
11116- if pre_balance >= self.funding.holder_selected_channel_reserve_satoshis * 1000 {
11116+ if pre_balance_msat >= ( self.funding.holder_selected_channel_reserve_satoshis * 1000) {
1111711117 return Err(post_channel_reserve_sats);
1111811118 }
1111911119 if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
11120- if pre_balance >= cp_reserve * 1000 {
11120+ if pre_balance_msat >= ( cp_reserve * 1000) {
1112111121 return Err(post_channel_reserve_sats);
1112211122 }
1112311123 }
1112411124 }
1112511125 // Make sure we either remain with the same balance or move towards the reserve.
11126- if post_balance >= pre_balance {
11126+ if post_balance_msat >= pre_balance_msat {
1112711127 Ok(())
1112811128 } else {
1112911129 Err(post_channel_reserve_sats)
1113011130 }
1113111131 }
1113211132
11133- /// Check that balances meet the channel reserve requirements or violates them (below reserve).
11133+ /// Check that balances (self and counterparty) meet the channel reserve requirements or violates them (below reserve).
1113411134 /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
1113511135 /// to check with new channel value (before being committed to it).
1113611136 #[cfg(splicing)]
1113711137 pub fn check_splice_balances_meet_v2_reserve_requirements(
1113811138 &self, self_balance_pre_msat: u64, self_balance_post_msat: u64,
1113911139 counterparty_balance_pre_msat: u64, counterparty_balance_post_msat: u64,
11140- channel_value_pre : u64, channel_value_post : u64,
11140+ channel_value_pre_sats : u64, channel_value_post_sats : u64,
1114111141 ) -> Result<(), ChannelError> {
11142- let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement_noerr (
11142+ let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement (
1114311143 self_balance_pre_msat,
1114411144 self_balance_post_msat,
11145- channel_value_pre ,
11146- channel_value_post ,
11145+ channel_value_pre_sats ,
11146+ channel_value_post_sats ,
1114711147 self.context.holder_dust_limit_satoshis,
1114811148 );
1114911149 if let Err(channel_reserve_self) = is_ok_self {
@@ -11152,11 +11152,11 @@ where
1115211152 self_balance_post_msat, channel_reserve_self,
1115311153 )));
1115411154 }
11155- let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement_noerr (
11155+ let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement (
1115611156 counterparty_balance_pre_msat,
1115711157 counterparty_balance_post_msat,
11158- channel_value_pre ,
11159- channel_value_post ,
11158+ channel_value_pre_sats ,
11159+ channel_value_post_sats ,
1116011160 self.context.counterparty_dust_limit_satoshis,
1116111161 );
1116211162 if let Err(channel_reserve_cp) = is_ok_cp {
0 commit comments