@@ -11092,59 +11092,58 @@ where
1109211092 ))
1109311093 }
1109411094
11095- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
1109611095 /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
11097- /// Returns the minimum channel reserve ( sats)
11096+ /// In case of error, it returns the minimum channel reserve that was violated (in sats)
1109811097 #[cfg(splicing)]
11099- pub fn check_splice_balance_meets_v2_reserve_requirement_noerr (
11100- &self, pre_balance : u64, post_balance : u64, pre_channel_value : u64,
11101- 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,
1110211101 ) -> Result<(), u64> {
1110311102 let post_channel_reserve_sats =
11104- get_v2_channel_reserve_satoshis(post_channel_value, dust_limit );
11105- 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) {
1110611105 return Ok(());
1110711106 }
1110811107 // We're not allowed to dip below the reserve once we've been above,
1110911108 // check differently for originally v1 and v2 channels
1111011109 if self.is_v2_established() {
1111111110 let pre_channel_reserve_sats =
11112- get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit );
11113- 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) {
1111411113 return Err(post_channel_reserve_sats);
1111511114 }
1111611115 } else {
11117- if pre_balance >= self.funding.holder_selected_channel_reserve_satoshis * 1000 {
11116+ if pre_balance_msat >= ( self.funding.holder_selected_channel_reserve_satoshis * 1000) {
1111811117 return Err(post_channel_reserve_sats);
1111911118 }
1112011119 if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
11121- if pre_balance >= cp_reserve * 1000 {
11120+ if pre_balance_msat >= ( cp_reserve * 1000) {
1112211121 return Err(post_channel_reserve_sats);
1112311122 }
1112411123 }
1112511124 }
1112611125 // Make sure we either remain with the same balance or move towards the reserve.
11127- if post_balance >= pre_balance {
11126+ if post_balance_msat >= pre_balance_msat {
1112811127 Ok(())
1112911128 } else {
1113011129 Err(post_channel_reserve_sats)
1113111130 }
1113211131 }
1113311132
11134- /// 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).
1113511134 /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
1113611135 /// to check with new channel value (before being committed to it).
1113711136 #[cfg(splicing)]
1113811137 pub fn check_splice_balances_meet_v2_reserve_requirements(
1113911138 &self, self_balance_pre_msat: u64, self_balance_post_msat: u64,
1114011139 counterparty_balance_pre_msat: u64, counterparty_balance_post_msat: u64,
11141- channel_value_pre : u64, channel_value_post : u64,
11140+ channel_value_pre_sats : u64, channel_value_post_sats : u64,
1114211141 ) -> Result<(), ChannelError> {
11143- 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 (
1114411143 self_balance_pre_msat,
1114511144 self_balance_post_msat,
11146- channel_value_pre ,
11147- channel_value_post ,
11145+ channel_value_pre_sats ,
11146+ channel_value_post_sats ,
1114811147 self.context.holder_dust_limit_satoshis,
1114911148 );
1115011149 if let Err(channel_reserve_self) = is_ok_self {
@@ -11153,11 +11152,11 @@ where
1115311152 self_balance_post_msat, channel_reserve_self,
1115411153 )));
1115511154 }
11156- 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 (
1115711156 counterparty_balance_pre_msat,
1115811157 counterparty_balance_post_msat,
11159- channel_value_pre ,
11160- channel_value_post ,
11158+ channel_value_pre_sats ,
11159+ channel_value_post_sats ,
1116111160 self.context.counterparty_dust_limit_satoshis,
1116211161 );
1116311162 if let Err(channel_reserve_cp) = is_ok_cp {
0 commit comments