Skip to content

Commit 36cc581

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 e885d0a commit 36cc581

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
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-
channel_keys_id: self.channel_keys_id,
22102209
revocation_pubkey: broadcasted_holder_revokable_script.2.clone(),
2210+
channel_keys_id: self.channel_keys_id,
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
channel_keys_id: self.channel_keys_id,
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 secret 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-
channel_keys_id: [u8; 32],
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::channel_keys_id()`. This may be useful in re-deriving keys used in
105+
/// the channel to spend the output.
106+
channel_keys_id: [u8; 32],
107+
/// The value of the channel which this output originated from, possibly indirectly.
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::channel_keys_id()`. This may be useful in re-deriving keys used in
124+
/// the channel to spend the output.
121125
channel_keys_id: [u8; 32],
126+
/// The value of the channel which this transactions spends.
127+
channel_value_satoshis: u64,
122128
}
123129
}
124130

@@ -130,20 +136,22 @@ 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 channel_keys_id, ref revocation_pubkey } => {
139+
&SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref revocation_pubkey, ref channel_keys_id, 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)?;
139-
channel_keys_id.write(writer)?;
140145
revocation_pubkey.write(writer)?;
146+
channel_keys_id.write(writer)?;
147+
channel_value_satoshis.write(writer)?;
141148
},
142-
&SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref channel_keys_id } => {
149+
&SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref channel_keys_id, channel_value_satoshis } => {
143150
2u8.write(writer)?;
144151
outpoint.write(writer)?;
145152
output.write(writer)?;
146153
channel_keys_id.write(writer)?;
154+
channel_value_satoshis.write(writer)?;
147155
},
148156
}
149157
Ok(())
@@ -162,13 +170,15 @@ impl Readable for SpendableOutputDescriptor {
162170
per_commitment_point: Readable::read(reader)?,
163171
to_self_delay: Readable::read(reader)?,
164172
output: Readable::read(reader)?,
165-
channel_keys_id: Readable::read(reader)?,
166173
revocation_pubkey: Readable::read(reader)?,
174+
channel_keys_id: Readable::read(reader)?,
175+
channel_value_satoshis: Readable::read(reader)?,
167176
}),
168177
2u8 => Ok(SpendableOutputDescriptor::StaticOutputCounterpartyPayment {
169178
outpoint: Readable::read(reader)?,
170179
output: Readable::read(reader)?,
171180
channel_keys_id: Readable::read(reader)?,
181+
channel_value_satoshis: Readable::read(reader)?,
172182
}),
173183
_ => Err(DecodeError::InvalidValue),
174184
}

lightning/src/ln/functional_tests.rs

Lines changed: 5 additions & 3 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 channel_keys_id } => {
4665+
SpendableOutputDescriptor::StaticOutputCounterpartyPayment { ref outpoint, ref output, ref channel_keys_id, 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 channel_keys_id, ref revocation_pubkey } => {
4695+
SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref per_commitment_point, ref to_self_delay, ref output, ref revocation_pubkey, ref channel_keys_id, 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(),
@@ -7484,7 +7486,7 @@ fn test_data_loss_protect() {
74847486
let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42};
74857487
connect_block(&nodes[0], &Block { header, txdata: vec![node_txn[0].clone()]}, 0);
74867488
connect_blocks(&nodes[0], ANTI_REORG_DELAY - 1, 0, true, header.block_hash());
7487-
let spend_txn = check_spendable_outputs!(nodes[0], 1, node_cfgs[0].keys_manager, 100000);
7489+
let spend_txn = check_spendable_outputs!(nodes[0], 1, node_cfgs[0].keys_manager, 1000000);
74887490
assert_eq!(spend_txn.len(), 1);
74897491
check_spends!(spend_txn[0], node_txn[0]);
74907492
}

0 commit comments

Comments
 (0)