@@ -10499,48 +10499,50 @@ where
1049910499 }
1050010500
1050110501 /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
10502+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
10503+ /// Returns the minimum channel reserve (sats)
1050210504 #[cfg(splicing)]
1050310505 pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(&self, pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> Result<(), u64> {
10504- let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
10505- if post_balance >= post_channel_reserve {
10506+ let post_channel_reserve_sats = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
10507+ if post_balance >= post_channel_reserve_sats * 1000 {
1050610508 return Ok(());
1050710509 }
10508- let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
10509- if pre_balance >= pre_channel_reserve {
10510+ let pre_channel_reserve_sats = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
10511+ if pre_balance >= pre_channel_reserve_sats * 1000 {
1051010512 // We're not allowed to dip below the reserve once we've been above.
10511- return Err(post_channel_reserve );
10513+ return Err(post_channel_reserve_sats );
1051210514 }
1051310515 // Make sure we either remain with the same balance or move towards the reserve.
1051410516 if post_balance >= pre_balance {
1051510517 Ok(())
1051610518 } else {
10517- Err(post_channel_reserve )
10519+ Err(post_channel_reserve_sats )
1051810520 }
1051910521 }
1052010522
1052110523 /// Check that balances meet the channel reserve requirements or violates them (below reserve).
1052210524 /// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
1052310525 /// to check with new channel value (before being committed to it).
1052410526 #[cfg(splicing)]
10525- 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> {
10527+ pub fn check_splice_balances_meet_v2_reserve_requirements(&self, self_balance_pre_msat : u64, self_balance_post_msat : u64, counterparty_balance_pre_msat : u64, counterparty_balance_post_msat : u64, channel_value_pre: u64, channel_value_post: u64) -> Result<(), ChannelError> {
1052610528 let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
10527- self_balance_pre, self_balance_post , channel_value_pre, channel_value_post,
10529+ self_balance_pre_msat, self_balance_post_msat , channel_value_pre, channel_value_post,
1052810530 self.context.holder_dust_limit_satoshis
1052910531 );
1053010532 if let Err(channel_reserve_self) = is_ok_self {
1053110533 return Err(ChannelError::Warn(format!(
1053210534 "Balance below reserve, mandated by holder, {} vs {}",
10533- self_balance_post , channel_reserve_self,
10535+ self_balance_post_msat , channel_reserve_self,
1053410536 )));
1053510537 }
1053610538 let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
10537- counterparty_balance_pre, counterparty_balance_post , channel_value_pre, channel_value_post,
10539+ counterparty_balance_pre_msat, counterparty_balance_post_msat , channel_value_pre, channel_value_post,
1053810540 self.context.counterparty_dust_limit_satoshis
1053910541 );
1054010542 if let Err(channel_reserve_cp) = is_ok_cp {
1054110543 return Err(ChannelError::Warn(format!(
1054210544 "Balance below reserve mandated by counterparty, {} vs {}",
10543- counterparty_balance_post , channel_reserve_cp,
10545+ counterparty_balance_post_msat , channel_reserve_cp,
1054410546 )));
1054510547 }
1054610548 Ok(())
0 commit comments