Merge pull request #2512 from arik-so/taproot/2023-08-taproot-signer-variant
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Tue, 28 Nov 2023 18:10:53 +0000 (18:10 +0000)
committerGitHub <noreply@github.com>
Tue, 28 Nov 2023 18:10:53 +0000 (18:10 +0000)
Taproot signer variant

lightning/src/chain/channelmonitor.rs
lightning/src/sign/mod.rs

index 832e60f5dc75208ce1bb2332aaa784e926adb64f..62d254a5377d412adb12e9bc9b47863455090641 100644 (file)
@@ -4082,6 +4082,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                spendable_outputs.push(SpendableOutputDescriptor::StaticOutput {
                                        outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
                                        output: outp.clone(),
+                                       channel_keys_id: Some(self.channel_keys_id),
                                });
                        }
                        if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script {
@@ -4110,6 +4111,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
                                spendable_outputs.push(SpendableOutputDescriptor::StaticOutput {
                                        outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
                                        output: outp.clone(),
+                                       channel_keys_id: Some(self.channel_keys_id),
                                });
                        }
                }
index 9de3ed8dc534ff9d08721d5640ddbb7fa717541a..d8f71f590534555988d5f06d4a9757b70baa4f8c 100644 (file)
@@ -215,6 +215,15 @@ pub enum SpendableOutputDescriptor {
                outpoint: OutPoint,
                /// The output which is referenced by the given outpoint.
                output: TxOut,
+               /// The `channel_keys_id` for the channel which this output came from.
+               ///
+               /// For channels which were generated on LDK 0.0.119 or later, this is the value which was
+               /// passed to the [`SignerProvider::get_destination_script`] call which provided this
+               /// output script.
+               ///
+               /// For channels which were generated prior to LDK 0.0.119, no such argument existed,
+               /// however this field may still be filled in if such data is available.
+               channel_keys_id: Option<[u8; 32]>
        },
        /// An output to a P2WSH script which can be spent with a single signature after an `OP_CSV`
        /// delay.
@@ -278,6 +287,7 @@ pub enum SpendableOutputDescriptor {
 impl_writeable_tlv_based_enum!(SpendableOutputDescriptor,
        (0, StaticOutput) => {
                (0, outpoint, required),
+               (1, channel_keys_id, option),
                (2, output, required),
        },
 ;
@@ -378,7 +388,7 @@ impl SpendableOutputDescriptor {
                                        { witness_weight -= 1; } // Guarantees a low R signature
                                        input_value += descriptor.output.value;
                                },
-                               SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output } => {
+                               SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output, .. } => {
                                        if !output_set.insert(*outpoint) { return Err(()); }
                                        input.push(TxIn {
                                                previous_output: outpoint.into_bitcoin_outpoint(),
@@ -1540,7 +1550,7 @@ impl KeysManager {
                                        let witness = keys_cache.as_ref().unwrap().0.sign_dynamic_p2wsh_input(&psbt.unsigned_tx, input_idx, &descriptor, &secp_ctx)?;
                                        psbt.inputs[input_idx].final_script_witness = Some(witness);
                                },
-                               SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output } => {
+                               SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output, .. } => {
                                        let input_idx = psbt.unsigned_tx.input.iter().position(|i| i.previous_output == outpoint.into_bitcoin_outpoint()).ok_or(())?;
                                        let derivation_idx = if output.script_pubkey == self.destination_script {
                                                1