Set the SigHashType of remote htlc signatures w/ anchors to SinglePlusAnyoneCanPay
[rust-lightning] / lightning / src / ln / chan_utils.rs
index cbafbed67bdf20a7e093f97b5531ace7c8452f26..6e11dc42b819e64a61bd65d2f8f5421928bd0a4f 100644 (file)
@@ -1394,6 +1394,8 @@ impl<'a> TrustedCommitmentTransaction<'a> {
        /// which HTLCOutputInCommitment::transaction_output_index.is_some()).
        ///
        /// The returned Vec has one entry for each HTLC, and in the same order.
+       ///
+       /// This function is only valid in the holder commitment context, it always uses SigHashType::All.
        pub fn get_htlc_sigs<T: secp256k1::Signing>(&self, htlc_base_key: &SecretKey, channel_parameters: &DirectedChannelTransactionParameters, secp_ctx: &Secp256k1<T>) -> Result<Vec<Signature>, ()> {
                let inner = self.inner;
                let keys = &inner.keys;
@@ -1429,12 +1431,14 @@ impl<'a> TrustedCommitmentTransaction<'a> {
 
                let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, self.opt_anchors(), &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
 
+               let sighashtype = if self.opt_anchors() { SigHashType::SinglePlusAnyoneCanPay } else { SigHashType::All };
+
                // First push the multisig dummy, note that due to BIP147 (NULLDUMMY) it must be a zero-length element.
                htlc_tx.input[0].witness.push(Vec::new());
 
                htlc_tx.input[0].witness.push(counterparty_signature.serialize_der().to_vec());
                htlc_tx.input[0].witness.push(signature.serialize_der().to_vec());
-               htlc_tx.input[0].witness[1].push(SigHashType::All as u8);
+               htlc_tx.input[0].witness[1].push(sighashtype as u8);
                htlc_tx.input[0].witness[2].push(SigHashType::All as u8);
 
                if this_htlc.offered {