Skip to content

Commit 287f54f

Browse files
committed
Add CHECKLOCKTIMEVERIFY (BIP65) soft-fork logic
Based on the earlier BIP66 soft-fork logic implemented by Pieter Wuille's 5a47811
1 parent d479311 commit 287f54f

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/main.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,11 +1740,18 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
17401740

17411741
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;
17421742

1743-
// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks, when 75% of the network has upgraded:
1743+
// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks,
1744+
// when 75% of the network has upgraded:
17441745
if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) {
17451746
flags |= SCRIPT_VERIFY_DERSIG;
17461747
}
17471748

1749+
// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
1750+
// blocks, when 75% of the network has upgraded:
1751+
if (block.nVersion >= 4 && IsSuperMajority(4, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) {
1752+
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
1753+
}
1754+
17481755
CBlockUndo blockundo;
17491756

17501757
CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL);
@@ -2684,6 +2691,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
26842691
return state.Invalid(error("%s : rejected nVersion=2 block", __func__),
26852692
REJECT_OBSOLETE, "bad-version");
26862693

2694+
// Reject block.nVersion=3 blocks when 95% (75% on testnet) of the network has upgraded:
2695+
if (block.nVersion < 4 && IsSuperMajority(4, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams))
2696+
return state.Invalid(error("%s : rejected nVersion=3 block", __func__),
2697+
REJECT_OBSOLETE, "bad-version");
2698+
26872699
return true;
26882700
}
26892701

src/primitives/block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CBlockHeader
2121
{
2222
public:
2323
// header
24-
static const int32_t CURRENT_VERSION=3;
24+
static const int32_t CURRENT_VERSION=4;
2525
int32_t nVersion;
2626
uint256 hashPrevBlock;
2727
uint256 hashMerkleRoot;

src/script/bitcoinconsensus.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ typedef enum bitcoinconsensus_error_t
4444
/** Script verification flags */
4545
enum
4646
{
47-
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE = 0,
48-
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts
49-
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG = (1U << 2), // enforce strict DER (BIP66) compliance
47+
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE = 0,
48+
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts
49+
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG = (1U << 2), // enforce strict DER (BIP66) compliance
50+
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
5051
};
5152

5253
/// Returns 1 if the input nIn of the serialized transaction pointed to by

0 commit comments

Comments
 (0)