Skip to content

Commit

Permalink
Rename to PendingSplice. sum instead of fold (review)
Browse files Browse the repository at this point in the history
  • Loading branch information
optout21 committed Dec 5, 2024
1 parent 519829f commit 6a2f344
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,12 @@ impl UnfundedChannelContext {
/// Info about a pending splice, used in the pre-splice channel
#[cfg(splicing)]
#[derive(Clone)]
struct PendingSpliceInfoPre {
struct PendingSplice {
pub our_funding_contribution: i64,
}

#[cfg(splicing)]
impl PendingSpliceInfoPre {
impl PendingSplice {
#[inline]
fn add_checked(base: u64, delta: i64) -> u64 {
if delta >= 0 {
Expand Down Expand Up @@ -4298,7 +4298,7 @@ pub(super) struct Channel<SP: Deref> where SP::Target: SignerProvider {
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
/// Info about an in-progress, pending splice (if any), on the pre-splice channel
#[cfg(splicing)]
pending_splice_pre: Option<PendingSpliceInfoPre>,
pending_splice_pre: Option<PendingSplice>,
}

#[cfg(any(test, fuzzing))]
Expand Down Expand Up @@ -7937,17 +7937,17 @@ impl<SP: Deref> Channel<SP> where
// (Cannot test for miminum required post-splice channel value)

// Check that inputs are sufficient to cover our contribution
let sum_input: i64 = our_funding_inputs.into_iter().fold(0, |acc, i|
acc + i.1.output.get(i.0.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
);
let sum_input: i64 = our_funding_inputs.into_iter().map(
|(txin, tx)| tx.output.get(txin.previous_output.vout as usize).map(|tx| tx.value.to_sat() as i64).unwrap_or(0)
).sum();
if sum_input < our_funding_contribution_satoshis {
return Err(ChannelError::Warn(format!(
"Provided inputs are insufficient for our contribution, {} {}",
sum_input, our_funding_contribution_satoshis,
)));
}

self.pending_splice_pre = Some(PendingSpliceInfoPre {
self.pending_splice_pre = Some(PendingSplice {
our_funding_contribution: our_funding_contribution_satoshis,
});

Expand Down Expand Up @@ -7993,8 +7993,8 @@ impl<SP: Deref> Channel<SP> where
)));
}

let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, their_funding_contribution_satoshis, our_funding_contribution_satoshis);
let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution_satoshis);
let post_channel_value = PendingSplice::compute_post_value(pre_channel_value, their_funding_contribution_satoshis, our_funding_contribution_satoshis);
let post_balance = PendingSplice::add_checked(self.context.value_to_self_msat, our_funding_contribution_satoshis);
// Early check for reserve requirement, assuming maximum balance of full channel value
// This will also be checked later at tx_complete
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
Expand Down Expand Up @@ -8022,8 +8022,8 @@ impl<SP: Deref> Channel<SP> where
let our_funding_contribution = pending_splice.our_funding_contribution;

let pre_channel_value = self.context.get_value_satoshis();
let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution_satoshis);
let post_balance = PendingSpliceInfoPre::add_checked(self.context.value_to_self_msat, our_funding_contribution);
let post_channel_value = PendingSplice::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution_satoshis);
let post_balance = PendingSplice::add_checked(self.context.value_to_self_msat, our_funding_contribution);
// Early check for reserve requirement, assuming maximum balance of full channel value
// This will also be checked later at tx_complete
let _res = self.context.check_balance_meets_reserve_requirements(post_balance, post_channel_value)?;
Expand Down Expand Up @@ -12142,9 +12142,9 @@ mod tests {

#[cfg(all(test, splicing))]
fn get_pre_and_post(pre_channel_value: u64, our_funding_contribution: i64, their_funding_contribution: i64) -> (u64, u64) {
use crate::ln::channel::PendingSpliceInfoPre;
use crate::ln::channel::PendingSplice;

let post_channel_value = PendingSpliceInfoPre::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution);
let post_channel_value = PendingSplice::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution);
(pre_channel_value, post_channel_value)
}

Expand Down

0 comments on commit 6a2f344

Please sign in to comment.