@@ -1954,6 +1954,59 @@ impl FundingScope {
19541954 pub fn get_channel_type(&self) -> &ChannelTypeFeatures {
19551955 &self.channel_transaction_parameters.channel_type_features
19561956 }
1957+
1958+ /// Construct FundingScope for a splicing channel
1959+ #[cfg(splicing)]
1960+ pub fn for_splice<SP: Deref>(prev_funding: &Self, context: &ChannelContext<SP>, our_funding_satoshis: u64, post_channel_value: u64, is_initiator: bool, counterparty_funding_pubkey: PublicKey) -> Self where SP::Target: SignerProvider {
1961+ let post_value_to_self_msat = prev_funding.value_to_self_msat.saturating_add(our_funding_satoshis);
1962+
1963+ let prev_funding_txid = prev_funding.channel_transaction_parameters.funding_outpoint
1964+ .map(|outpoint| outpoint.txid);
1965+ let holder_pubkeys = match &context.holder_signer {
1966+ ChannelSignerType::Ecdsa(ecdsa) => {
1967+ ecdsa.pubkeys(prev_funding_txid, &context.secp_ctx)
1968+ }
1969+ // TODO (taproot|arik)
1970+ #[cfg(taproot)]
1971+ _ => todo!()
1972+ };
1973+ let mut post_channel_transaction_parameters = ChannelTransactionParameters {
1974+ holder_pubkeys,
1975+ holder_selected_contest_delay: prev_funding.channel_transaction_parameters.holder_selected_contest_delay,
1976+ // The 'outbound' attribute may change, if the the splice is being initiated by the previous acceptor
1977+ is_outbound_from_holder: is_initiator,
1978+ counterparty_parameters: prev_funding.channel_transaction_parameters.counterparty_parameters.clone(),
1979+ funding_outpoint: None, // filled later
1980+ splice_parent_funding_txid: prev_funding_txid,
1981+ channel_type_features: prev_funding.channel_transaction_parameters.channel_type_features.clone(),
1982+ channel_value_satoshis: post_channel_value,
1983+ };
1984+ // Update the splicing 'tweak', this will rotate the keys in the signer
1985+ if let Some(ref mut counterparty_parameters) = post_channel_transaction_parameters.counterparty_parameters {
1986+ counterparty_parameters.pubkeys.funding_pubkey = counterparty_funding_pubkey;
1987+ }
1988+
1989+ // New reserve values are based on the new channel value, and v2-specific
1990+ let counterparty_selected_channel_reserve_satoshis = Some(get_v2_channel_reserve_satoshis(
1991+ post_channel_value, context.counterparty_dust_limit_satoshis));
1992+ let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
1993+ post_channel_value, MIN_CHAN_DUST_LIMIT_SATOSHIS);
1994+ Self {
1995+ channel_transaction_parameters: post_channel_transaction_parameters,
1996+ value_to_self_msat: post_value_to_self_msat,
1997+ funding_transaction: None,
1998+ counterparty_selected_channel_reserve_satoshis,
1999+ holder_selected_channel_reserve_satoshis,
2000+ #[cfg(debug_assertions)]
2001+ holder_max_commitment_tx_output: Mutex::new((post_value_to_self_msat, (post_channel_value * 1000).saturating_sub(post_value_to_self_msat))),
2002+ #[cfg(debug_assertions)]
2003+ counterparty_max_commitment_tx_output: Mutex::new((post_value_to_self_msat, (post_channel_value * 1000).saturating_sub(post_value_to_self_msat))),
2004+ #[cfg(any(test, fuzzing))]
2005+ next_local_commitment_tx_fee_info_cached: Mutex::new(None),
2006+ #[cfg(any(test, fuzzing))]
2007+ next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
2008+ }
2009+ }
19572010}
19582011
19592012/// Info about a pending splice
@@ -9135,59 +9188,6 @@ impl<SP: Deref> FundedChannel<SP> where
91359188 Ok(())
91369189 }
91379190
9138- /// Helper to build the FundingScope for the splicing channel
9139- #[cfg(splicing)]
9140- fn funding_scope_for_splice(&self, our_funding_satoshis: u64, post_channel_value: u64, is_initiator: bool, counterparty_funding_pubkey: PublicKey) -> FundingScope {
9141- let post_value_to_self_msat = self.funding.value_to_self_msat.saturating_add(our_funding_satoshis);
9142-
9143- let prev_funding_txid = self.funding.channel_transaction_parameters.funding_outpoint
9144- .map(|outpoint| outpoint.txid);
9145- let holder_pubkeys = match &self.context.holder_signer {
9146- ChannelSignerType::Ecdsa(ecdsa) => {
9147- ecdsa.pubkeys(prev_funding_txid, &self.context.secp_ctx)
9148- }
9149- // TODO (taproot|arik)
9150- #[cfg(taproot)]
9151- _ => todo!()
9152- };
9153- let mut post_channel_transaction_parameters = ChannelTransactionParameters {
9154- holder_pubkeys,
9155- holder_selected_contest_delay: self.funding.channel_transaction_parameters.holder_selected_contest_delay,
9156- // The 'outbound' attribute may change, if the the splice is being initiated by the previous acceptor
9157- is_outbound_from_holder: is_initiator,
9158- counterparty_parameters: self.funding.channel_transaction_parameters.counterparty_parameters.clone(),
9159- funding_outpoint: None, // filled later
9160- splice_parent_funding_txid: prev_funding_txid,
9161- channel_type_features: self.funding.channel_transaction_parameters.channel_type_features.clone(),
9162- channel_value_satoshis: post_channel_value,
9163- };
9164- // Update the splicing 'tweak', this will rotate the keys in the signer
9165- if let Some(ref mut counterparty_parameters) = post_channel_transaction_parameters.counterparty_parameters {
9166- counterparty_parameters.pubkeys.funding_pubkey = counterparty_funding_pubkey;
9167- }
9168-
9169- // New reserve values are based on the new channel value, and v2-specific
9170- let counterparty_selected_channel_reserve_satoshis = Some(get_v2_channel_reserve_satoshis(
9171- post_channel_value, self.context.counterparty_dust_limit_satoshis));
9172- let holder_selected_channel_reserve_satoshis = get_v2_channel_reserve_satoshis(
9173- post_channel_value, MIN_CHAN_DUST_LIMIT_SATOSHIS);
9174- FundingScope {
9175- channel_transaction_parameters: post_channel_transaction_parameters,
9176- value_to_self_msat: post_value_to_self_msat,
9177- funding_transaction: None,
9178- counterparty_selected_channel_reserve_satoshis,
9179- holder_selected_channel_reserve_satoshis,
9180- #[cfg(debug_assertions)]
9181- holder_max_commitment_tx_output: Mutex::new((post_value_to_self_msat, (post_channel_value * 1000).saturating_sub(post_value_to_self_msat))),
9182- #[cfg(debug_assertions)]
9183- counterparty_max_commitment_tx_output: Mutex::new((post_value_to_self_msat, (post_channel_value * 1000).saturating_sub(post_value_to_self_msat))),
9184- #[cfg(any(test, fuzzing))]
9185- next_local_commitment_tx_fee_info_cached: Mutex::new(None),
9186- #[cfg(any(test, fuzzing))]
9187- next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
9188- }
9189- }
9190-
91919191 /// See also [`splice_init_checks`]
91929192 #[cfg(splicing)]
91939193 pub(crate) fn splice_init<ES: Deref, L: Deref>(
@@ -9210,7 +9210,7 @@ impl<SP: Deref> FundedChannel<SP> where
92109210 false, // is_outbound
92119211 )?;
92129212
9213- let funding_scope = self.funding_scope_for_splice( our_funding_satoshis, post_channel_value, false, msg.funding_pubkey);
9213+ let funding_scope = FundingScope::for_splice(& self.funding, &self.context, our_funding_satoshis, post_channel_value, false, msg.funding_pubkey);
92149214
92159215 let funding_negotiation_context = FundingNegotiationContext {
92169216 our_funding_satoshis,
@@ -9274,7 +9274,7 @@ impl<SP: Deref> FundedChannel<SP> where
92749274 signer_provider: &SP, entropy_source: &ES, holder_node_id: &PublicKey, logger: &L,
92759275 ) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
92769276 // check if splice is pending
9277- let pending_splice = if let Some(pending_splice) = &self.pending_splice {
9277+ let pending_splice = if let Some(ref mut pending_splice) = &mut self.pending_splice {
92789278 pending_splice
92799279 } else {
92809280 return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
@@ -9305,31 +9305,30 @@ impl<SP: Deref> FundedChannel<SP> where
93059305 true, // is_outbound
93069306 )?;
93079307
9308- let funding_scope = self.funding_scope_for_splice( our_funding_satoshis, post_channel_value, true, msg.funding_pubkey);
9308+ let funding_scope = FundingScope::for_splice(& self.funding, &self.context, our_funding_satoshis, post_channel_value, true, msg.funding_pubkey);
93099309
93109310 let pre_funding_transaction = &self.funding.funding_transaction;
93119311 let pre_funding_txo = &self.funding.get_funding_txo();
93129312 // We need the current funding tx as an extra input
93139313 let prev_funding_input = Self::get_input_of_previous_funding(pre_funding_transaction, pre_funding_txo)?;
9314- let pending_splice_mut = self.pending_splice.as_mut().unwrap(); // existence checked above
9315- debug_assert!(pending_splice_mut.funding_scope.is_none());
9316- pending_splice_mut.funding_scope = Some(funding_scope);
9314+ debug_assert!(pending_splice.funding_scope.is_none());
9315+ pending_splice.funding_scope = Some(funding_scope);
93179316 // update funding values
9318- pending_splice_mut .funding_negotiation_context.our_funding_satoshis = our_funding_satoshis;
9319- pending_splice_mut .funding_negotiation_context.their_funding_satoshis = Some(their_funding_satoshis);
9320- pending_splice_mut .interactive_tx_constructor = None;
9321- pending_splice_mut .interactive_tx_signing_session = None;
9317+ pending_splice .funding_negotiation_context.our_funding_satoshis = our_funding_satoshis;
9318+ pending_splice .funding_negotiation_context.their_funding_satoshis = Some(their_funding_satoshis);
9319+ pending_splice .interactive_tx_constructor = None;
9320+ pending_splice .interactive_tx_signing_session = None;
93229321
93239322 log_info!(logger, "Splicing process started after splice_ack, new channel value {}, old {}, outgoing {}, channel_id {}",
93249323 post_channel_value, pre_channel_value, true, self.context.channel_id);
93259324
93269325 // Build NegotiatingChannelView lcoally, simmilar to Channel::as_renegotiating_channel()
93279326 let mut negotiating_view = NegotiatingChannelView {
93289327 context: &mut self.context,
9329- funding: &mut pending_splice_mut .funding_scope.as_mut().unwrap(), // set above
9330- funding_negotiation_context: &mut pending_splice_mut .funding_negotiation_context,
9331- interactive_tx_constructor: &mut pending_splice_mut .interactive_tx_constructor,
9332- interactive_tx_signing_session: &mut pending_splice_mut .interactive_tx_signing_session,
9328+ funding: &mut pending_splice .funding_scope.as_mut().unwrap(), // set above
9329+ funding_negotiation_context: &mut pending_splice .funding_negotiation_context,
9330+ interactive_tx_constructor: &mut pending_splice .interactive_tx_constructor,
9331+ interactive_tx_signing_session: &mut pending_splice .interactive_tx_signing_session,
93339332 holder_commitment_transaction_number: self.holder_commitment_point.transaction_number(),
93349333 is_splice: true,
93359334 };
0 commit comments