Skip to content

Commit ce65018

Browse files
committed
Use P2SH consensus rules for all blocks
This commit moves P2SH activation back to the genesis block, with a hardcoded exception for the one historical block in the chain that violated this rule.
1 parent 94deb09 commit ce65018

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

src/chainparams.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CMainParams : public CChainParams {
7575
CMainParams() {
7676
strNetworkID = "main";
7777
consensus.nSubsidyHalvingInterval = 210000;
78-
consensus.BIP16Height = 173805; // 00000000000000ce80a7e057163a4db1d5ad7b20fb6f598c9597b9665c8fb0d4 - April 1, 2012
78+
consensus.BIP16Exception = uint256S("0x00000000000002dc756eebf4f49723ed8d30cc28a5f108eb94b1ba88ac4f9c22");
7979
consensus.BIP34Height = 227931;
8080
consensus.BIP34Hash = uint256S("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
8181
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
@@ -190,7 +190,7 @@ class CTestNetParams : public CChainParams {
190190
CTestNetParams() {
191191
strNetworkID = "test";
192192
consensus.nSubsidyHalvingInterval = 210000;
193-
consensus.BIP16Height = 514; // 00000000040b4e986385315e14bee30ad876d8b47f748025b26683116d21aa65
193+
consensus.BIP16Exception = uint256S("0x00000000dd30457c001f4095d208cc1296b0eed002427aa599874af7a432b105");
194194
consensus.BIP34Height = 21111;
195195
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
196196
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
@@ -283,7 +283,7 @@ class CRegTestParams : public CChainParams {
283283
CRegTestParams() {
284284
strNetworkID = "regtest";
285285
consensus.nSubsidyHalvingInterval = 150;
286-
consensus.BIP16Height = 0; // always enforce P2SH BIP16 on regtest
286+
consensus.BIP16Exception = uint256();
287287
consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
288288
consensus.BIP34Hash = uint256();
289289
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)

src/consensus/params.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ struct BIP9Deployment {
4949
struct Params {
5050
uint256 hashGenesisBlock;
5151
int nSubsidyHalvingInterval;
52-
/** Block height at which BIP16 becomes active */
53-
int BIP16Height;
52+
/* Block hash that is excepted from BIP16 enforcement */
53+
uint256 BIP16Exception;
5454
/** Block height and hash at which BIP34 becomes active */
5555
int BIP34Height;
5656
uint256 BIP34Hash;

src/validation.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,8 +1730,15 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
17301730

17311731
unsigned int flags = SCRIPT_VERIFY_NONE;
17321732

1733-
// Start enforcing P2SH (BIP16)
1734-
if (pindex->nHeight >= consensusparams.BIP16Height) {
1733+
// BIP16 didn't become active until Apr 1 2012 (on mainnet, and
1734+
// retroactively applied to testnet)
1735+
// However, only one historical block violated the P2SH rules (on both
1736+
// mainnet and testnet), so for simplicity, always leave P2SH
1737+
// on except for the one violating block.
1738+
if (consensusparams.BIP16Exception.IsNull() || // no bip16 exception on this chain
1739+
pindex->phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
1740+
*pindex->phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
1741+
{
17351742
flags |= SCRIPT_VERIFY_P2SH;
17361743
}
17371744

0 commit comments

Comments
 (0)