Skip to content

Commit 6ec250f

Browse files
committed
Minor fixes – return types, typos, wording
1 parent d6d82d8 commit 6ec250f

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

lightning/src/ln/channel.rs

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,60 +4095,62 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
40954095
}
40964096
}
40974097

4098-
/// Check a balance against a channel reserver requirement
4098+
/// Check a balance against a channel reserve requirement
40994099
#[cfg(splicing)]
4100-
pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> (bool, u64) {
4100+
pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> Result<u64, u64> {
41014101
let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
41024102
if balance == 0 {
41034103
// 0 balance is fine
4104-
(true, channel_reserve)
4104+
Ok(channel_reserve)
41054105
} else {
4106-
((balance >= channel_reserve), channel_reserve)
4106+
if balance >= channel_reserve {
4107+
Ok(channel_reserve)
4108+
} else {
4109+
Err(channel_reserve)
4110+
}
41074111
}
41084112
}
41094113

4110-
/// Check that post-splicing balance meets reserver requirements, but only if it met it pre-splice as well
4114+
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
41114115
#[cfg(splicing)]
4112-
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) {
4116+
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, u64> {
41134117
match Self::check_balance_meets_reserve_requirement(
41144118
post_balance, post_channel_value, dust_limit
41154119
) {
4116-
(true, channel_reserve) => (true, channel_reserve),
4117-
(false, channel_reserve) =>
4120+
Ok(post_channel_reserve) => Ok(post_channel_reserve),
4121+
Err(post_channel_reserve) =>
41184122
// post is not OK, check pre
41194123
match Self::check_balance_meets_reserve_requirement(
41204124
pre_balance, pre_channel_value, dust_limit
41214125
) {
4122-
(true, _) =>
4123-
// pre OK, post not -> not
4124-
(false, channel_reserve),
4125-
(false, _) =>
4126-
// post not OK, but so was pre -> OK
4127-
(true, channel_reserve),
4126+
// pre OK, post not -> not
4127+
Ok(_) => Err(post_channel_reserve),
4128+
// post not OK, but so was pre -> OK
4129+
Err(_) => Ok(post_channel_reserve),
41284130
}
41294131
}
41304132
}
41314133

41324134
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
4133-
/// The channel value is an input as opposed to using from self, so that this can be used in case of splicing
4134-
/// to check with new channel value (before being comitted to it).
4135+
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
4136+
/// to check with new channel value (before being committed to it).
41354137
#[cfg(splicing)]
41364138
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> {
4137-
let (is_ok, channel_reserve_self) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4139+
let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
41384140
self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
41394141
self.holder_dust_limit_satoshis
41404142
);
4141-
if !is_ok {
4143+
if let Err(channel_reserve_self) = is_ok_self {
41424144
return Err(ChannelError::Warn(format!(
41434145
"Balance below reserve, mandated by holder, {} vs {}",
41444146
self_balance_post, channel_reserve_self,
41454147
)));
41464148
}
4147-
let (is_ok, channel_reserve_cp) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4149+
let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
41484150
counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
41494151
self.counterparty_dust_limit_satoshis
41504152
);
4151-
if !is_ok {
4153+
if let Err(channel_reserve_cp) = is_ok_cp {
41524154
return Err(ChannelError::Warn(format!(
41534155
"Balance below reserve mandated by counterparty, {} vs {}",
41544156
counterparty_balance_post, channel_reserve_cp,
@@ -8518,7 +8520,8 @@ impl<SP: Deref> FundedChannel<SP> where
85188520

85198521
if their_funding_contribution_satoshis.saturating_add(our_funding_contribution_satoshis) < 0 {
85208522
return Err(ChannelError::Warn(format!(
8521-
"Splice-out not supported, only splice in, relative {} + {}",
8523+
"Splice-out not supported, only splice in, contribution is {} ({} + {})",
8524+
their_funding_contribution_satoshis + our_funding_contribution_satoshis,
85228525
their_funding_contribution_satoshis, our_funding_contribution_satoshis,
85238526
)));
85248527
}

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4303,16 +4303,11 @@ where
43034303
hash_map::Entry::Occupied(mut chan_phase_entry) => {
43044304
let locktime = locktime.unwrap_or(self.current_best_block().height);
43054305
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4306-
let msg = match chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime) {
4307-
Ok(m) => m,
4308-
Err(e) => return Err(e),
4309-
};
4310-
4306+
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)?;
43114307
peer_state.pending_msg_events.push(events::MessageSendEvent::SendSpliceInit {
43124308
node_id: *counterparty_node_id,
43134309
msg,
43144310
});
4315-
43164311
Ok(())
43174312
} else {
43184313
Err(APIError::ChannelUnavailable {

0 commit comments

Comments
 (0)