@@ -1946,8 +1946,12 @@ impl FundingScope {
1946
1946
1947
1947
/// Construct FundingScope for a splicing channel
1948
1948
#[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
+ };
1951
1955
1952
1956
let prev_funding_txid = prev_funding.channel_transaction_parameters.funding_outpoint
1953
1957
.map(|outpoint| outpoint.txid);
@@ -9192,14 +9196,14 @@ impl<SP: Deref> FundedChannel<SP> where
9192
9196
9193
9197
let post_channel_value = PendingSplice::compute_post_value(pre_channel_value, our_funding_contribution, their_funding_contribution);
9194
9198
9195
- let (our_funding_satoshis, their_funding_satoshis) = calculate_funding_values (
9199
+ let (our_funding_satoshis, their_funding_satoshis) = calculate_total_funding_contribution (
9196
9200
pre_channel_value,
9197
9201
our_funding_contribution,
9198
9202
msg.funding_contribution_satoshis,
9199
9203
false, // is_outbound
9200
9204
)?;
9201
9205
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);
9203
9207
9204
9208
let funding_negotiation_context = FundingNegotiationContext {
9205
9209
our_funding_satoshis,
@@ -9287,14 +9291,14 @@ impl<SP: Deref> FundedChannel<SP> where
9287
9291
// TODO(splicing): Pre-check for reserve requirement
9288
9292
// (Note: It should also be checked later at tx_complete)
9289
9293
9290
- let (our_funding_satoshis, their_funding_satoshis) = calculate_funding_values (
9294
+ let (our_funding_satoshis, their_funding_satoshis) = calculate_total_funding_contribution (
9291
9295
pre_channel_value,
9292
9296
our_funding_contribution,
9293
9297
their_funding_contribution_satoshis,
9294
9298
true, // is_outbound
9295
9299
)?;
9296
9300
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);
9298
9302
9299
9303
let pre_funding_transaction = &self.funding.funding_transaction;
9300
9304
let pre_funding_txo = &self.funding.get_funding_txo();
@@ -10653,14 +10657,15 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
10653
10657
}
10654
10658
}
10655
10659
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.
10657
10662
#[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,
10660
10665
) -> Result<(u64, u64), ChannelError> {
10661
10666
// 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 ;
10664
10669
if is_initiator {
10665
10670
our_contribution_with_prev = our_contribution_with_prev.saturating_add(pre_channel_value as i64);
10666
10671
} else {
@@ -10670,7 +10675,7 @@ fn calculate_funding_values(
10670
10675
return Err(ChannelError::Warn(format!(
10671
10676
"Funding contribution cannot be negative! ours {} theirs {} pre {} initiator {} acceptor {}",
10672
10677
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
10674
10679
)));
10675
10680
}
10676
10681
Ok((our_contribution_with_prev.abs() as u64, their_contribution_with_prev.abs() as u64))
0 commit comments