Skip to content

Commit ee5d746

Browse files
committed
Minor fixes – return types, typos, wording
1 parent bd703b4 commit ee5d746

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,60 +4273,62 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
42734273
}
42744274
}
42754275

4276-
/// Check a balance against a channel reserver requirement
4276+
/// Check a balance against a channel reserve requirement
42774277
#[cfg(splicing)]
4278-
pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> (bool, u64) {
4279-
let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4278+
pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> Result<(), u64> {
42804279
if balance == 0 {
42814280
// 0 balance is fine
4282-
(true, channel_reserve)
4281+
Ok(())
42834282
} else {
4284-
((balance >= channel_reserve), channel_reserve)
4283+
let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4284+
if balance >= channel_reserve {
4285+
Ok(())
4286+
} else {
4287+
Err(channel_reserve)
4288+
}
42854289
}
42864290
}
42874291

4288-
/// Check that post-splicing balance meets reserver requirements, but only if it met it pre-splice as well
4292+
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
42894293
#[cfg(splicing)]
4290-
pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> (bool, u64) {
4294+
pub fn check_splice_balance_meets_v2_reserve_requirement_noerr(pre_balance: u64, post_balance: u64, pre_channel_value: u64, post_channel_value: u64, dust_limit: u64) -> Result<(), u64> {
42914295
match Self::check_balance_meets_reserve_requirement(
42924296
post_balance, post_channel_value, dust_limit
42934297
) {
4294-
(true, channel_reserve) => (true, channel_reserve),
4295-
(false, channel_reserve) =>
4298+
Ok(_) => Ok(()),
4299+
Err(post_channel_reserve) =>
42964300
// post is not OK, check pre
42974301
match Self::check_balance_meets_reserve_requirement(
42984302
pre_balance, pre_channel_value, dust_limit
42994303
) {
4300-
(true, _) =>
4301-
// pre OK, post not -> not
4302-
(false, channel_reserve),
4303-
(false, _) =>
4304-
// post not OK, but so was pre -> OK
4305-
(true, channel_reserve),
4304+
// pre OK, post not -> not
4305+
Ok(_) => Err(post_channel_reserve),
4306+
// post not OK, but so was pre -> OK
4307+
Err(_) => Ok(()),
43064308
}
43074309
}
43084310
}
43094311

43104312
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
4311-
/// The channel value is an input as opposed to using from self, so that this can be used in case of splicing
4312-
/// to check with new channel value (before being comitted to it).
4313+
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
4314+
/// to check with new channel value (before being committed to it).
43134315
#[cfg(splicing)]
43144316
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> {
4315-
let (is_ok, channel_reserve_self) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4317+
let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
43164318
self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
43174319
self.holder_dust_limit_satoshis
43184320
);
4319-
if !is_ok {
4321+
if let Err(channel_reserve_self) = is_ok_self {
43204322
return Err(ChannelError::Warn(format!(
43214323
"Balance below reserve, mandated by holder, {} vs {}",
43224324
self_balance_post, channel_reserve_self,
43234325
)));
43244326
}
4325-
let (is_ok, channel_reserve_cp) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4327+
let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
43264328
counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
43274329
self.counterparty_dust_limit_satoshis
43284330
);
4329-
if !is_ok {
4331+
if let Err(channel_reserve_cp) = is_ok_cp {
43304332
return Err(ChannelError::Warn(format!(
43314333
"Balance below reserve mandated by counterparty, {} vs {}",
43324334
counterparty_balance_post, channel_reserve_cp,

0 commit comments

Comments
 (0)