<p>It's checked in the IsFinal() method of CTransaction. A non-final transaction cannot be included in blocks.</p>

<p>A transaction is final if <em>either</em>:</p>

<ul>
<li>The lock time is in the past.</li>
<li>All of the inputs have sequence numbers equal to UINT_MAX.</li>
</ul>

<p>The second one is probably what confused you.</p>

CC BY-SA 3.0
2012-12-26T22:07:01.367Z
Thank you! I hadn't checked that. Still, I have just sent a transaction with both sequence number smaller than UINT_MAX and a locktime greater than 0 and spent it right away. I will revise IsFinal() to check what is wrong...
halftimepad
CC BY-SA 3.0
2013-01-06T23:35:03.627Z
Done. I was using a wrong locktime. It must be an absolute time with UNIX timestamp format.
halftimepad
CC BY-SA 3.0
2012-12-24T21:01:44.510Z
2012-12-24T21:01:44.510Z
theymos
<p>I am trying to study the locktime feature of transactions ( <a href="https://en.bitcoin.it/wiki/Protocol_specification#tx">https://en.bitcoin.it/wiki/Protocol_specification#tx</a> ). I have created some raw transactions in the testnet with different locktimes, but, when I send them, they are confirmed as usual. I have also been able to spend the just sent coins immediately. When I dump the block, the locktime field looks correct. </p>

<p>How is the locktime checked when confirming a transaction? Can someone point me to the piece of the code that does the checking? </p>

<p>Or am I wrong and locktime is really not implemented? </p>

<protocol><bitcoind><bitcoin-core><timestamp><locktime>
How is locktime enforced in the standard client?
halftimepad
# How is locktime enforced in the standard client?

(Asked by: username_0 on 2012-12-24)

I am trying to study the locktime feature of transactions ( <https://en.bitcoin.it/wiki/Protocol_specification#tx> ). I have created some raw transactions in the testnet with different locktimes, but, when I send them, they are confirmed as usual. I have also been able to spend the just sent coins immediately. When I dump the block, the locktime field looks correct.

How is the locktime checked when confirming a transaction? Can someone point me to the piece of the code that does the checking?

Or am I wrong and locktime is really not implemented?

**Tags:** protocol, bitcoind, bitcoin-core, timestamp, locktime


---

## 1 answers

### Answer by username_1 on 2012-12-24. Score: 6 | Accepted answer

It's checked in the IsFinal() method of CTransaction. A non-final transaction cannot be included in blocks.

A transaction is final if *either*:

* The lock time is in the past.
* All of the inputs have sequence numbers equal to UINT\_MAX.

The second one is probably what confused you.

> **Comments:**
> **username_0**: Thank you! I hadn't checked that. Still, I have just sent a transaction with both sequence number smaller than UINT_MAX and a locktime greater than 0 and spent it right away. I will revise IsFinal() to check what is wrong...  
> **username_0**: Done. I was using a wrong locktime. It must be an absolute time with UNIX timestamp format.  

---

