Skip to content

Commit ccb8ca4

Browse files
committed
Always enforce SCRIPT_VERIFY_WITNESS with P2SH
1 parent 5c31b20 commit ccb8ca4

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/validation.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,15 @@ class WarningBitsConditionChecker : public AbstractThresholdConditionChecker
17251725
// Protected by cs_main
17261726
static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS];
17271727

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+
17281737
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams) {
17291738
AssertLockHeld(cs_main);
17301739

@@ -1742,6 +1751,12 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
17421751
flags |= SCRIPT_VERIFY_P2SH;
17431752
}
17441753

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+
17451760
// Start enforcing the DERSIG (BIP66) rule
17461761
if (pindex->nHeight >= consensusparams.BIP66Height) {
17471762
flags |= SCRIPT_VERIFY_DERSIG;
@@ -1757,11 +1772,6 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
17571772
flags |= SCRIPT_VERIFY_CHECKSEQUENCEVERIFY;
17581773
}
17591774

1760-
// Start enforcing WITNESS rules using versionbits logic.
1761-
if (IsWitnessEnabled(pindex->pprev, consensusparams)) {
1762-
flags |= SCRIPT_VERIFY_WITNESS;
1763-
}
1764-
17651775
if (IsNullDummyEnabled(pindex->pprev, consensusparams)) {
17661776
flags |= SCRIPT_VERIFY_NULLDUMMY;
17671777
}
@@ -4107,6 +4117,9 @@ bool CChainState::RewindBlockIndex(const CChainParams& params)
41074117

41084118
int nHeight = 1;
41094119
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.
41104123
if (IsWitnessEnabled(chainActive[nHeight - 1], params.GetConsensus()) && !(chainActive[nHeight]->nStatus & BLOCK_OPT_WITNESS)) {
41114124
break;
41124125
}

0 commit comments

Comments
 (0)