Difference between revisions of "NLockTime"

From Bitcoin Wiki
Jump to: navigation, search
(Specified that nLockTime is part of an input to a transaction.)
m (See Also: Add link to transaction page)
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
{{stub}}
 
{{stub}}
  
nLockTime is a parameter that can be attached to an input to a transaction, that mandates a minimal time (specified in either unix time or block height), that before this time, the transaction cannot be accepted into a block.
+
'''nLockTime''' is a parameter of a transaction, that, if any input indicates so (by having nSequence not equal to UINT_MAX), mandates a minimal time (specified in either unix time or block height), before which the transaction cannot be accepted into a block.  If all inputs in a transaction have nSequence equal to UINT_MAX, then nLockTime is ignored.
  
See lock_time in [[Protocol_specification#tx|the protocol specification]]
+
* If <code>nLockTime < 500000000</code>
 +
** Specifies the block number after which this transaction can be included in a block.
 +
* Otherwise
 +
** Specifies the UNIX timestamp after which this transaction can be included in a block.
 +
 
 +
Note that since the adoption of BIP 113, the time-based nLockTime is compared to the 11-block [[median time past]] (the median timestamp of the 11 blocks preceding the block in which the transaction is mined), and not the block time itself. The median time past tends to lag the current unix time by about one hour (give or take), but unlike block time it increases monotonically.
 +
 
 +
For transaction relay, nLockTime must be <= the current block's height (block-based) or <= the current median time past (if time based). This ensures that the transaction can be included in the next block.
 +
 
 +
==See Also==
 +
* lock_time in [[Protocol_specification#tx|the protocol specification]]
 +
* [[Transaction]]
 +
* [[Timelock]]
 +
* [https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki BIP113]
 +
* The CHECKLOCKTIMEVERIFY opcode in [https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki BIP65]
  
 
[[Category:Technical]]
 
[[Category:Technical]]
 +
{{lowercase}}

Revision as of 12:25, 10 June 2021

Hashbtc.jpgThis page is a stub. Help by expanding it.

nLockTime is a parameter of a transaction, that, if any input indicates so (by having nSequence not equal to UINT_MAX), mandates a minimal time (specified in either unix time or block height), before which the transaction cannot be accepted into a block. If all inputs in a transaction have nSequence equal to UINT_MAX, then nLockTime is ignored.

  • If nLockTime < 500000000
    • Specifies the block number after which this transaction can be included in a block.
  • Otherwise
    • Specifies the UNIX timestamp after which this transaction can be included in a block.

Note that since the adoption of BIP 113, the time-based nLockTime is compared to the 11-block median time past (the median timestamp of the 11 blocks preceding the block in which the transaction is mined), and not the block time itself. The median time past tends to lag the current unix time by about one hour (give or take), but unlike block time it increases monotonically.

For transaction relay, nLockTime must be <= the current block's height (block-based) or <= the current median time past (if time based). This ensures that the transaction can be included in the next block.

See Also