From 95749a58364611c997ba9295fb27489e0d7b1d42 Mon Sep 17 00:00:00 2001 From: Suhas Daftuar Date: Tue, 12 Sep 2017 12:40:29 -0400 Subject: [PATCH] Separate NULLDUMMY enforcement from SEGWIT enforcement This is in preparation for enforcing SCRIPT_VERIFY_WITNESS from the genesis block. --- src/validation.cpp | 9 +++++++++ src/validation.h | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/validation.cpp b/src/validation.cpp index ac585895e54..6bcc03c3051 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1760,6 +1760,9 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens // Start enforcing WITNESS rules using versionbits logic. if (IsWitnessEnabled(pindex->pprev, consensusparams)) { flags |= SCRIPT_VERIFY_WITNESS; + } + + if (IsNullDummyEnabled(pindex->pprev, consensusparams)) { flags |= SCRIPT_VERIFY_NULLDUMMY; } @@ -3106,6 +3109,12 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE); } +bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params) +{ + LOCK(cs_main); + return (VersionBitsState(pindexPrev, params, Consensus::DEPLOYMENT_SEGWIT, versionbitscache) == ThresholdState::ACTIVE); +} + // Compute at which vout of the block's coinbase transaction the witness // commitment occurs, or -1 if not found. static int GetWitnessCommitmentIndex(const CBlock& block) diff --git a/src/validation.h b/src/validation.h index 36684846961..b415a85053e 100644 --- a/src/validation.h +++ b/src/validation.h @@ -411,6 +411,9 @@ bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, /** Check whether witness commitments are required for block. */ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params); +/** Check whether NULLDUMMY (BIP 147) has activated. */ +bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params); + /** When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index */ bool RewindBlockIndex(const CChainParams& params);