diff options
author | Suhas Daftuar <sdaftuar@chaincode.com> | 2017-09-13 10:13:57 -0400 |
---|---|---|
committer | Suhas Daftuar <sdaftuar@gmail.com> | 2018-04-13 10:35:27 -0400 |
commit | ccb8ca42a42a3e1bf6c85410aa4050aa61e5bf81 (patch) | |
tree | 8987480daf2a634643c7bdf71ec579a63a7a7aea /src/validation.cpp | |
parent | 5c31b20a35053e75fdf6b86213860088a4e6f3a0 (diff) |
Always enforce SCRIPT_VERIFY_WITNESS with P2SH
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 6bcc03c305..c0bfc56403 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1725,6 +1725,15 @@ public: // Protected by cs_main static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS]; +// 0.13.0 was shipped with a segwit deployment defined for testnet, but not for +// mainnet. We no longer need to support disabling the segwit deployment +// except for testing purposes, due to limitations of the functional test +// environment. See test/functional/p2p-segwit.py. +static bool IsScriptWitnessEnabled(const Consensus::Params& params) +{ + return params.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0; +} + static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams) { AssertLockHeld(cs_main); @@ -1742,6 +1751,12 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens flags |= SCRIPT_VERIFY_P2SH; } + // Enforce WITNESS rules whenever P2SH is in effect (and the segwit + // deployment is defined). + if (flags & SCRIPT_VERIFY_P2SH && IsScriptWitnessEnabled(consensusparams)) { + flags |= SCRIPT_VERIFY_WITNESS; + } + // Start enforcing the DERSIG (BIP66) rule if (pindex->nHeight >= consensusparams.BIP66Height) { flags |= SCRIPT_VERIFY_DERSIG; @@ -1757,11 +1772,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY; } - // 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; } @@ -4107,6 +4117,9 @@ bool CChainState::RewindBlockIndex(const CChainParams& params) int nHeight = 1; while (nHeight <= chainActive.Height()) { + // Although SCRIPT_VERIFY_WITNESS is now generally enforced on all + // blocks in ConnectBlock, we don't need to go back and + // re-download/re-verify blocks from before segwit actually activated. if (IsWitnessEnabled(chainActive[nHeight - 1], params.GetConsensus()) && !(chainActive[nHeight]->nStatus & BLOCK_OPT_WITNESS)) { break; } |