Skip to content

Commit 6ebc0bd

Browse files
committed
fix Change the order of the 2 check methods
1 parent f528f80 commit 6ebc0bd

1 file changed

Lines changed: 38 additions & 38 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -10517,44 +10517,6 @@ where
1051710517
Ok((None, None))
1051810518
}
1051910519

10520-
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
10521-
/// In case of error, it returns the minimum channel reserve that was violated (in sats)
10522-
#[cfg(splicing)]
10523-
pub fn check_splice_balance_meets_v2_reserve_requirement(
10524-
&self, pre_balance_msat: u64, post_balance_msat: u64, pre_channel_value_sats: u64,
10525-
post_channel_value_sats: u64, dust_limit_sats: u64,
10526-
) -> Result<(), u64> {
10527-
let post_channel_reserve_sats =
10528-
get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats);
10529-
if post_balance_msat >= (post_channel_reserve_sats * 1000) {
10530-
return Ok(());
10531-
}
10532-
// We're not allowed to dip below the reserve once we've been above,
10533-
// check differently for originally v1 and v2 channels
10534-
if self.is_v2_established() {
10535-
let pre_channel_reserve_sats =
10536-
get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats);
10537-
if pre_balance_msat >= (pre_channel_reserve_sats * 1000) {
10538-
return Err(post_channel_reserve_sats);
10539-
}
10540-
} else {
10541-
if pre_balance_msat >= (self.funding.holder_selected_channel_reserve_satoshis * 1000) {
10542-
return Err(post_channel_reserve_sats);
10543-
}
10544-
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
10545-
if pre_balance_msat >= (cp_reserve * 1000) {
10546-
return Err(post_channel_reserve_sats);
10547-
}
10548-
}
10549-
}
10550-
// Make sure we either remain with the same balance or move towards the reserve.
10551-
if post_balance_msat >= pre_balance_msat {
10552-
Ok(())
10553-
} else {
10554-
Err(post_channel_reserve_sats)
10555-
}
10556-
}
10557-
1055810520
/// Check that balances (self and counterparty) meet the channel reserve requirements or violates them (below reserve).
1055910521
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
1056010522
/// to check with new channel value (before being committed to it).
@@ -10593,6 +10555,44 @@ where
1059310555
Ok(())
1059410556
}
1059510557

10558+
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well.
10559+
/// In case of error, it returns the minimum channel reserve that was violated (in sats)
10560+
#[cfg(splicing)]
10561+
pub fn check_splice_balance_meets_v2_reserve_requirement(
10562+
&self, pre_balance_msat: u64, post_balance_msat: u64, pre_channel_value_sats: u64,
10563+
post_channel_value_sats: u64, dust_limit_sats: u64,
10564+
) -> Result<(), u64> {
10565+
let post_channel_reserve_sats =
10566+
get_v2_channel_reserve_satoshis(post_channel_value_sats, dust_limit_sats);
10567+
if post_balance_msat >= (post_channel_reserve_sats * 1000) {
10568+
return Ok(());
10569+
}
10570+
// We're not allowed to dip below the reserve once we've been above,
10571+
// check differently for originally v1 and v2 channels
10572+
if self.is_v2_established() {
10573+
let pre_channel_reserve_sats =
10574+
get_v2_channel_reserve_satoshis(pre_channel_value_sats, dust_limit_sats);
10575+
if pre_balance_msat >= (pre_channel_reserve_sats * 1000) {
10576+
return Err(post_channel_reserve_sats);
10577+
}
10578+
} else {
10579+
if pre_balance_msat >= (self.funding.holder_selected_channel_reserve_satoshis * 1000) {
10580+
return Err(post_channel_reserve_sats);
10581+
}
10582+
if let Some(cp_reserve) = self.funding.counterparty_selected_channel_reserve_satoshis {
10583+
if pre_balance_msat >= (cp_reserve * 1000) {
10584+
return Err(post_channel_reserve_sats);
10585+
}
10586+
}
10587+
}
10588+
// Make sure we either remain with the same balance or move towards the reserve.
10589+
if post_balance_msat >= pre_balance_msat {
10590+
Ok(())
10591+
} else {
10592+
Err(post_channel_reserve_sats)
10593+
}
10594+
}
10595+
1059610596
// Send stuff to our remote peers:
1059710597

1059810598
/// Queues up an outbound HTLC to send by placing it in the holding cell. You should call

0 commit comments

Comments
 (0)