@@ -2192,6 +2192,11 @@ impl FundingScope {
21922192 self.channel_transaction_parameters.make_funding_redeemscript()
21932193 }
21942194
2195+ #[cfg(splicing)]
2196+ fn holder_funding_pubkey(&self) -> &PublicKey {
2197+ &self.get_holder_pubkeys().funding_pubkey
2198+ }
2199+
21952200 fn counterparty_funding_pubkey(&self) -> &PublicKey {
21962201 &self.get_counterparty_pubkeys().funding_pubkey
21972202 }
@@ -2335,8 +2340,16 @@ impl FundingScope {
23352340 };
23362341
23372342 let local_owned = self.value_to_self_msat / 1000;
2338-
2339- SharedOwnedInput::new(input, prev_output, local_owned)
2343+ let holder_sig_first = self.holder_funding_pubkey().serialize()[..]
2344+ < self.counterparty_funding_pubkey().serialize()[..];
2345+
2346+ SharedOwnedInput::new(
2347+ input,
2348+ prev_output,
2349+ local_owned,
2350+ holder_sig_first,
2351+ self.get_funding_redeemscript(),
2352+ )
23402353 }
23412354}
23422355
@@ -7969,9 +7982,9 @@ where
79697982 }
79707983
79717984 pub fn funding_transaction_signed(
7972- &mut self, witnesses: Vec<Witness>,
7985+ &mut self, funding_txid_signed: Txid, witnesses: Vec<Witness>,
79737986 ) -> Result<(Option<msgs::TxSignatures>, Option<Transaction>), APIError> {
7974- let (funding_tx_opt, tx_signatures_opt ) = self
7987+ let (tx_signatures_opt, funding_tx_opt ) = self
79757988 .interactive_tx_signing_session
79767989 .as_mut()
79777990 .ok_or_else(|| APIError::APIMisuseError {
@@ -7981,12 +7994,21 @@ where
79817994 ),
79827995 })
79837996 .and_then(|signing_session| {
7997+ let tx = signing_session.unsigned_tx().build_unsigned_tx();
7998+ if funding_txid_signed != tx.compute_txid() {
7999+ return Err(APIError::APIMisuseError {
8000+ err: "Transaction was malleated prior to signing".to_owned(),
8001+ });
8002+ }
8003+
8004+ let tx_signatures = msgs::TxSignatures {
8005+ channel_id: self.context.channel_id,
8006+ tx_hash: funding_txid_signed,
8007+ witnesses,
8008+ shared_input_signature: None,
8009+ };
79848010 signing_session
7985- .provide_holder_witnesses(
7986- &self.context.secp_ctx,
7987- self.context.channel_id,
7988- witnesses,
7989- )
8011+ .provide_holder_witnesses(tx_signatures, &self.context.secp_ctx)
79908012 .map_err(|err| APIError::APIMisuseError { err })
79918013 })?;
79928014
@@ -8004,7 +8026,7 @@ where
80048026 }
80058027
80068028 #[rustfmt::skip]
8007- pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<Transaction >, Option<msgs::TxSignatures >), ChannelError> {
8029+ pub fn tx_signatures(&mut self, msg: &msgs::TxSignatures) -> Result<(Option<msgs::TxSignatures >, Option<Transaction >), ChannelError> {
80088030 if !self.context.channel_state.is_interactive_signing()
80098031 || self.context.channel_state.is_their_tx_signatures_sent()
80108032 {
@@ -8035,7 +8057,7 @@ where
80358057 }
80368058 }
80378059
8038- let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg.clone() )
8060+ let (holder_tx_signatures_opt, funding_tx_opt) = signing_session.received_tx_signatures(msg)
80398061 .map_err(|msg| ChannelError::Warn(msg))?;
80408062
80418063 // Set `THEIR_TX_SIGNATURES_SENT` flag after all potential errors.
@@ -8050,7 +8072,7 @@ where
80508072 self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
80518073 }
80528074
8053- Ok((funding_tx_opt, holder_tx_signatures_opt ))
8075+ Ok((holder_tx_signatures_opt, funding_tx_opt ))
80548076 } else {
80558077 let msg = "Unexpected tx_signatures. No funding transaction awaiting signatures";
80568078 let reason = ClosureReason::ProcessingError { err: msg.to_owned() };
0 commit comments