Skip to content

Commit 18e0718

Browse files
jnewberysipa
authored andcommitted
[consensus] Pin P2SH activation to block 173805 on mainnet
1 parent 526023a commit 18e0718

File tree

4 files changed

+28
-21
lines changed

4 files changed

+28
-21
lines changed

src/chainparams.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class CMainParams : public CChainParams {
7575
CMainParams() {
7676
strNetworkID = "main";
7777
consensus.nSubsidyHalvingInterval = 210000;
78+
consensus.BIP16Height = 173805; // 00000000000000ce80a7e057163a4db1d5ad7b20fb6f598c9597b9665c8fb0d4 - April 1, 2012
7879
consensus.BIP34Height = 227931;
7980
consensus.BIP34Hash = uint256S("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
8081
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
@@ -181,6 +182,7 @@ class CTestNetParams : public CChainParams {
181182
CTestNetParams() {
182183
strNetworkID = "test";
183184
consensus.nSubsidyHalvingInterval = 210000;
185+
consensus.BIP16Height = 514; // 00000000040b4e986385315e14bee30ad876d8b47f748025b26683116d21aa65
184186
consensus.BIP34Height = 21111;
185187
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
186188
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
@@ -270,6 +272,7 @@ class CRegTestParams : public CChainParams {
270272
CRegTestParams() {
271273
strNetworkID = "regtest";
272274
consensus.nSubsidyHalvingInterval = 150;
275+
consensus.BIP16Height = 0; // always enforce P2SH BIP16 on regtest
273276
consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
274277
consensus.BIP34Hash = uint256();
275278
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)

src/consensus/params.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ struct BIP9Deployment {
4343
struct Params {
4444
uint256 hashGenesisBlock;
4545
int nSubsidyHalvingInterval;
46+
/** Block height at which BIP16 becomes active */
47+
int BIP16Height;
4648
/** Block height and hash at which BIP34 becomes active */
4749
int BIP34Height;
4850
uint256 BIP34Hash;

src/test/miner_tests.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,23 +335,6 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
335335
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
336336
mempool.clear();
337337

338-
// invalid (pre-p2sh) txn in mempool, template creation fails
339-
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
340-
tx.vin[0].prevout.n = 0;
341-
tx.vin[0].scriptSig = CScript() << OP_1;
342-
tx.vout[0].nValue = BLOCKSUBSIDY-LOWFEE;
343-
script = CScript() << OP_0;
344-
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
345-
hash = tx.GetHash();
346-
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
347-
tx.vin[0].prevout.hash = hash;
348-
tx.vin[0].scriptSig = CScript() << std::vector<unsigned char>(script.begin(), script.end());
349-
tx.vout[0].nValue -= LOWFEE;
350-
hash = tx.GetHash();
351-
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
352-
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
353-
mempool.clear();
354-
355338
// double spend txn pair in mempool, template creation fails
356339
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
357340
tx.vin[0].scriptSig = CScript() << OP_1;
@@ -391,6 +374,24 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
391374
chainActive.SetTip(next);
392375
}
393376
BOOST_CHECK(pblocktemplate = AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey));
377+
378+
// invalid p2sh txn in mempool, template creation fails
379+
tx.vin[0].prevout.hash = txFirst[0]->GetHash();
380+
tx.vin[0].prevout.n = 0;
381+
tx.vin[0].scriptSig = CScript() << OP_1;
382+
tx.vout[0].nValue = BLOCKSUBSIDY-LOWFEE;
383+
script = CScript() << OP_0;
384+
tx.vout[0].scriptPubKey = GetScriptForDestination(CScriptID(script));
385+
hash = tx.GetHash();
386+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(true).FromTx(tx));
387+
tx.vin[0].prevout.hash = hash;
388+
tx.vin[0].scriptSig = CScript() << std::vector<unsigned char>(script.begin(), script.end());
389+
tx.vout[0].nValue -= LOWFEE;
390+
hash = tx.GetHash();
391+
mempool.addUnchecked(hash, entry.Fee(LOWFEE).Time(GetTime()).SpendsCoinbase(false).FromTx(tx));
392+
BOOST_CHECK_THROW(AssemblerForTest(chainparams).CreateNewBlock(scriptPubKey), std::runtime_error);
393+
mempool.clear();
394+
394395
// Delete the dummy blocks again.
395396
while (chainActive.Tip()->nHeight > nHeight) {
396397
CBlockIndex* del = chainActive.Tip();

src/validation.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,11 +1590,12 @@ static ThresholdConditionCache warningcache[VERSIONBITS_NUM_BITS];
15901590
static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consensus::Params& consensusparams) {
15911591
AssertLockHeld(cs_main);
15921592

1593-
// BIP16 didn't become active until Apr 1 2012
1594-
int64_t nBIP16SwitchTime = 1333238400;
1595-
bool fStrictPayToScriptHash = (pindex->GetBlockTime() >= nBIP16SwitchTime);
1593+
unsigned int flags = SCRIPT_VERIFY_NONE;
15961594

1597-
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;
1595+
// Start enforcing P2SH (BIP16)
1596+
if (pindex->nHeight >= consensusparams.BIP16Height) {
1597+
flags |= SCRIPT_VERIFY_P2SH;
1598+
}
15981599

15991600
// Start enforcing the DERSIG (BIP66) rule
16001601
if (pindex->nHeight >= consensusparams.BIP66Height) {

0 commit comments

Comments
 (0)