Skip to content

Commit 1d9ea18

Browse files
committed
Minor fixes – return types, typos, wording
1 parent 5d38338 commit 1d9ea18

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

lightning/src/ln/channel.rs

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4131,60 +4131,62 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
41314131
}
41324132
}
41334133

4134-
/// Check a balance against a channel reserver requirement
4134+
/// Check a balance against a channel reserve requirement
41354135
#[cfg(splicing)]
4136-
pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> (bool, u64) {
4137-
let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4136+
pub fn check_balance_meets_reserve_requirement(balance: u64, channel_value: u64, dust_limit: u64) -> Result<(), u64> {
41384137
if balance == 0 {
41394138
// 0 balance is fine
4140-
(true, channel_reserve)
4139+
Ok(())
41414140
} else {
4142-
((balance >= channel_reserve), channel_reserve)
4141+
let channel_reserve = get_v2_channel_reserve_satoshis(channel_value, dust_limit);
4142+
if balance >= channel_reserve {
4143+
Ok(())
4144+
} else {
4145+
Err(channel_reserve)
4146+
}
41434147
}
41444148
}
41454149

4146-
/// Check that post-splicing balance meets reserver requirements, but only if it met it pre-splice as well
4150+
/// Check that post-splicing balance meets reserve requirements, but only if it met it pre-splice as well
41474151
#[cfg(splicing)]
4148-
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) {
4152+
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> {
41494153
match Self::check_balance_meets_reserve_requirement(
41504154
post_balance, post_channel_value, dust_limit
41514155
) {
4152-
(true, channel_reserve) => (true, channel_reserve),
4153-
(false, channel_reserve) =>
4156+
Ok(_) => Ok(()),
4157+
Err(post_channel_reserve) =>
41544158
// post is not OK, check pre
41554159
match Self::check_balance_meets_reserve_requirement(
41564160
pre_balance, pre_channel_value, dust_limit
41574161
) {
4158-
(true, _) =>
4159-
// pre OK, post not -> not
4160-
(false, channel_reserve),
4161-
(false, _) =>
4162-
// post not OK, but so was pre -> OK
4163-
(true, channel_reserve),
4162+
// pre OK, post not -> not
4163+
Ok(_) => Err(post_channel_reserve),
4164+
// post not OK, but so was pre -> OK
4165+
Err(_) => Ok(()),
41644166
}
41654167
}
41664168
}
41674169

41684170
/// Check that balances meet the channel reserve requirements or violates them (below reserve).
4169-
/// The channel value is an input as opposed to using from self, so that this can be used in case of splicing
4170-
/// to check with new channel value (before being comitted to it).
4171+
/// The channel value is an input as opposed to using from the FundingScope, so that this can be used in case of splicing
4172+
/// to check with new channel value (before being committed to it).
41714173
#[cfg(splicing)]
41724174
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> {
4173-
let (is_ok, channel_reserve_self) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4175+
let is_ok_self = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
41744176
self_balance_pre, self_balance_post, channel_value_pre, channel_value_post,
41754177
self.holder_dust_limit_satoshis
41764178
);
4177-
if !is_ok {
4179+
if let Err(channel_reserve_self) = is_ok_self {
41784180
return Err(ChannelError::Warn(format!(
41794181
"Balance below reserve, mandated by holder, {} vs {}",
41804182
self_balance_post, channel_reserve_self,
41814183
)));
41824184
}
4183-
let (is_ok, channel_reserve_cp) = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
4185+
let is_ok_cp = Self::check_splice_balance_meets_v2_reserve_requirement_noerr(
41844186
counterparty_balance_pre, counterparty_balance_post, channel_value_pre, channel_value_post,
41854187
self.counterparty_dust_limit_satoshis
41864188
);
4187-
if !is_ok {
4189+
if let Err(channel_reserve_cp) = is_ok_cp {
41884190
return Err(ChannelError::Warn(format!(
41894191
"Balance below reserve mandated by counterparty, {} vs {}",
41904192
counterparty_balance_post, channel_reserve_cp,
@@ -8563,7 +8565,8 @@ impl<SP: Deref> FundedChannel<SP> where
85638565

85648566
if their_funding_contribution_satoshis.saturating_add(our_funding_contribution_satoshis) < 0 {
85658567
return Err(ChannelError::Warn(format!(
8566-
"Splice-out not supported, only splice in, relative {} + {}",
8568+
"Splice-out not supported, only splice in, contribution is {} ({} + {})",
8569+
their_funding_contribution_satoshis + our_funding_contribution_satoshis,
85678570
their_funding_contribution_satoshis, our_funding_contribution_satoshis,
85688571
)));
85698572
}

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)