Skip to content

Commit 5d8dd02

Browse files
committed
Expand documentation and fields in SpendableOutputDescriptors
This adds a channel_value_satoshis field to SpendableOutputDescriptors as it is required to recreate our InMemoryChannelKeys. It also slightly expands documentation.
1 parent 151d4ac commit 5d8dd02

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2206,8 +2206,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
22062206
per_commitment_point: broadcasted_holder_revokable_script.1,
22072207
to_self_delay: self.on_holder_tx_csv,
22082208
output: outp.clone(),
2209-
key_derivation_params: self.key_derivation_params,
22102209
revocation_pubkey: broadcasted_holder_revokable_script.2.clone(),
2210+
key_derivation_params: self.key_derivation_params,
2211+
channel_value_satoshis: self.channel_value_satoshis,
22112212
});
22122213
break;
22132214
}
@@ -2216,6 +2217,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
22162217
outpoint: OutPoint { txid: tx.txid(), index: i as u16 },
22172218
output: outp.clone(),
22182219
key_derivation_params: self.key_derivation_params,
2220+
channel_value_satoshis: self.channel_value_satoshis,
22192221
});
22202222
break;
22212223
} else if outp.script_pubkey == self.shutdown_script {

lightning/src/chain/keysinterface.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ use ln::msgs::DecodeError;
4747
/// that txid/index, and any keys or other information required to sign.
4848
#[derive(Clone, Debug, PartialEq)]
4949
pub enum SpendableOutputDescriptor {
50-
/// An output to a script which was provided via KeysInterface, thus you should already know
51-
/// how to spend it. No keys are provided as rust-lightning was never given any keys - only the
52-
/// script_pubkey as it appears in the output.
50+
/// An output to a script which was provided via KeysInterface directly, either from
51+
/// `get_destination_script()` or `get_shutdown_pubkey()`, thus you should already know how to
52+
/// spend it. No keys are provided as rust-lightning was never given any key.
5353
/// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
5454
/// on-chain using the payment preimage or after it has timed out.
5555
StaticOutput {
@@ -98,11 +98,14 @@ pub enum SpendableOutputDescriptor {
9898
to_self_delay: u16,
9999
/// The output which is referenced by the given outpoint
100100
output: TxOut,
101-
/// The channel keys state used to proceed to derivation of signing key. Must
102-
/// be pass to KeysInterface::derive_channel_keys.
103-
key_derivation_params: (u64, u64),
104101
/// The revocation_pubkey used to derive witnessScript
105-
revocation_pubkey: PublicKey
102+
revocation_pubkey: PublicKey,
103+
/// Arbitrary identification information returned by a call to
104+
/// `ChannelKeys::key_derivation_params()`. This may be useful in re-deriving keys used in
105+
/// the channel to spend the output.
106+
key_derivation_params: (u64, u64),
107+
/// The value of the channel which this transactions spends.
108+
channel_value_satoshis: u64,
106109
},
107110
/// An output to a P2WPKH, spendable exclusively by our payment key (ie the private key which
108111
/// corresponds to the public key in ChannelKeys::pubkeys().payment_point).
@@ -116,9 +119,12 @@ pub enum SpendableOutputDescriptor {
116119
outpoint: OutPoint,
117120
/// The output which is reference by the given outpoint
118121
output: TxOut,
119-
/// The channel keys state used to proceed to derivation of signing key. Must
120-
/// be pass to KeysInterface::derive_channel_keys.
122+
/// Arbitrary identification information returned by a call to
123+
/// `ChannelKeys::key_derivation_params()`. This may be useful in re-deriving keys used in
124+
/// the channel to spend the output.
121125
key_derivation_params: (u64, u64),
126+
/// The value of the channel which this transactions spends.
127+
channel_value_satoshis: u64,
122128
}
123129
}
124130

@@ -130,22 +136,24 @@ impl Writeable for SpendableOutputDescriptor {
130136
outpoint.write(writer)?;
131137
output.write(writer)?;
132138
},
133-
&SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey } => {
139+
&SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref revocation_pubkey, ref key_derivation_params, channel_value_satoshis } => {
134140
1u8.write(writer)?;
135141
outpoint.write(writer)?;
136142
per_commitment_point.write(writer)?;
137143
to_self_delay.write(writer)?;
138144
output.write(writer)?;
145+
revocation_pubkey.write(writer)?;
139146
key_derivation_params.0.write(writer)?;
140147
key_derivation_params.1.write(writer)?;
141-
revocation_pubkey.write(writer)?;
148+
channel_value_satoshis.write(writer)?;
142149
},
143-
&SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref key_derivation_params } => {
150+
&SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref key_derivation_params, channel_value_satoshis } => {
144151
2u8.write(writer)?;
145152
outpoint.write(writer)?;
146153
output.write(writer)?;
147154
key_derivation_params.0.write(writer)?;
148155
key_derivation_params.1.write(writer)?;
156+
channel_value_satoshis.write(writer)?;
149157
},
150158
}
151159
Ok(())
@@ -164,13 +172,15 @@ impl Readable for SpendableOutputDescriptor {
164172
per_commitment_point: Readable::read(reader)?,
165173
to_self_delay: Readable::read(reader)?,
166174
output: Readable::read(reader)?,
167-
key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?),
168175
revocation_pubkey: Readable::read(reader)?,
176+
key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?),
177+
channel_value_satoshis: Readable::read(reader)?,
169178
}),
170179
2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment {
171180
outpoint: Readable::read(reader)?,
172181
output: Readable::read(reader)?,
173182
key_derivation_params: (Readable::read(reader)?, Readable::read(reader)?),
183+
channel_value_satoshis: Readable::read(reader)?,
174184
}),
175185
_ => Err(DecodeError::InvalidValue),
176186
}

lightning/src/ln/functional_tests.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4662,7 +4662,8 @@ macro_rules! check_spendable_outputs {
46624662
Event::SpendableOutputs { ref outputs } => {
46634663
for outp in outputs {
46644664
match *outp {
4665-
SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref key_derivation_params } => {
4665+
SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref key_derivation_params, channel_value_satoshis } => {
4666+
assert_eq!(channel_value_satoshis, $chan_value);
46664667
let input = TxIn {
46674668
previous_output: outpoint.into_bitcoin_outpoint(),
46684669
script_sig: Script::new(),
@@ -4691,7 +4692,8 @@ macro_rules! check_spendable_outputs {
46914692
spend_tx.input[0].witness.push(remotepubkey.serialize().to_vec());
46924693
txn.push(spend_tx);
46934694
},
4694-
SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref key_derivation_params, ref revocation_pubkey } => {
4695+
SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref revocation_pubkey, ref key_derivation_params, channel_value_satoshis } => {
4696+
assert_eq!(channel_value_satoshis, $chan_value);
46954697
let input = TxIn {
46964698
previous_output: outpoint.into_bitcoin_outpoint(),
46974699
script_sig: Script::new(),

0 commit comments

Comments
 (0)