Skip to content

Commit

Permalink
Add CHECKLOCKTIMEVERIFY (BIP65) soft-fork logic
Browse files Browse the repository at this point in the history
Based on the earlier BIP66 soft-fork logic implemented by Pieter
Wuille's 5a47811

Rebased-From: 287f54f
  • Loading branch information
petertodd committed Oct 8, 2015
1 parent 0e01d0f commit 4137248
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
14 changes: 13 additions & 1 deletion src/main.cpp
Expand Up @@ -1698,11 +1698,18 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin

unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;

// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks, when 75% of the network has upgraded:
// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks,
// when 75% of the network has upgraded:
if (block.nVersion >= 3 && CBlockIndex::IsSuperMajority(3, pindex->pprev, Params().EnforceBlockUpgradeMajority())) {
flags |= SCRIPT_VERIFY_DERSIG;
}

// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
// blocks, when 75% of the network has upgraded:
if (block.nVersion >= 4 && CBlockIndex::IsSuperMajority(4, pindex->pprev, Params().EnforceBlockUpgradeMajority())) {
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
}

CBlockUndo blockundo;

CCheckQueueControl<CScriptCheck> control(fScriptChecks && nScriptCheckThreads ? &scriptcheckqueue : NULL);
Expand Down Expand Up @@ -2555,6 +2562,11 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
REJECT_OBSOLETE, "bad-version");
}

// Reject block.nVersion=3 blocks when 95% (75% on testnet) of the network has upgraded:
if (block.nVersion < 4 && CBlockIndex::IsSuperMajority(4, pindexPrev, Params().RejectBlockOutdatedMajority()))
return state.Invalid(error("%s : rejected nVersion=3 block", __func__),
REJECT_OBSOLETE, "bad-version");

return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/primitives/block.h
Expand Up @@ -24,7 +24,7 @@ class CBlockHeader
{
public:
// header
static const int32_t CURRENT_VERSION=3;
static const int32_t CURRENT_VERSION=4;
int32_t nVersion;
uint256 hashPrevBlock;
uint256 hashMerkleRoot;
Expand Down
7 changes: 4 additions & 3 deletions src/script/bitcoinconsensus.h
Expand Up @@ -44,9 +44,10 @@ typedef enum bitcoinconsensus_error_t
/** Script verification flags */
enum
{
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE = 0,
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG = (1U << 2), // enforce strict DER (BIP66) compliance
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_NONE = 0,
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_P2SH = (1U << 0), // evaluate P2SH (BIP16) subscripts
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_DERSIG = (1U << 2), // enforce strict DER (BIP66) compliance
bitcoinconsensus_SCRIPT_FLAGS_VERIFY_CHECKLOCKTIMEVERIFY = (1U << 9), // enable CHECKLOCKTIMEVERIFY (BIP65)
};

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

0 comments on commit 4137248

Please sign in to comment.