From: Matt Corallo Date: Tue, 16 Feb 2021 21:15:40 +0000 (-0500) Subject: Rename output descriptor types for some clarity X-Git-Tag: v0.0.13~28^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=95d0fe99ee568f8edfe6b6a66f97e810051e04c4;p=rust-lightning Rename output descriptor types for some clarity Both Miron and Val suggested naming tweaks in their reviews, so clarifying things some would be good. --- diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index 91c2a3c5..83b57c8e 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -43,7 +43,7 @@ use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash}; use ln::onchaintx::{OnchainTxHandler, InputDescriptors}; use chain::chaininterface::{BroadcasterInterface, FeeEstimator}; use chain::transaction::{OutPoint, TransactionData}; -use chain::keysinterface::{SpendableOutputDescriptor, StaticCounterpartyPaymentOutputDescriptor, DynamicP2WSHOutputDescriptor, ChannelKeys, KeysInterface}; +use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, ChannelKeys, KeysInterface}; use util::logger::Logger; use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48}; use util::byte_utils; @@ -2201,7 +2201,7 @@ impl ChannelMonitor { break; } else if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script { if broadcasted_holder_revokable_script.0 == outp.script_pubkey { - spendable_output = Some(SpendableOutputDescriptor::DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor { + spendable_output = Some(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor { outpoint: OutPoint { txid: tx.txid(), index: i as u16 }, per_commitment_point: broadcasted_holder_revokable_script.1, to_self_delay: self.on_holder_tx_csv, @@ -2213,7 +2213,7 @@ impl ChannelMonitor { break; } } else if self.counterparty_payment_script == outp.script_pubkey { - spendable_output = Some(SpendableOutputDescriptor::StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor { + spendable_output = Some(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor { outpoint: OutPoint { txid: tx.txid(), index: i as u16 }, output: outp.clone(), channel_keys_id: self.channel_keys_id, diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index 706f9d88..b3e33b57 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -42,9 +42,9 @@ use std::io::Error; use ln::msgs::{DecodeError, MAX_VALUE_MSAT}; /// Information about a spendable output to a P2WSH script. See -/// SpendableOutputDescriptor::DynamicOutputP2WSH for more details on how to spend this. +/// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this. #[derive(Clone, Debug, PartialEq)] -pub struct DynamicP2WSHOutputDescriptor { +pub struct DelayedPaymentOutputDescriptor { /// The outpoint which is spendable pub outpoint: OutPoint, /// Per commitment point to derive delayed_payment_key by key holder @@ -64,7 +64,7 @@ pub struct DynamicP2WSHOutputDescriptor { /// The value of the channel which this output originated from, possibly indirectly. pub channel_value_satoshis: u64, } -impl DynamicP2WSHOutputDescriptor { +impl DelayedPaymentOutputDescriptor { /// The maximum length a well-formed witness spending one of these should have. // Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus // redeemscript push length. @@ -72,9 +72,9 @@ impl DynamicP2WSHOutputDescriptor { } /// Information about a spendable output to our "payment key". See -/// SpendableOutputDescriptor::StaticOutputCounterpartyPayment for more details on how to spend this. +/// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this. #[derive(Clone, Debug, PartialEq)] -pub struct StaticCounterpartyPaymentOutputDescriptor { +pub struct StaticPaymentOutputDescriptor { /// The outpoint which is spendable pub outpoint: OutPoint, /// The output which is referenced by the given outpoint @@ -86,7 +86,7 @@ pub struct StaticCounterpartyPaymentOutputDescriptor { /// The value of the channel which this transactions spends. pub channel_value_satoshis: u64, } -impl StaticCounterpartyPaymentOutputDescriptor { +impl StaticPaymentOutputDescriptor { /// The maximum length a well-formed witness spending one of these should have. // Calculated as 1 byte legnth + 73 byte signature, 1 byte empty vec push, 1 byte length plus // redeemscript push length. @@ -139,7 +139,7 @@ pub enum SpendableOutputDescriptor { /// regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey /// (derived as above), and the to_self_delay contained here to /// chan_utils::get_revokeable_redeemscript. - DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor), + DelayedPaymentOutput(DelayedPaymentOutputDescriptor), /// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which /// corresponds to the public key in ChannelKeys::pubkeys().payment_point). /// The witness in the spending input, is, thus, simply: @@ -147,7 +147,7 @@ pub enum SpendableOutputDescriptor { /// /// These are generally the result of our counterparty having broadcast the current state, /// allowing us to claim the non-HTLC-encumbered outputs immediately. - StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor), + StaticPaymentOutput(StaticPaymentOutputDescriptor), } impl Writeable for SpendableOutputDescriptor { @@ -158,7 +158,7 @@ impl Writeable for SpendableOutputDescriptor { outpoint.write(writer)?; output.write(writer)?; }, - &SpendableOutputDescriptor::DynamicOutputP2WSH(ref descriptor) => { + &SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) => { 1u8.write(writer)?; descriptor.outpoint.write(writer)?; descriptor.per_commitment_point.write(writer)?; @@ -168,7 +168,7 @@ impl Writeable for SpendableOutputDescriptor { descriptor.channel_keys_id.write(writer)?; descriptor.channel_value_satoshis.write(writer)?; }, - &SpendableOutputDescriptor::StaticOutputCounterpartyPayment(ref descriptor) => { + &SpendableOutputDescriptor::StaticPaymentOutput(ref descriptor) => { 2u8.write(writer)?; descriptor.outpoint.write(writer)?; descriptor.output.write(writer)?; @@ -187,7 +187,7 @@ impl Readable for SpendableOutputDescriptor { outpoint: Readable::read(reader)?, output: Readable::read(reader)?, }), - 1u8 => Ok(SpendableOutputDescriptor::DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor { + 1u8 => Ok(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor { outpoint: Readable::read(reader)?, per_commitment_point: Readable::read(reader)?, to_self_delay: Readable::read(reader)?, @@ -196,7 +196,7 @@ impl Readable for SpendableOutputDescriptor { channel_keys_id: Readable::read(reader)?, channel_value_satoshis: Readable::read(reader)?, })), - 2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor { + 2u8 => Ok(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor { outpoint: Readable::read(reader)?, output: Readable::read(reader)?, channel_keys_id: Readable::read(reader)?, @@ -496,7 +496,7 @@ impl InMemoryChannelKeys { /// /// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig, /// or is not spending the outpoint described by `descriptor.outpoint`. - pub fn sign_counterparty_payment_input(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticCounterpartyPaymentOutputDescriptor, secp_ctx: &Secp256k1) -> Result>, ()> { + pub fn sign_counterparty_payment_input(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticPaymentOutputDescriptor, secp_ctx: &Secp256k1) -> Result>, ()> { // TODO: We really should be taking the SigHashCache as a parameter here instead of // spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only // so that we can check them. This requires upstream rust-bitcoin changes (as well as @@ -523,7 +523,7 @@ impl InMemoryChannelKeys { /// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig, /// is not spending the outpoint described by `descriptor.outpoint`, or does not have a /// sequence set to `descriptor.to_self_delay`. - pub fn sign_dynamic_p2wsh_input(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DynamicP2WSHOutputDescriptor, secp_ctx: &Secp256k1) -> Result>, ()> { + pub fn sign_dynamic_p2wsh_input(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DelayedPaymentOutputDescriptor, secp_ctx: &Secp256k1) -> Result>, ()> { // TODO: We really should be taking the SigHashCache as a parameter here instead of // spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only // so that we can check them. This requires upstream rust-bitcoin changes (as well as @@ -891,25 +891,25 @@ impl KeysManager { let mut output_set = HashSet::with_capacity(descriptors.len()); for outp in descriptors { match outp { - SpendableOutputDescriptor::StaticOutputCounterpartyPayment(descriptor) => { + SpendableOutputDescriptor::StaticPaymentOutput(descriptor) => { input.push(TxIn { previous_output: descriptor.outpoint.into_bitcoin_outpoint(), script_sig: Script::new(), sequence: 0, witness: Vec::new(), }); - witness_weight += StaticCounterpartyPaymentOutputDescriptor::MAX_WITNESS_LENGTH; + witness_weight += StaticPaymentOutputDescriptor::MAX_WITNESS_LENGTH; input_value += descriptor.output.value; if !output_set.insert(descriptor.outpoint) { return Err(()); } }, - SpendableOutputDescriptor::DynamicOutputP2WSH(descriptor) => { + SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => { input.push(TxIn { previous_output: descriptor.outpoint.into_bitcoin_outpoint(), script_sig: Script::new(), sequence: descriptor.to_self_delay as u32, witness: Vec::new(), }); - witness_weight += DynamicP2WSHOutputDescriptor::MAX_WITNESS_LENGTH; + witness_weight += DelayedPaymentOutputDescriptor::MAX_WITNESS_LENGTH; input_value += descriptor.output.value; if !output_set.insert(descriptor.outpoint) { return Err(()); } }, @@ -939,7 +939,7 @@ impl KeysManager { let mut input_idx = 0; for outp in descriptors { match outp { - SpendableOutputDescriptor::StaticOutputCounterpartyPayment(descriptor) => { + SpendableOutputDescriptor::StaticPaymentOutput(descriptor) => { if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id { keys_cache = Some(( self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id), @@ -947,7 +947,7 @@ impl KeysManager { } spend_tx.input[input_idx].witness = keys_cache.as_ref().unwrap().0.sign_counterparty_payment_input(&spend_tx, input_idx, &descriptor, &secp_ctx).unwrap(); }, - SpendableOutputDescriptor::DynamicOutputP2WSH(descriptor) => { + SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => { if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id { keys_cache = Some(( self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id), diff --git a/lightning/src/util/macro_logger.rs b/lightning/src/util/macro_logger.rs index 222964b0..2065f404 100644 --- a/lightning/src/util/macro_logger.rs +++ b/lightning/src/util/macro_logger.rs @@ -138,10 +138,10 @@ impl<'a> std::fmt::Display for DebugSpendable<'a> { &SpendableOutputDescriptor::StaticOutput { ref outpoint, .. } => { write!(f, "StaticOutput {}:{} marked for spending", outpoint.txid, outpoint.index)?; } - &SpendableOutputDescriptor::DynamicOutputP2WSH(ref descriptor) => { - write!(f, "DynamicOutputP2WSH {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?; + &SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) => { + write!(f, "DelayedPaymentOutput {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?; } - &SpendableOutputDescriptor::StaticOutputCounterpartyPayment(ref descriptor) => { + &SpendableOutputDescriptor::StaticPaymentOutput(ref descriptor) => { write!(f, "DynamicOutputP2WPKH {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?; } }