Bitcoin Locktime and Sequence Validation: Debugging Non-Final Transactions
A Bitcoin transaction may have valid signatures and sufficient inputs yet still be rejected as non-final. Debugging that result requires checking several independent layers: absolute nLockTime, per-input sequence fields, relative locks under BIP68, Script conditions such as CLTV and CSV, and the difference between consensus validity and mempool policy.
Step 1: Read the transaction fields
Decode the transaction version, nLockTime, and each input's nSequence. If all inputs use 0xffffffff, the absolute locktime does not restrict finality. Otherwise determine whether nLockTime encodes a height (below 500,000,000) or Unix time (at least that threshold). Do not compare a height-based lock to a wall-clock timestamp.
For version 2 or later transactions, inspect whether each sequence has the BIP68 disable flag set. When the flag is clear, decode the type bit and low 16-bit value. The type bit distinguishes block intervals from 512-second intervals. Do not infer a delay by reading the whole 32-bit number as a plain integer.
Step 2: Evaluate against chain state
A transaction can be non-final at one tip and valid after more blocks have been mined. For absolute time locks, use the previous block's median-time-past. For relative sequence locks, use the confirmation height and relevant MTP context of the outputs being spent. Inputs spending unconfirmed outputs require special attention to mempool sequence-lock handling.
A transaction that is not currently eligible should not be described as permanently invalid. But a transaction with malformed Script, incorrect signatures, or missing inputs has a different problem; waiting for time to pass will not repair it.
Step 3: Inspect Script commitments
OP_CHECKLOCKTIMEVERIFY and OP_CHECKSEQUENCEVERIFY may impose constraints in the spending Script. These are not merely wallet metadata. An input that satisfies transaction-level finality can still fail Script evaluation if it does not satisfy the spending condition. Conversely, setting nLockTime or nSequence in a transaction does not by itself create a permanent covenant on a UTXO.
Step 4: Separate consensus from relay policy
A node's mempool may decline a transaction for reasons unrelated to locktime: fee policy, ancestor limits, conflicts, or nonstandard forms. A consensus-valid transaction is not guaranteed immediate relay or mining. Inspect the exact rejection reason and avoid treating a mempool response as a universal prediction about all future blocks.
Step 5: Test boundary cases
Test one block before eligibility, the boundary itself, and one block after; test time-mode sequence locks around 512-second units; test version 1 versus version 2; and test mixed inputs with different constraints. Use regtest when possible so blocks and MTP can be advanced deliberately. Such tests are more reliable than relying on real-world elapsed time alone.
Primary references
Bitcoin developer reference — Transactions: https://developer.bitcoin.org/reference/transactions.html
BIP68 — Relative lock-time: https://github.com/bitcoin/bips/blob/master/bip-0068.mediawiki
BIP112 — CHECKSEQUENCEVERIFY: https://github.com/bitcoin/bips/blob/master/bip-0112.mediawiki
BIP113 — Median time-past: https://github.com/bitcoin/bips/blob/master/bip-0113.mediawiki
