Skip to content

Commit 8919039

Browse files
committed
fix Msat-Sat discrepancy in balance/reserve check
1 parent 285a799 commit 8919039

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

lightning/src/ln/channel.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8631,49 +8631,50 @@ impl<SP: Deref> FundedChannel<SP> where
86318631
Ok(())
86328632
}
86338633

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)
86358636
#[cfg(splicing)]
86368637
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 {
86398640
return Ok(());
86408641
}
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 {
86438644
// 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);
86458646
}
86468647
// Make sure we either remain with the same balance or move towards the reserve.
86478648
if post_balance >= pre_balance {
86488649
Ok(())
86498650
} else {
8650-
Err(post_channel_reserve)
8651+
Err(post_channel_reserve_sats)
86518652
}
86528653
}
86538654

86548655
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
86558656
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
86568657
/// to check with new channel value (before being committed to it).
86578658
#[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> {
86598660
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,
86618662
self.context.holder_dust_limit_satoshis
86628663
);
86638664
if let Err(channel_reserve_self) = is_ok_self {
86648665
return Err(ChannelError::Warn(format!(
86658666
"Balance below reserve, mandated by holder, {} vs {}",
8666-
self_balance_post, channel_reserve_self,
8667+
self_balance_post_msat, channel_reserve_self,
86678668
)));
86688669
}
86698670
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,
86718672
self.context.counterparty_dust_limit_satoshis
86728673
);
86738674
if let Err(channel_reserve_cp) = is_ok_cp {
86748675
return Err(ChannelError::Warn(format!(
86758676
"Balance below reserve mandated by counterparty, {} vs {}",
8676-
counterparty_balance_post, channel_reserve_cp,
8677+
counterparty_balance_post_msat, channel_reserve_cp,
86778678
)));
86788679
}
86798680
Ok(())

0 commit comments

Comments
 (0)