Skip to content

Commit e1a13f1

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#18096: doc: IsFinalTx comment about nSequence & OP_CLTV
f9e37f3 doc: IsFinalTx comment about nSequence & OP_CLTV (Yuval Kogman) Pull request description: 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`. ACKs for top commit: MarcoFalke: ACK f9e37f3 Tree-SHA512: 88460dacbe4b8115fb1948715f09b21d4f34ba1da9e88d52f0b774a969f845e9eddc5940e7fee66eacdd3062dc40d6d44c3f282b0e5144411fd47eb2320b44f5
2 parents bfd910c + f9e37f3 commit e1a13f1

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
@@ -1740,9 +1740,9 @@ bool GenericTransactionSignatureChecker<T>::CheckLockTime(const CScriptNum& nLoc
17401740
if (nLockTime > (int64_t)txTo->nLockTime)
17411741
return false;
17421742

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

0 commit comments

Comments
 (0)