@@ -1725,6 +1725,15 @@ class WarningBitsConditionChecker : public AbstractThresholdConditionChecker
1725
1725
// Protected by cs_main
1726
1726
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS];
1727
1727
1728
+ // 0.13.0 was shipped with a segwit deployment defined for testnet, but not for
1729
+ // mainnet. We no longer need to support disabling the segwit deployment
1730
+ // except for testing purposes, due to limitations of the functional test
1731
+ // environment. See test/functional/p2p-segwit.py.
1732
+ static bool IsScriptWitnessEnabled (const Consensus::Params& params)
1733
+ {
1734
+ return params.vDeployments [Consensus::DEPLOYMENT_SEGWIT].nTimeout != 0 ;
1735
+ }
1736
+
1728
1737
static unsigned int GetBlockScriptFlags (const CBlockIndex* pindex, const Consensus::Params& consensusparams) {
1729
1738
AssertLockHeld (cs_main);
1730
1739
@@ -1742,6 +1751,12 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
1742
1751
flags |= SCRIPT_VERIFY_P2SH;
1743
1752
}
1744
1753
1754
+ // Enforce WITNESS rules whenever P2SH is in effect (and the segwit
1755
+ // deployment is defined).
1756
+ if (flags & SCRIPT_VERIFY_P2SH && IsScriptWitnessEnabled (consensusparams)) {
1757
+ flags |= SCRIPT_VERIFY_WITNESS;
1758
+ }
1759
+
1745
1760
// Start enforcing the DERSIG (BIP66) rule
1746
1761
if (pindex->nHeight >= consensusparams.BIP66Height ) {
1747
1762
flags |= SCRIPT_VERIFY_DERSIG;
@@ -1757,11 +1772,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
1757
1772
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
1758
1773
}
1759
1774
1760
- // Start enforcing WITNESS rules using versionbits logic.
1761
- if (IsWitnessEnabled (pindex->pprev , consensusparams)) {
1762
- flags |= SCRIPT_VERIFY_WITNESS;
1763
- }
1764
-
1765
1775
if (IsNullDummyEnabled (pindex->pprev , consensusparams)) {
1766
1776
flags |= SCRIPT_VERIFY_NULLDUMMY;
1767
1777
}
@@ -4107,6 +4117,9 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
4107
4117
4108
4118
int nHeight = 1 ;
4109
4119
while (nHeight <= chainActive.Height ()) {
4120
+ // Although SCRIPT_VERIFY_WITNESS is now generally enforced on all
4121
+ // blocks in ConnectBlock, we don't need to go back and
4122
+ // re-download/re-verify blocks from before segwit actually activated.
4110
4123
if (IsWitnessEnabled (chainActive[nHeight - 1 ], params.GetConsensus ()) && !(chainActive[nHeight]->nStatus & BLOCK_OPT_WITNESS)) {
4111
4124
break ;
4112
4125
}
0 commit comments