@@ -1954,6 +1954,59 @@ impl FundingScope {
1954
1954
pub fn get_channel_type(&self) -> &ChannelTypeFeatures {
1955
1955
&self.channel_transaction_parameters.channel_type_features
1956
1956
}
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
+ }
1957
2010
}
1958
2011
1959
2012
/// Info about a pending splice
@@ -9135,59 +9188,6 @@ impl<SP: Deref> FundedChannel<SP> where
9135
9188
Ok(())
9136
9189
}
9137
9190
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
-
9191
9191
/// See also [`splice_init_checks`]
9192
9192
#[cfg(splicing)]
9193
9193
pub(crate) fn splice_init<ES: Deref, L: Deref>(
@@ -9210,7 +9210,7 @@ impl<SP: Deref> FundedChannel<SP> where
9210
9210
false, // is_outbound
9211
9211
)?;
9212
9212
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);
9214
9214
9215
9215
let funding_negotiation_context = FundingNegotiationContext {
9216
9216
our_funding_satoshis,
@@ -9274,7 +9274,7 @@ impl<SP: Deref> FundedChannel<SP> where
9274
9274
signer_provider: &SP, entropy_source: &ES, holder_node_id: &PublicKey, logger: &L,
9275
9275
) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
9276
9276
// 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 {
9278
9278
pending_splice
9279
9279
} else {
9280
9280
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
@@ -9305,31 +9305,30 @@ impl<SP: Deref> FundedChannel<SP> where
9305
9305
true, // is_outbound
9306
9306
)?;
9307
9307
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);
9309
9309
9310
9310
let pre_funding_transaction = &self.funding.funding_transaction;
9311
9311
let pre_funding_txo = &self.funding.get_funding_txo();
9312
9312
// We need the current funding tx as an extra input
9313
9313
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);
9317
9316
// 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;
9322
9321
9323
9322
log_info!(logger, "Splicing process started after splice_ack, new channel value {}, old {}, outgoing {}, channel_id {}",
9324
9323
post_channel_value, pre_channel_value, true, self.context.channel_id);
9325
9324
9326
9325
// Build NegotiatingChannelView lcoally, simmilar to Channel::as_renegotiating_channel()
9327
9326
let mut negotiating_view = NegotiatingChannelView {
9328
9327
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,
9333
9332
holder_commitment_transaction_number: self.holder_commitment_point.transaction_number(),
9334
9333
is_splice: true,
9335
9334
};
0 commit comments