@@ -4132,60 +4132,62 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
41324132 }
41334133 }
41344134
4135- /// Check a balance against a channel reserver requirement
4135+ /// Check a balance against a channel reserve requirement
41364136 #[cfg(splicing)]
4137- pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> (bool, u64) {
4138- let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4137+ pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> Result<(), u64> {
41394138 if balance == 0 {
41404139 // 0 balance is fine
4141- (true, channel_reserve )
4140+ Ok(() )
41424141 } else {
4143- ((balance >= channel_reserve), channel_reserve)
4142+ let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4143+ if balance >= channel_reserve {
4144+ Ok(())
4145+ } else {
4146+ Err(channel_reserve)
4147+ }
41444148 }
41454149 }
41464150
4147- /// Check that post-splicing balance meets reserver requirements, but only if it met it pre-splice as well
4151+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
41484152 #[cfg(splicing)]
4149- 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) -> (bool , u64) {
4153+ 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> {
41504154 match Self::check_balance_meets_reserve_requirement(
41514155 post_balance, post_channel_value, dust_limit
41524156 ) {
4153- (true, channel_reserve ) => (true, channel_reserve ),
4154- (false, channel_reserve ) =>
4157+ Ok(_ ) => Ok(() ),
4158+ Err(post_channel_reserve ) =>
41554159 // post is not OK, check pre
41564160 match Self::check_balance_meets_reserve_requirement(
41574161 pre_balance, pre_channel_value, dust_limit
41584162 ) {
4159- (true, _) =>
4160- // pre OK, post not -> not
4161- (false, channel_reserve),
4162- (false, _) =>
4163- // post not OK, but so was pre -> OK
4164- (true, channel_reserve),
4163+ // pre OK, post not -> not
4164+ Ok(_) => Err(post_channel_reserve),
4165+ // post not OK, but so was pre -> OK
4166+ Err(_) => Ok(()),
41654167 }
41664168 }
41674169 }
41684170
41694171 /// Check that balances meet the channel reserve requirements or violates them (below reserve).
4170- /// The channel value is an input as opposed to using from self , so that this can be used in case of splicing
4171- /// to check with new channel value (before being comitted to it).
4172+ /// The channel value is an input as opposed to using from the FundingScope , so that this can be used in case of splicing
4173+ /// to check with new channel value (before being committed to it).
41724174 #[cfg(splicing)]
41734175 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> {
4174- let (is_ok, channel_reserve_self) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4176+ let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
41754177 self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
41764178 self.holder_dust_limit_satoshis
41774179 );
4178- if !is_ok {
4180+ if let Err(channel_reserve_self) = is_ok_self {
41794181 return Err(ChannelError::Warn(format!(
41804182 "Balance below reserve, mandated by holder, {} vs {}",
41814183 self_balance_post, channel_reserve_self,
41824184 )));
41834185 }
4184- let (is_ok, channel_reserve_cp) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4186+ let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
41854187 counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
41864188 self.counterparty_dust_limit_satoshis
41874189 );
4188- if !is_ok {
4190+ if let Err(channel_reserve_cp) = is_ok_cp {
41894191 return Err(ChannelError::Warn(format!(
41904192 "Balance below reserve mandated by counterparty, {} vs {}",
41914193 counterparty_balance_post, channel_reserve_cp,
@@ -8564,7 +8566,8 @@ impl<SP: Deref> FundedChannel<SP> where
85648566
85658567 if their_funding_contribution_satoshis.saturating_add(our_funding_contribution_satoshis) < 0 {
85668568 return Err(ChannelError::Warn(format!(
8567- "Splice-out not supported, only splice in, relative {} + {}",
8569+ "Splice-out not supported, only splice in, contribution is {} ({} + {})",
8570+ their_funding_contribution_satoshis + our_funding_contribution_satoshis,
85688571 their_funding_contribution_satoshis, our_funding_contribution_satoshis,
85698572 )));
85708573 }
0 commit comments