NLockTime: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Belcher (talk | contribs)
Add link to timelock page
Darosior (talk | contribs)
Add more details about the lock time interpretation.
(2 intermediate revisions by the same user not shown)
Line 2: Line 2:


'''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.
'''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.
Since [https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki BIP68], the lock time can either be absolute or relative. Given a transaction,
* If the most significant bit (<code>1<<31</code>) of the '''nLockTime''' field is set (if the lock time is absolute)
** If <code>nLockTime < 500000000</code>
*** Specifies the block number at which this transaction can be spent
** Otherwise
*** Specifies the UNIX timestamp at which this transaction can be spent
* Otherwise (if the lock time is relative)
** If the 23rd bit (<code>1<<22</code>) is not set
*** The last 16 bits of the '''nLockTime''' field specify a relative time in units of 512 seconds. The transaction can only be included in a block if <code>spending_tx_block_time > spent_tx_block_time + nLockTime * 512</code>.
** Otherwise
*** The last 16 bits of the '''nLockTime''' field specify a relative block height before which the transaction can not be included in a block. In other words it can be included if <code>spending_tx_block_height > spent_tx_block_height + nLockTime</code>


==See Also==
==See Also==
* lock_time in [[Protocol_specification#tx|the protocol specification]]
* lock_time in [[Protocol_specification#tx|the protocol specification]]
* [[Timelock]]
* [[Timelock]]
* [https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki BIP68]
* The CHECKLOCKTIMEVERIFY opcode in [https://github.com/bitcoin/bips/blob/master/bip-0065.mediawiki BIP65]
* The CHECKSEQUENCEVERIFY opcode in [https://github.com/bitcoin/bips/blob/master/bip-00112.mediawiki BIP112]


[[Category:Technical]]
[[Category:Technical]]
{{lowercase}}
{{lowercase}}

Revision as of 13:00, 23 September 2019

This 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.

Since BIP68, the lock time can either be absolute or relative. Given a transaction,

  • If the most significant bit (1<<31) of the nLockTime field is set (if the lock time is absolute)
    • If nLockTime < 500000000
      • Specifies the block number at which this transaction can be spent
    • Otherwise
      • Specifies the UNIX timestamp at which this transaction can be spent
  • Otherwise (if the lock time is relative)
    • If the 23rd bit (1<<22) is not set
      • The last 16 bits of the nLockTime field specify a relative time in units of 512 seconds. The transaction can only be included in a block if spending_tx_block_time > spent_tx_block_time + nLockTime * 512.
    • Otherwise
      • The last 16 bits of the nLockTime field specify a relative block height before which the transaction can not be included in a block. In other words it can be included if spending_tx_block_height > spent_tx_block_height + nLockTime

See Also