Skip to content

Commit f9e37f3

Browse files
committed
doc: IsFinalTx comment about nSequence & OP_CLTV
It's somewhat surprising that a transaction's nLockTime field is ignored when all nSequence fields are final, so this change aims to clarify this behavior and cross reference relevant details of OP_CHECKLOCKTIMEVERIFY.
1 parent c6d6bc8 commit f9e37f3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/consensus/tx_verify.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
2020
return true;
2121
if ((int64_t)tx.nLockTime < ((int64_t)tx.nLockTime < LOCKTIME_THRESHOLD ? (int64_t)nBlockHeight : nBlockTime))
2222
return true;
23+
24+
// Even if tx.nLockTime isn't satisfied by nBlockHeight/nBlockTime, a
25+
// transaction is still considered final if all inputs' nSequence ==
26+
// SEQUENCE_FINAL (0xffffffff), in which case nLockTime is ignored.
27+
//
28+
// Because of this behavior OP_CHECKLOCKTIMEVERIFY/CheckLockTime() will
29+
// also check that the spending input's nSequence != SEQUENCE_FINAL,
30+
// ensuring that an unsatisfied nLockTime value will actually cause
31+
// IsFinalTx() to return false here:
2332
for (const auto& txin : tx.vin) {
2433
if (!(txin.nSequence == CTxIn::SEQUENCE_FINAL))
2534
return false;

src/script/interpreter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1741,9 +1741,9 @@ bool GenericTransactionSignatureChecker<T>::CheckLockTime(const CScriptNum& nLoc
17411741
if (nLockTime > (int64_t)txTo->nLockTime)
17421742
return false;
17431743

1744-
// Finally the nLockTime feature can be disabled and thus
1745-
// CHECKLOCKTIMEVERIFY bypassed if every txin has been
1746-
// finalized by setting nSequence to maxint. The
1744+
// Finally the nLockTime feature can be disabled in IsFinalTx()
1745+
// and thus CHECKLOCKTIMEVERIFY bypassed if every txin has
1746+
// been finalized by setting nSequence to maxint. The
17471747
// transaction would be allowed into the blockchain, making
17481748
// the opcode ineffective.
17491749
//

0 commit comments

Comments
 (0)