Update 9_1_Understanding_Timelock_Options.md

This commit is contained in:
Shannon Appelcline 2017-05-24 11:34:54 -07:00 committed by GitHub
parent 6eec269b6a
commit 5340edd897

View File

@ -2,27 +2,47 @@
> **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning. > **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.
In [§6.4: Sending a Transaction with a Locktime](6_4_Sending_a_Transaction_with_a_Locktime.md), `nLocktime` provided a great basis for locking transactions so that they couldn't be spent until some point in the future — based either on time or blockheight. But, that's not the only way to put a timelock on a transaction. In [§6.4: Sending a Transaction with a Locktime](6_4_Sending_a_Transaction_with_a_Locktime.md), `nLocktime` offered a great foundation for locking transactions so that they couldn't be spent until some point in the future — based either on time or blockheight. But, that's not the only way to put a timelock on a transaction.
## Understand the Limitations of nLockTime ## Understand the Limitations of nLockTime
1. [whole transaction] `nLockTime` is a simple and powerful way to lock a transaction, but it has some limitations:
2. [can't even be put on network]
1. **No Splits.** `nLocktime` locks the entire transaction.
2. **No Networking.** Most modern nodes won't accept a `nLockTime` into the memory pool until it's almost ready to finalize.
3. **No Scripts.** The original, simple use of `nLockTime` didn't allow it to be used in Scripts.
4. **No Protection.** `nLockTime` allows the funds to be spent with a different, non-locked transaction.
The last item was often the dealbreaker for `nLockTime`. It prevented a transaction from being spent, but it didn't prevent the funds from being used.
## Understand the Possibilities of Timelock Scripts ## Understand the Possibilities of Timelock Scripts
[a script locks a single output] In more recent years, Bitcoin Core has expanded to include two new sorts of timelocks, _OP_CHECKLOCKTIMEVERIFY_ (CLTV) and _OP_CHECKSEQUENCEVERIFY_ (CSV). These both work under a new methodology that further empowers Bitcoin.
[can be used for as part of more complex redemption conditions]
- largely depend on conditionals in next chapter
here's a catch: [can't be negative; make available in the future, but not the converse] _They Are Opcodes._ Because they're opcodes, CLTV and CSV can be used as part of more complex redemption conditions. Most often they're linked with the conditionals described in the next chapter.
### CLTV _They Lock Outputs._ Because they're opcodes that are included in transactions as part of a `sigPubKey`, they just lock that single output. That means that the transactions are accepted onto the Bitcoin network and that the UTXOs used to fund those transactions are spent. There's no going back on a transaction Timelocked with CLTV or CSV, as there is with a bare `nLockTime`. Respending the resultant UTXO then requires that the timelock conditions be met.
[like nLockTime, but for a single output] Here's one catch to use timelocks: _They Can't Relock Funds._ The Timelocks are designed in such a way that they unlock funds at a certain time. They cannot then relock a fund: once a timelocked fund is available to spend, it remains available to spend.
### CSV ### Understand the Possibilities of CLTV
[relative time] _OP_CHECKLOCKTIMEVERIFY_ or CLTV is a match for the classic `nLockTime` feature, but in the new opcode-based paradigm. It allows a UTXO to become accessible at a certain time or at a certain blockheight.
CLTV was first detailed in [BIP 65](https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki).
### Understand the Possibilities of CSV
_OP_CHECKSEQUENCEVERIFY_ or CSV depends on a new sort of "relative locktime", which is set in the transaction's _nSequence_ field. As usual, it can be set as either a time or a blockheight. If it's set as a time, "n", then a relative-timelocked transaction is spendable "n x 512" seconds after it was created, and if it's set as a block, "n", then a relative-timelocked transaction is spendable "n" blocks after it was created.
The use of `nSequence` for a relative timelock was first detailed in [BIP 68](https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki), then the CSV opcode was added in [BIP 112](https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki).
## Summary: Understanding Timelock Options ## Summary: Understanding Timelock Options
You now have four options for Timelock:
* `nLockTime` to keep a transaction off the blockchain until a specific time.
* `nSequence` to keep a transaction off the blockchain until a relative time.
* CLTV to make a UTXO unspendable until a specific time.
* CSV to make a UTXO unspendable until a relative time.