Skip to content

Commit 5e5b9d2

Browse files
committed
fix Smaller local code changes
ChannelTransactionParameters: clone only unchanged members. Optimize checking twice for pending_splice in splice_ack.
1 parent b3529e3 commit 5e5b9d2

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

lightning/src/ln/channel.rs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9219,27 +9219,31 @@ impl<SP: Deref> FundedChannel<SP> where
92199219

92209220
/// Helper to build the FundingScope for the splicing channel
92219221
#[cfg(splicing)]
9222-
fn funding_scope_for_splice(&self, our_funding_satoshis: u64, post_channel_value: u64, is_outbound: bool, counterparty_funding_pubkey: PublicKey) -> FundingScope {
9222+
fn funding_scope_for_splice(&self, our_funding_satoshis: u64, post_channel_value: u64, is_initiator: bool, counterparty_funding_pubkey: PublicKey) -> FundingScope {
92239223
let post_value_to_self_msat = self.funding.value_to_self_msat.saturating_add(our_funding_satoshis);
92249224

9225-
let mut post_channel_transaction_parameters = self.funding.channel_transaction_parameters.clone();
9226-
// Updated fields:
9227-
post_channel_transaction_parameters.channel_value_satoshis = post_channel_value;
9228-
post_channel_transaction_parameters.is_outbound_from_holder = is_outbound;
9229-
// Update the splicing 'tweak', this will rotate the keys in the signer
92309225
let prev_funding_txid = self.funding.channel_transaction_parameters.funding_outpoint
92319226
.map(|outpoint| outpoint.txid);
9232-
post_channel_transaction_parameters.splice_parent_funding_txid = prev_funding_txid;
9233-
match &self.context.holder_signer {
9227+
let holder_pubkeys = match &self.context.holder_signer {
92349228
ChannelSignerType::Ecdsa(ecdsa) => {
9235-
post_channel_transaction_parameters.holder_pubkeys =
9236-
ecdsa.pubkeys(prev_funding_txid, &self.context.secp_ctx);
9229+
ecdsa.pubkeys(prev_funding_txid, &self.context.secp_ctx)
92379230
}
92389231
// TODO (taproot|arik)
92399232
#[cfg(taproot)]
92409233
_ => todo!()
9241-
}
9242-
post_channel_transaction_parameters.funding_outpoint = None; // filled later
9234+
};
9235+
let mut post_channel_transaction_parameters = ChannelTransactionParameters {
9236+
holder_pubkeys,
9237+
holder_selected_contest_delay: self.funding.channel_transaction_parameters.holder_selected_contest_delay,
9238+
// The 'outbound' attribute may change, if the the splice is being initiated by the previous acceptor
9239+
is_outbound_from_holder: is_initiator,
9240+
counterparty_parameters: self.funding.channel_transaction_parameters.counterparty_parameters.clone(),
9241+
funding_outpoint: None, // filled later
9242+
splice_parent_funding_txid: prev_funding_txid,
9243+
channel_type_features: self.funding.channel_transaction_parameters.channel_type_features.clone(),
9244+
channel_value_satoshis: post_channel_value,
9245+
};
9246+
// Update the splicing 'tweak', this will rotate the keys in the signer
92439247
if let Some(ref mut counterparty_parameters) = post_channel_transaction_parameters.counterparty_parameters {
92449248
counterparty_parameters.pubkeys.funding_pubkey = counterparty_funding_pubkey;
92459249
}
@@ -9375,18 +9379,15 @@ impl<SP: Deref> FundedChannel<SP> where
93759379
let pre_funding_txo = &self.funding.get_funding_txo();
93769380
// We need the current funding tx as an extra input
93779381
let prev_funding_input = Self::get_input_of_previous_funding(pre_funding_transaction, pre_funding_txo)?;
9378-
if let Some(ref mut pending_splice) = &mut self.pending_splice {
9379-
pending_splice.funding_scope = Some(funding_scope);
9380-
// update funding values
9381-
pending_splice.funding_negotiation_context.our_funding_satoshis = our_funding_satoshis;
9382-
pending_splice.funding_negotiation_context.their_funding_satoshis = Some(their_funding_satoshis);
9383-
pending_splice.interactive_tx_constructor = None;
9384-
pending_splice.interactive_tx_signing_session = None;
9385-
debug_assert!(pending_splice.awaiting_splice_ack);
9386-
pending_splice.awaiting_splice_ack = false;
9387-
} else {
9388-
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
9389-
};
9382+
let pending_splice_mut = self.pending_splice.as_mut().unwrap(); // existence checked above
9383+
pending_splice_mut.funding_scope = Some(funding_scope);
9384+
// update funding values
9385+
pending_splice_mut.funding_negotiation_context.our_funding_satoshis = our_funding_satoshis;
9386+
pending_splice_mut.funding_negotiation_context.their_funding_satoshis = Some(their_funding_satoshis);
9387+
pending_splice_mut.interactive_tx_constructor = None;
9388+
pending_splice_mut.interactive_tx_signing_session = None;
9389+
debug_assert!(pending_splice_mut.awaiting_splice_ack);
9390+
pending_splice_mut.awaiting_splice_ack = false;
93909391

93919392
// TODO(splicing): Pre-check for reserve requirement
93929393
// (Note: It should also be checked later at tx_complete)

0 commit comments

Comments
 (0)