@@ -10499,48 +10499,50 @@ where
10499
10499
}
10500
10500
10501
10501
/// 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)
10502
10504
#[cfg(splicing)]
10503
10505
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 {
10506
10508
return Ok(());
10507
10509
}
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 {
10510
10512
// 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 );
10512
10514
}
10513
10515
// Make sure we either remain with the same balance or move towards the reserve.
10514
10516
if post_balance >= pre_balance {
10515
10517
Ok(())
10516
10518
} else {
10517
- Err(post_channel_reserve )
10519
+ Err(post_channel_reserve_sats )
10518
10520
}
10519
10521
}
10520
10522
10521
10523
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
10522
10524
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
10523
10525
/// to check with new channel value (before being committed to it).
10524
10526
#[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> {
10526
10528
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,
10528
10530
self.context.holder_dust_limit_satoshis
10529
10531
);
10530
10532
if let Err(channel_reserve_self) = is_ok_self {
10531
10533
return Err(ChannelError::Warn(format!(
10532
10534
"Balance below reserve, mandated by holder, {} vs {}",
10533
- self_balance_post , channel_reserve_self,
10535
+ self_balance_post_msat , channel_reserve_self,
10534
10536
)));
10535
10537
}
10536
10538
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,
10538
10540
self.context.counterparty_dust_limit_satoshis
10539
10541
);
10540
10542
if let Err(channel_reserve_cp) = is_ok_cp {
10541
10543
return Err(ChannelError::Warn(format!(
10542
10544
"Balance below reserve mandated by counterparty, {} vs {}",
10543
- counterparty_balance_post , channel_reserve_cp,
10545
+ counterparty_balance_post_msat , channel_reserve_cp,
10544
10546
)));
10545
10547
}
10546
10548
Ok(())
0 commit comments