Skip to content

Commit 95d0fe9

Browse files
committed
Rename output descriptor types for some clarity
Both Miron and Val suggested naming tweaks in their reviews, so clarifying things some would be good.
1 parent 8dbadd1 commit 95d0fe9

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use ln::channelmanager::{HTLCSource, PaymentPreimage, PaymentHash};
4343
use ln::onchaintx::{OnchainTxHandler, InputDescriptors};
4444
use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
4545
use chain::transaction::{OutPoint, TransactionData};
46-
use chain::keysinterface::{SpendableOutputDescriptor, StaticCounterpartyPaymentOutputDescriptor, DynamicP2WSHOutputDescriptor, ChannelKeys, KeysInterface};
46+
use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, ChannelKeys, KeysInterface};
4747
use util::logger::Logger;
4848
use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48};
4949
use util::byte_utils;
@@ -2201,7 +2201,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
22012201
break;
22022202
} else if let Some(ref broadcasted_holder_revokable_script) = self.broadcasted_holder_revokable_script {
22032203
if broadcasted_holder_revokable_script.0 == outp.script_pubkey {
2204-
spendable_output = Some(SpendableOutputDescriptor::DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor {
2204+
spendable_output = Some(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor {
22052205
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
22062206
per_commitment_point: broadcasted_holder_revokable_script.1,
22072207
to_self_delay: self.on_holder_tx_csv,
@@ -2213,7 +2213,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
22132213
break;
22142214
}
22152215
} else if self.counterparty_payment_script == outp.script_pubkey {
2216-
spendable_output = Some(SpendableOutputDescriptor::StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor {
2216+
spendable_output = Some(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor {
22172217
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
22182218
output: outp.clone(),
22192219
channel_keys_id: self.channel_keys_id,

lightning/src/chain/keysinterface.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ use std::io::Error;
4242
use ln::msgs::{DecodeError, MAX_VALUE_MSAT};
4343

4444
/// Information about a spendable output to a P2WSH script. See
45-
/// SpendableOutputDescriptor::DynamicOutputP2WSH for more details on how to spend this.
45+
/// SpendableOutputDescriptor::DelayedPaymentOutput for more details on how to spend this.
4646
#[derive(Clone, Debug, PartialEq)]
47-
pub struct DynamicP2WSHOutputDescriptor {
47+
pub struct DelayedPaymentOutputDescriptor {
4848
/// The outpoint which is spendable
4949
pub outpoint: OutPoint,
5050
/// Per commitment point to derive delayed_payment_key by key holder
@@ -64,17 +64,17 @@ pub struct DynamicP2WSHOutputDescriptor {
6464
/// The value of the channel which this output originated from, possibly indirectly.
6565
pub channel_value_satoshis: u64,
6666
}
67-
impl DynamicP2WSHOutputDescriptor {
67+
impl DelayedPaymentOutputDescriptor {
6868
/// The maximum length a well-formed witness spending one of these should have.
6969
// Calculated as 1 byte length + 73 byte signature, 1 byte empty vec push, 1 byte length plus
7070
// redeemscript push length.
7171
pub const MAX_WITNESS_LENGTH: usize = 1 + 73 + 1 + chan_utils::REVOKEABLE_REDEEMSCRIPT_MAX_LENGTH + 1;
7272
}
7373

7474
/// Information about a spendable output to our "payment key". See
75-
/// SpendableOutputDescriptor::StaticOutputCounterpartyPayment for more details on how to spend this.
75+
/// SpendableOutputDescriptor::StaticPaymentOutput for more details on how to spend this.
7676
#[derive(Clone, Debug, PartialEq)]
77-
pub struct StaticCounterpartyPaymentOutputDescriptor {
77+
pub struct StaticPaymentOutputDescriptor {
7878
/// The outpoint which is spendable
7979
pub outpoint: OutPoint,
8080
/// The output which is referenced by the given outpoint
@@ -86,7 +86,7 @@ pub struct StaticCounterpartyPaymentOutputDescriptor {
8686
/// The value of the channel which this transactions spends.
8787
pub channel_value_satoshis: u64,
8888
}
89-
impl StaticCounterpartyPaymentOutputDescriptor {
89+
impl StaticPaymentOutputDescriptor {
9090
/// The maximum length a well-formed witness spending one of these should have.
9191
// Calculated as 1 byte legnth + 73 byte signature, 1 byte empty vec push, 1 byte length plus
9292
// redeemscript push length.
@@ -139,15 +139,15 @@ pub enum SpendableOutputDescriptor {
139139
/// regenerated by passing the revocation_pubkey (derived as above), our delayed_payment pubkey
140140
/// (derived as above), and the to_self_delay contained here to
141141
/// chan_utils::get_revokeable_redeemscript.
142-
DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor),
142+
DelayedPaymentOutput(DelayedPaymentOutputDescriptor),
143143
/// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
144144
/// corresponds to the public key in ChannelKeys::pubkeys().payment_point).
145145
/// The witness in the spending input, is, thus, simply:
146146
/// <BIP 143 signature> <payment key>
147147
///
148148
/// These are generally the result of our counterparty having broadcast the current state,
149149
/// allowing us to claim the non-HTLC-encumbered outputs immediately.
150-
StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor),
150+
StaticPaymentOutput(StaticPaymentOutputDescriptor),
151151
}
152152

153153
impl Writeable for SpendableOutputDescriptor {
@@ -158,7 +158,7 @@ impl Writeable for SpendableOutputDescriptor {
158158
outpoint.write(writer)?;
159159
output.write(writer)?;
160160
},
161-
&SpendableOutputDescriptor::DynamicOutputP2WSH(ref descriptor) => {
161+
&SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) => {
162162
1u8.write(writer)?;
163163
descriptor.outpoint.write(writer)?;
164164
descriptor.per_commitment_point.write(writer)?;
@@ -168,7 +168,7 @@ impl Writeable for SpendableOutputDescriptor {
168168
descriptor.channel_keys_id.write(writer)?;
169169
descriptor.channel_value_satoshis.write(writer)?;
170170
},
171-
&SpendableOutputDescriptor::StaticOutputCounterpartyPayment(ref descriptor) => {
171+
&SpendableOutputDescriptor::StaticPaymentOutput(ref descriptor) => {
172172
2u8.write(writer)?;
173173
descriptor.outpoint.write(writer)?;
174174
descriptor.output.write(writer)?;
@@ -187,7 +187,7 @@ impl Readable for SpendableOutputDescriptor {
187187
outpoint: Readable::read(reader)?,
188188
output: Readable::read(reader)?,
189189
}),
190-
1u8 => Ok(SpendableOutputDescriptor::DynamicOutputP2WSH(DynamicP2WSHOutputDescriptor {
190+
1u8 => Ok(SpendableOutputDescriptor::DelayedPaymentOutput(DelayedPaymentOutputDescriptor {
191191
outpoint: Readable::read(reader)?,
192192
per_commitment_point: Readable::read(reader)?,
193193
to_self_delay: Readable::read(reader)?,
@@ -196,7 +196,7 @@ impl Readable for SpendableOutputDescriptor {
196196
channel_keys_id: Readable::read(reader)?,
197197
channel_value_satoshis: Readable::read(reader)?,
198198
})),
199-
2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment(StaticCounterpartyPaymentOutputDescriptor {
199+
2u8 => Ok(SpendableOutputDescriptor::StaticPaymentOutput(StaticPaymentOutputDescriptor {
200200
outpoint: Readable::read(reader)?,
201201
output: Readable::read(reader)?,
202202
channel_keys_id: Readable::read(reader)?,
@@ -496,7 +496,7 @@ impl InMemoryChannelKeys {
496496
///
497497
/// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
498498
/// or is not spending the outpoint described by `descriptor.outpoint`.
499-
pub fn sign_counterparty_payment_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticCounterpartyPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
499+
pub fn sign_counterparty_payment_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &StaticPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
500500
// TODO: We really should be taking the SigHashCache as a parameter here instead of
501501
// spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
502502
// so that we can check them. This requires upstream rust-bitcoin changes (as well as
@@ -523,7 +523,7 @@ impl InMemoryChannelKeys {
523523
/// Returns an Err if the input at input_idx does not exist, has a non-empty script_sig,
524524
/// is not spending the outpoint described by `descriptor.outpoint`, or does not have a
525525
/// sequence set to `descriptor.to_self_delay`.
526-
pub fn sign_dynamic_p2wsh_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DynamicP2WSHOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
526+
pub fn sign_dynamic_p2wsh_input<C: Signing>(&self, spend_tx: &Transaction, input_idx: usize, descriptor: &DelayedPaymentOutputDescriptor, secp_ctx: &Secp256k1<C>) -> Result<Vec<Vec<u8>>, ()> {
527527
// TODO: We really should be taking the SigHashCache as a parameter here instead of
528528
// spend_tx, but ideally the SigHashCache would expose the transaction's inputs read-only
529529
// so that we can check them. This requires upstream rust-bitcoin changes (as well as
@@ -891,25 +891,25 @@ impl KeysManager {
891891
let mut output_set = HashSet::with_capacity(descriptors.len());
892892
for outp in descriptors {
893893
match outp {
894-
SpendableOutputDescriptor::StaticOutputCounterpartyPayment(descriptor) => {
894+
SpendableOutputDescriptor::StaticPaymentOutput(descriptor) => {
895895
input.push(TxIn {
896896
previous_output: descriptor.outpoint.into_bitcoin_outpoint(),
897897
script_sig: Script::new(),
898898
sequence: 0,
899899
witness: Vec::new(),
900900
});
901-
witness_weight += StaticCounterpartyPaymentOutputDescriptor::MAX_WITNESS_LENGTH;
901+
witness_weight += StaticPaymentOutputDescriptor::MAX_WITNESS_LENGTH;
902902
input_value += descriptor.output.value;
903903
if !output_set.insert(descriptor.outpoint) { return Err(()); }
904904
},
905-
SpendableOutputDescriptor::DynamicOutputP2WSH(descriptor) => {
905+
SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => {
906906
input.push(TxIn {
907907
previous_output: descriptor.outpoint.into_bitcoin_outpoint(),
908908
script_sig: Script::new(),
909909
sequence: descriptor.to_self_delay as u32,
910910
witness: Vec::new(),
911911
});
912-
witness_weight += DynamicP2WSHOutputDescriptor::MAX_WITNESS_LENGTH;
912+
witness_weight += DelayedPaymentOutputDescriptor::MAX_WITNESS_LENGTH;
913913
input_value += descriptor.output.value;
914914
if !output_set.insert(descriptor.outpoint) { return Err(()); }
915915
},
@@ -939,15 +939,15 @@ impl KeysManager {
939939
let mut input_idx = 0;
940940
for outp in descriptors {
941941
match outp {
942-
SpendableOutputDescriptor::StaticOutputCounterpartyPayment(descriptor) => {
942+
SpendableOutputDescriptor::StaticPaymentOutput(descriptor) => {
943943
if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id {
944944
keys_cache = Some((
945945
self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id),
946946
descriptor.channel_keys_id));
947947
}
948948
spend_tx.input[input_idx].witness = keys_cache.as_ref().unwrap().0.sign_counterparty_payment_input(&spend_tx, input_idx, &descriptor, &secp_ctx).unwrap();
949949
},
950-
SpendableOutputDescriptor::DynamicOutputP2WSH(descriptor) => {
950+
SpendableOutputDescriptor::DelayedPaymentOutput(descriptor) => {
951951
if keys_cache.is_none() || keys_cache.as_ref().unwrap().1 != descriptor.channel_keys_id {
952952
keys_cache = Some((
953953
self.derive_channel_keys(descriptor.channel_value_satoshis, &descriptor.channel_keys_id),

lightning/src/util/macro_logger.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,10 @@ impl<'a> std::fmt::Display for DebugSpendable<'a> {
138138
&SpendableOutputDescriptor::StaticOutput { ref outpoint, .. } => {
139139
write!(f, "StaticOutput {}:{} marked for spending", outpoint.txid, outpoint.index)?;
140140
}
141-
&SpendableOutputDescriptor::DynamicOutputP2WSH(ref descriptor) => {
142-
write!(f, "DynamicOutputP2WSH {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?;
141+
&SpendableOutputDescriptor::DelayedPaymentOutput(ref descriptor) => {
142+
write!(f, "DelayedPaymentOutput {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?;
143143
}
144-
&SpendableOutputDescriptor::StaticOutputCounterpartyPayment(ref descriptor) => {
144+
&SpendableOutputDescriptor::StaticPaymentOutput(ref descriptor) => {
145145
write!(f, "DynamicOutputP2WPKH {}:{} marked for spending", descriptor.outpoint.txid, descriptor.outpoint.index)?;
146146
}
147147
}

0 commit comments

Comments
 (0)