Skip to content

Commit 30a1275

Browse files
authored
Merge pull request #458 from TheBlueMatt/2020-01-spendable-docs
Clean up documentation around spendable outputs significantly.
2 parents 4fa6d96 + 6c9180f commit 30a1275

File tree

2 files changed

+38
-24
lines changed

2 files changed

+38
-24
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,43 +30,56 @@ use ln::msgs;
3030
use std::sync::Arc;
3131
use std::sync::atomic::{AtomicUsize, Ordering};
3232

33-
/// When on-chain outputs are created by rust-lightning an event is generated which informs the
34-
/// user thereof. This enum describes the format of the output and provides the OutPoint.
33+
/// When on-chain outputs are created by rust-lightning (which our counterparty is not able to
34+
/// claim at any point in the future) an event is generated which you must track and be able to
35+
/// spend on-chain. The information needed to do this is provided in this enum, including the
36+
/// outpoint describing which txid and output index is available, the full output which exists at
37+
/// that txid/index, and any keys or other information required to sign.
3538
pub enum SpendableOutputDescriptor {
36-
/// Outpoint with an output to a script which was provided via KeysInterface, thus you should
37-
/// have stored somewhere how to spend script_pubkey!
38-
/// Outputs from a justice tx, claim tx or preimage tx
39+
/// An output to a script which was provided via KeysInterface, thus you should already know
40+
/// how to spend it. No keys are provided as rust-lightning was never given any keys - only the
41+
/// script_pubkey as it appears in the output.
42+
/// These may include outputs from a transaction punishing our counterparty or claiming an HTLC
43+
/// on-chain using the payment preimage or after it has timed out.
3944
StaticOutput {
40-
/// The outpoint spendable by user wallet
45+
/// The outpoint which is spendable
4146
outpoint: OutPoint,
42-
/// The output which is referenced by the given outpoint
47+
/// The output which is referenced by the given outpoint.
4348
output: TxOut,
4449
},
45-
/// Outpoint commits to a P2WSH
46-
/// P2WSH should be spend by the following witness :
47-
/// <local_delayedsig> 0 <witnessScript>
48-
/// With input nSequence set to_self_delay.
49-
/// Outputs from a HTLC-Success/Timeout tx/commitment tx
50+
/// An output to a P2WSH script which can be spent with a single signature after a CSV delay.
51+
/// The private key which should be used to sign the transaction is provided, as well as the
52+
/// full witness redeemScript which is hashed in the output script_pubkey.
53+
/// The witness in the spending input should be:
54+
/// <BIP 143 signature generated with the given key> <one zero byte aka OP_0>
55+
/// <witness_script as provided>
56+
/// Note that the nSequence field in the input must be set to_self_delay (which corresponds to
57+
/// the transaction not being broadcastable until at least to_self_delay blocks after the input
58+
/// confirms).
59+
/// These are generally the result of a "revocable" output to us, spendable only by us unless
60+
/// it is an output from us having broadcast an old state (which should never happen).
5061
DynamicOutputP2WSH {
51-
/// Outpoint spendable by user wallet
62+
/// The outpoint which is spendable
5263
outpoint: OutPoint,
53-
/// local_delayedkey = delayed_payment_basepoint_secret + SHA256(per_commitment_point || delayed_payment_basepoint) OR
64+
/// The secret key which must be used to sign the spending transaction
5465
key: SecretKey,
55-
/// witness redeemScript encumbering output.
66+
/// The witness redeemScript which is hashed to create the script_pubkey in the given output
5667
witness_script: Script,
57-
/// nSequence input must commit to self_delay to satisfy script's OP_CSV
68+
/// The nSequence value which must be set in the spending input to satisfy the OP_CSV in
69+
/// the witness_script.
5870
to_self_delay: u16,
5971
/// The output which is referenced by the given outpoint
6072
output: TxOut,
6173
},
62-
/// Outpoint commits to a P2WPKH
63-
/// P2WPKH should be spend by the following witness :
64-
/// <local_sig> <local_pubkey>
65-
/// Outputs to_remote from a commitment tx
74+
/// An output to a P2WPKH, spendable exclusively by the given private key.
75+
/// The witness in the spending input, is, thus, simply:
76+
/// <BIP 143 signature generated with the given key> <public key derived from the given key>
77+
/// These are generally the result of our counterparty having broadcast the current state,
78+
/// allowing us to claim the non-HTLC-encumbered outputs immediately.
6679
DynamicOutputP2WPKH {
67-
/// Outpoint spendable by user wallet
80+
/// The outpoint which is spendable
6881
outpoint: OutPoint,
69-
/// localkey = payment_basepoint_secret + SHA256(per_commitment_point || payment_basepoint
82+
/// The secret key which must be used to sign the spending transaction
7083
key: SecretKey,
7184
/// The output which is reference by the given outpoint
7285
output: TxOut,

lightning/src/util/events.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,9 @@ pub enum Event {
9999
time_forwardable: Duration,
100100
},
101101
/// Used to indicate that an output was generated on-chain which you should know how to spend.
102-
/// Such an output will *not* ever be spent by rust-lightning, so you need to store them
103-
/// somewhere and spend them when you create on-chain spends.
102+
/// Such an output will *not* ever be spent by rust-lightning, and are not at risk of your
103+
/// counterparty spending them due to some kind of timeout. Thus, you need to store them
104+
/// somewhere and spend them when you create on-chain transactions.
104105
SpendableOutputs {
105106
/// The outputs which you should store as spendable by you.
106107
outputs: Vec<SpendableOutputDescriptor>,

0 commit comments

Comments
 (0)