@@ -8631,49 +8631,50 @@ impl<SP: Deref> FundedChannel<SP> where
8631
8631
Ok(())
8632
8632
}
8633
8633
8634
- /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
8634
+ /// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
8635
+ /// Returns the minimum channel reserve (sats)
8635
8636
#[cfg(splicing)]
8636
8637
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> {
8637
- let post_channel_reserve = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
8638
- if post_balance >= post_channel_reserve {
8638
+ let post_channel_reserve_sats = get_v2_channel_reserve_satoshis(post_channel_value, dust_limit);
8639
+ if post_balance >= post_channel_reserve_sats * 1000 {
8639
8640
return Ok(());
8640
8641
}
8641
- let pre_channel_reserve = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
8642
- if pre_balance >= pre_channel_reserve {
8642
+ let pre_channel_reserve_sats = get_v2_channel_reserve_satoshis(pre_channel_value, dust_limit);
8643
+ if pre_balance >= pre_channel_reserve_sats * 1000 {
8643
8644
// We're not allowed to dip below the reserve once we've been above.
8644
- return Err(post_channel_reserve );
8645
+ return Err(post_channel_reserve_sats );
8645
8646
}
8646
8647
// Make sure we either remain with the same balance or move towards the reserve.
8647
8648
if post_balance >= pre_balance {
8648
8649
Ok(())
8649
8650
} else {
8650
- Err(post_channel_reserve )
8651
+ Err(post_channel_reserve_sats )
8651
8652
}
8652
8653
}
8653
8654
8654
8655
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
8655
8656
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
8656
8657
/// to check with new channel value (before being committed to it).
8657
8658
#[cfg(splicing)]
8658
- 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> {
8659
+ 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> {
8659
8660
let is_ok_self = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
8660
- self_balance_pre, self_balance_post , channel_value_pre, channel_value_post,
8661
+ self_balance_pre_msat, self_balance_post_msat , channel_value_pre, channel_value_post,
8661
8662
self.context.holder_dust_limit_satoshis
8662
8663
);
8663
8664
if let Err(channel_reserve_self) = is_ok_self {
8664
8665
return Err(ChannelError::Warn(format!(
8665
8666
"Balance below reserve, mandated by holder, {} vs {}",
8666
- self_balance_post , channel_reserve_self,
8667
+ self_balance_post_msat , channel_reserve_self,
8667
8668
)));
8668
8669
}
8669
8670
let is_ok_cp = self.check_splice_balance_meets_v2_reserve_requirement_noerr(
8670
- counterparty_balance_pre, counterparty_balance_post , channel_value_pre, channel_value_post,
8671
+ counterparty_balance_pre_msat, counterparty_balance_post_msat , channel_value_pre, channel_value_post,
8671
8672
self.context.counterparty_dust_limit_satoshis
8672
8673
);
8673
8674
if let Err(channel_reserve_cp) = is_ok_cp {
8674
8675
return Err(ChannelError::Warn(format!(
8675
8676
"Balance below reserve mandated by counterparty, {} vs {}",
8676
- counterparty_balance_post , channel_reserve_cp,
8677
+ counterparty_balance_post_msat , channel_reserve_cp,
8677
8678
)));
8678
8679
}
8679
8680
Ok(())
0 commit comments