@@ -1946,8 +1946,12 @@ impl FundingScope {
19461946
19471947 /// Construct FundingScope for a splicing channel
19481948 #[cfg(splicing)]
1949- pub fn for_splice<SP: Deref>(prev_funding: &Self, context: &ChannelContext<SP>, our_funding_satoshis: u64, post_channel_value: u64, counterparty_funding_pubkey: PublicKey) -> Self where SP::Target: SignerProvider {
1950- let post_value_to_self_msat = prev_funding.value_to_self_msat.saturating_add(our_funding_satoshis);
1949+ pub fn for_splice<SP: Deref>(prev_funding: &Self, context: &ChannelContext<SP>, our_funding_contribution_sats: i64, post_channel_value: u64, counterparty_funding_pubkey: PublicKey) -> Self where SP::Target: SignerProvider {
1950+ let post_value_to_self_msat = if our_funding_contribution_sats < 0 {
1951+ prev_funding.value_to_self_msat.saturating_sub((-our_funding_contribution_sats as u64) * 1000)
1952+ } else {
1953+ prev_funding.value_to_self_msat.saturating_add((our_funding_contribution_sats as u64) * 1000)
1954+ };
19511955
19521956 let prev_funding_txid = prev_funding.channel_transaction_parameters.funding_outpoint
19531957 .map(|outpoint| outpoint.txid);
@@ -9192,14 +9196,14 @@ impl<SP: Deref> FundedChannel<SP> where
91929196
91939197 let post_channel_value = PendingSplice::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution);
91949198
9195- let (our_funding_satoshis, their_funding_satoshis) = calculate_funding_values (
9199+ let (our_funding_satoshis, their_funding_satoshis) = calculate_total_funding_contribution (
91969200 pre_channel_value,
91979201 our_funding_contribution,
91989202 msg.funding_contribution_satoshis,
91999203 false, // is_outbound
92009204 )?;
92019205
9202- let funding_scope = FundingScope::for_splice(&self.funding, &self.context, our_funding_satoshis , post_channel_value, msg.funding_pubkey);
9206+ let funding_scope = FundingScope::for_splice(&self.funding, &self.context, our_funding_contribution , post_channel_value, msg.funding_pubkey);
92039207
92049208 let funding_negotiation_context = FundingNegotiationContext {
92059209 our_funding_satoshis,
@@ -9287,14 +9291,14 @@ impl<SP: Deref> FundedChannel<SP> where
92879291 // TODO(splicing): Pre-check for reserve requirement
92889292 // (Note: It should also be checked later at tx_complete)
92899293
9290- let (our_funding_satoshis, their_funding_satoshis) = calculate_funding_values (
9294+ let (our_funding_satoshis, their_funding_satoshis) = calculate_total_funding_contribution (
92919295 pre_channel_value,
92929296 our_funding_contribution,
92939297 their_funding_contribution_satoshis,
92949298 true, // is_outbound
92959299 )?;
92969300
9297- let funding_scope = FundingScope::for_splice(&self.funding, &self.context, our_funding_satoshis , post_channel_value, msg.funding_pubkey);
9301+ let funding_scope = FundingScope::for_splice(&self.funding, &self.context, our_funding_contribution , post_channel_value, msg.funding_pubkey);
92989302
92999303 let pre_funding_transaction = &self.funding.funding_transaction;
93009304 let pre_funding_txo = &self.funding.get_funding_txo();
@@ -10653,14 +10657,15 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
1065310657 }
1065410658}
1065510659
10656- /// Calculate funding values for interactive tx for splicing, based on channel value changes
10660+ /// Calculate total funding contributions, needed for interactive tx for splicing,
10661+ /// based on the current channel value and the splice contributions.
1065710662#[cfg(splicing)]
10658- fn calculate_funding_values (
10659- pre_channel_value: u64, our_funding_contribution : i64, their_funding_contribution : i64, is_initiator: bool,
10663+ fn calculate_total_funding_contribution (
10664+ pre_channel_value: u64, our_splice_contribution : i64, their_splice_contribution : i64, is_initiator: bool,
1066010665) -> Result<(u64, u64), ChannelError> {
1066110666 // Initiator also adds the previous funding as input
10662- let mut our_contribution_with_prev = our_funding_contribution ;
10663- let mut their_contribution_with_prev = their_funding_contribution ;
10667+ let mut our_contribution_with_prev = our_splice_contribution ;
10668+ let mut their_contribution_with_prev = their_splice_contribution ;
1066410669 if is_initiator {
1066510670 our_contribution_with_prev = our_contribution_with_prev.saturating_add(pre_channel_value as i64);
1066610671 } else {
@@ -10670,7 +10675,7 @@ fn calculate_funding_values(
1067010675 return Err(ChannelError::Warn(format!(
1067110676 "Funding contribution cannot be negative! ours {} theirs {} pre {} initiator {} acceptor {}",
1067210677 our_contribution_with_prev, their_contribution_with_prev, pre_channel_value,
10673- our_funding_contribution, their_funding_contribution
10678+ our_splice_contribution, their_splice_contribution
1067410679 )));
1067510680 }
1067610681 Ok((our_contribution_with_prev.abs() as u64, their_contribution_with_prev.abs() as u64))
0 commit comments