Skip to content

Commit 37d83bb

Browse files
committed
Merge #8391: Consensus: Remove ISM
122786d Consensus: Remove ISM (NicolasDorier)
2 parents 5c7a5e1 + 122786d commit 37d83bb

File tree

7 files changed

+83
-107
lines changed

7 files changed

+83
-107
lines changed

qa/rpc-tests/bip65-cltv-p2p.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ def get_tests(self):
7171
self.nodeaddress = self.nodes[0].getnewaddress()
7272
self.last_block_time = int(time.time())
7373

74-
''' 98 more version 3 blocks '''
74+
''' 398 more version 3 blocks '''
7575
test_blocks = []
76-
for i in range(98):
76+
for i in range(398):
7777
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
7878
block.nVersion = 3
7979
block.rehash()
@@ -118,24 +118,6 @@ def get_tests(self):
118118
height += 1
119119
yield TestInstance([[block, True]])
120120

121-
'''
122-
Check that the new CLTV rules are enforced in the 751st version 4
123-
block.
124-
'''
125-
spendtx = self.create_transaction(self.nodes[0],
126-
self.coinbase_blocks[1], self.nodeaddress, 1.0)
127-
cltv_invalidate(spendtx)
128-
spendtx.rehash()
129-
130-
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
131-
block.nVersion = 4
132-
block.vtx.append(spendtx)
133-
block.hashMerkleRoot = block.calc_merkle_root()
134-
block.rehash()
135-
block.solve()
136-
self.last_block_time += 1
137-
yield TestInstance([[block, False]])
138-
139121
''' Mine 199 new version blocks on last valid tip '''
140122
test_blocks = []
141123
for i in range(199):
@@ -169,6 +151,24 @@ def get_tests(self):
169151
height += 1
170152
yield TestInstance([[block, True]])
171153

154+
'''
155+
Check that the new CLTV rules are enforced in the 951st version 4
156+
block.
157+
'''
158+
spendtx = self.create_transaction(self.nodes[0],
159+
self.coinbase_blocks[1], self.nodeaddress, 1.0)
160+
cltv_invalidate(spendtx)
161+
spendtx.rehash()
162+
163+
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
164+
block.nVersion = 4
165+
block.vtx.append(spendtx)
166+
block.hashMerkleRoot = block.calc_merkle_root()
167+
block.rehash()
168+
block.solve()
169+
self.last_block_time += 1
170+
yield TestInstance([[block, False]])
171+
172172
''' Mine 1 old version block, should be invalid '''
173173
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
174174
block.nVersion = 3

qa/rpc-tests/bip65-cltv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def run_test(self):
3030
cnt = self.nodes[0].getblockcount()
3131

3232
# Mine some old-version blocks
33-
self.nodes[1].generate(100)
33+
self.nodes[1].generate(200)
34+
cnt += 100
3435
self.sync_all()
3536
if (self.nodes[0].getblockcount() != cnt + 100):
3637
raise AssertionError("Failed to mine 100 version=3 blocks")

qa/rpc-tests/bipdersig-p2p.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def get_tests(self):
7979
self.nodeaddress = self.nodes[0].getnewaddress()
8080
self.last_block_time = int(time.time())
8181

82-
''' 98 more version 2 blocks '''
82+
''' 298 more version 2 blocks '''
8383
test_blocks = []
84-
for i in range(98):
84+
for i in range(298):
8585
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
8686
block.nVersion = 2
8787
block.rehash()
@@ -124,25 +124,7 @@ def get_tests(self):
124124
self.last_block_time += 1
125125
self.tip = block.sha256
126126
height += 1
127-
yield TestInstance([[block, True]])
128-
129-
'''
130-
Check that the new DERSIG rules are enforced in the 751st version 3
131-
block.
132-
'''
133-
spendtx = self.create_transaction(self.nodes[0],
134-
self.coinbase_blocks[1], self.nodeaddress, 1.0)
135-
unDERify(spendtx)
136-
spendtx.rehash()
137-
138-
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
139-
block.nVersion = 3
140-
block.vtx.append(spendtx)
141-
block.hashMerkleRoot = block.calc_merkle_root()
142-
block.rehash()
143-
block.solve()
144-
self.last_block_time += 1
145-
yield TestInstance([[block, False]])
127+
yield TestInstance([[block, True]])
146128

147129
''' Mine 199 new version blocks on last valid tip '''
148130
test_blocks = []
@@ -177,6 +159,24 @@ def get_tests(self):
177159
height += 1
178160
yield TestInstance([[block, True]])
179161

162+
'''
163+
Check that the new DERSIG rules are enforced in the 951st version 3
164+
block.
165+
'''
166+
spendtx = self.create_transaction(self.nodes[0],
167+
self.coinbase_blocks[1], self.nodeaddress, 1.0)
168+
unDERify(spendtx)
169+
spendtx.rehash()
170+
171+
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
172+
block.nVersion = 3
173+
block.vtx.append(spendtx)
174+
block.hashMerkleRoot = block.calc_merkle_root()
175+
block.rehash()
176+
block.solve()
177+
self.last_block_time += 1
178+
yield TestInstance([[block, False]])
179+
180180
''' Mine 1 old version block, should be invalid '''
181181
block = create_block(self.tip, create_coinbase(height), self.last_block_time + 1)
182182
block.nVersion = 2

src/chainparams.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ class CMainParams : public CChainParams {
7171
CMainParams() {
7272
strNetworkID = "main";
7373
consensus.nSubsidyHalvingInterval = 210000;
74-
consensus.nMajorityEnforceBlockUpgrade = 750;
75-
consensus.nMajorityRejectBlockOutdated = 950;
76-
consensus.nMajorityWindow = 1000;
7774
consensus.BIP34Height = 227931;
7875
consensus.BIP34Hash = uint256S("0x000000000000024b89b42a942fe0d9fea3bb44ab7bd1b19115dd6a759c0808b8");
76+
consensus.BIP65Height = 388381; // 000000000000000004c2b624ed5d7756c508d90fd0da2c7c679febfa6c4735f0
77+
consensus.BIP66Height = 363725; // 00000000000000000379eaa19dce8c9b722d46ae6a57c2f1a988119488b50931
7978
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
8079
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
8180
consensus.nPowTargetSpacing = 10 * 60;
@@ -167,11 +166,10 @@ class CTestNetParams : public CChainParams {
167166
CTestNetParams() {
168167
strNetworkID = "test";
169168
consensus.nSubsidyHalvingInterval = 210000;
170-
consensus.nMajorityEnforceBlockUpgrade = 51;
171-
consensus.nMajorityRejectBlockOutdated = 75;
172-
consensus.nMajorityWindow = 100;
173169
consensus.BIP34Height = 21111;
174170
consensus.BIP34Hash = uint256S("0x0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8");
171+
consensus.BIP65Height = 581885; // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6
172+
consensus.BIP66Height = 330776; // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182
175173
consensus.powLimit = uint256S("00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
176174
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
177175
consensus.nPowTargetSpacing = 10 * 60;
@@ -247,11 +245,10 @@ class CRegTestParams : public CChainParams {
247245
CRegTestParams() {
248246
strNetworkID = "regtest";
249247
consensus.nSubsidyHalvingInterval = 150;
250-
consensus.nMajorityEnforceBlockUpgrade = 750;
251-
consensus.nMajorityRejectBlockOutdated = 950;
252-
consensus.nMajorityWindow = 1000;
253-
consensus.BIP34Height = -1; // BIP34 has not necessarily activated on regtest
248+
consensus.BIP34Height = 100000000; // BIP34 has not activated on regtest (far in the future so block v1 are not rejected in tests)
254249
consensus.BIP34Hash = uint256();
250+
consensus.BIP65Height = 1351; // BIP65 activated on regtest (Used in rpc activation tests)
251+
consensus.BIP66Height = 1251; // BIP66 activated on regtest (Used in rpc activation tests)
255252
consensus.powLimit = uint256S("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
256253
consensus.nPowTargetTimespan = 14 * 24 * 60 * 60; // two weeks
257254
consensus.nPowTargetSpacing = 10 * 60;

src/consensus/params.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ struct BIP9Deployment {
3939
struct Params {
4040
uint256 hashGenesisBlock;
4141
int nSubsidyHalvingInterval;
42-
/** Used to check majorities for block version upgrade */
43-
int nMajorityEnforceBlockUpgrade;
44-
int nMajorityRejectBlockOutdated;
45-
int nMajorityWindow;
4642
/** Block height and hash at which BIP34 becomes active */
4743
int BIP34Height;
4844
uint256 BIP34Hash;
45+
/** Block height at which BIP65 becomes active */
46+
int BIP65Height;
47+
/** Block height at which BIP66 becomes active */
48+
int BIP66Height;
4949
/**
5050
* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargetting period,
5151
* (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.

src/main.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ map<uint256, COrphanTx> mapOrphanTransactions GUARDED_BY(cs_main);
106106
map<COutPoint, set<map<uint256, COrphanTx>::iterator, IteratorComparator>> mapOrphanTransactionsByPrev GUARDED_BY(cs_main);
107107
void EraseOrphansFor(NodeId peer) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
108108

109-
/**
110-
* Returns true if there are nRequired or more blocks of minVersion or above
111-
* in the last Consensus::Params::nMajorityWindow blocks, starting at pstart and going backwards.
112-
*/
113-
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams);
114109
static void CheckBlockIndex(const Consensus::Params& consensusParams);
115110

116111
/** Constant stuff for coinbase transactions we create: */
@@ -2372,15 +2367,13 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
23722367

23732368
unsigned int flags = fStrictPayToScriptHash ? SCRIPT_VERIFY_P2SH : SCRIPT_VERIFY_NONE;
23742369

2375-
// Start enforcing the DERSIG (BIP66) rules, for block.nVersion=3 blocks,
2376-
// when 75% of the network has upgraded:
2377-
if (block.nVersion >= 3 && IsSuperMajority(3, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) {
2370+
// Start enforcing the DERSIG (BIP66) rule
2371+
if (pindex->nHeight >= chainparams.GetConsensus().BIP66Height) {
23782372
flags |= SCRIPT_VERIFY_DERSIG;
23792373
}
23802374

2381-
// Start enforcing CHECKLOCKTIMEVERIFY, (BIP65) for block.nVersion=4
2382-
// blocks, when 75% of the network has upgraded:
2383-
if (block.nVersion >= 4 && IsSuperMajority(4, pindex->pprev, chainparams.GetConsensus().nMajorityEnforceBlockUpgrade, chainparams.GetConsensus())) {
2375+
// Start enforcing CHECKLOCKTIMEVERIFY (BIP65) rule
2376+
if (pindex->nHeight >= chainparams.GetConsensus().BIP65Height) {
23842377
flags |= SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY;
23852378
}
23862379

@@ -3504,6 +3497,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
35043497

35053498
bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev, int64_t nAdjustedTime)
35063499
{
3500+
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1;
35073501
// Check proof of work
35083502
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams))
35093503
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, "incorrect proof of work");
@@ -3517,10 +3511,12 @@ bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& sta
35173511
return state.Invalid(false, REJECT_INVALID, "time-too-new", "block timestamp too far in the future");
35183512

35193513
// Reject outdated version blocks when 95% (75% on testnet) of the network has upgraded:
3520-
for (int32_t version = 2; version < 5; ++version) // check for version 2, 3 and 4 upgrades
3521-
if (block.nVersion < version && IsSuperMajority(version, pindexPrev, consensusParams.nMajorityRejectBlockOutdated, consensusParams))
3522-
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", version - 1),
3523-
strprintf("rejected nVersion=0x%08x block", version - 1));
3514+
// check for version 2, 3 and 4 upgrades
3515+
if((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) ||
3516+
(block.nVersion < 3 && nHeight >= consensusParams.BIP66Height) ||
3517+
(block.nVersion < 4 && nHeight >= consensusParams.BIP65Height))
3518+
return state.Invalid(false, REJECT_OBSOLETE, strprintf("bad-version(0x%08x)", block.nVersion),
3519+
strprintf("rejected nVersion=0x%08x block", block.nVersion));
35243520

35253521
return true;
35263522
}
@@ -3546,9 +3542,8 @@ bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const Co
35463542
}
35473543
}
35483544

3549-
// Enforce block.nVersion=2 rule that the coinbase starts with serialized block height
3550-
// if 750 of the last 1,000 blocks are version 2 or greater (51/100 if testnet):
3551-
if (block.nVersion >= 2 && IsSuperMajority(2, pindexPrev, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams))
3545+
// Enforce rule that the coinbase starts with serialized block height
3546+
if (nHeight >= consensusParams.BIP34Height)
35523547
{
35533548
CScript expect = CScript() << nHeight;
35543549
if (block.vtx[0].vin[0].scriptSig.size() < expect.size() ||
@@ -3722,19 +3717,6 @@ static bool AcceptBlock(const CBlock& block, CValidationState& state, const CCha
37223717
return true;
37233718
}
37243719

3725-
static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned nRequired, const Consensus::Params& consensusParams)
3726-
{
3727-
unsigned int nFound = 0;
3728-
for (int i = 0; i < consensusParams.nMajorityWindow && nFound < nRequired && pstart != NULL; i++)
3729-
{
3730-
if (pstart->nVersion >= minVersion)
3731-
++nFound;
3732-
pstart = pstart->pprev;
3733-
}
3734-
return (nFound >= nRequired);
3735-
}
3736-
3737-
37383720
bool ProcessNewBlock(CValidationState& state, const CChainParams& chainparams, CNode* pfrom, const CBlock* pblock, bool fForceProcessing, const CDiskBlockPos* dbp)
37393721
{
37403722
{

src/rpc/blockchain.cpp

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -817,22 +817,23 @@ UniValue verifychain(const UniValue& params, bool fHelp)
817817
}
818818

819819
/** Implementation of IsSuperMajority with better feedback */
820-
static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired, const Consensus::Params& consensusParams)
820+
static UniValue SoftForkMajorityDesc(int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
821821
{
822-
int nFound = 0;
823-
CBlockIndex* pstart = pindex;
824-
for (int i = 0; i < consensusParams.nMajorityWindow && pstart != NULL; i++)
822+
UniValue rv(UniValue::VOBJ);
823+
bool activated = false;
824+
switch(version)
825825
{
826-
if (pstart->nVersion >= minVersion)
827-
++nFound;
828-
pstart = pstart->pprev;
826+
case 2:
827+
activated = pindex->nHeight >= consensusParams.BIP34Height;
828+
break;
829+
case 3:
830+
activated = pindex->nHeight >= consensusParams.BIP66Height;
831+
break;
832+
case 4:
833+
activated = pindex->nHeight >= consensusParams.BIP65Height;
834+
break;
829835
}
830-
831-
UniValue rv(UniValue::VOBJ);
832-
rv.push_back(Pair("status", nFound >= nRequired));
833-
rv.push_back(Pair("found", nFound));
834-
rv.push_back(Pair("required", nRequired));
835-
rv.push_back(Pair("window", consensusParams.nMajorityWindow));
836+
rv.push_back(Pair("status", activated));
836837
return rv;
837838
}
838839

@@ -841,8 +842,7 @@ static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex*
841842
UniValue rv(UniValue::VOBJ);
842843
rv.push_back(Pair("id", name));
843844
rv.push_back(Pair("version", version));
844-
rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)));
845-
rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, consensusParams.nMajorityRejectBlockOutdated, consensusParams)));
845+
rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, consensusParams)));
846846
return rv;
847847
}
848848

@@ -897,13 +897,9 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
897897
" {\n"
898898
" \"id\": \"xxxx\", (string) name of softfork\n"
899899
" \"version\": xx, (numeric) block version\n"
900-
" \"enforce\": { (object) progress toward enforcing the softfork rules for new-version blocks\n"
900+
" \"reject\": { (object) progress toward rejecting pre-softfork blocks\n"
901901
" \"status\": xx, (boolean) true if threshold reached\n"
902-
" \"found\": xx, (numeric) number of blocks with the new version found\n"
903-
" \"required\": xx, (numeric) number of blocks required to trigger\n"
904-
" \"window\": xx, (numeric) maximum size of examined window of recent blocks\n"
905902
" },\n"
906-
" \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
907903
" }, ...\n"
908904
" ],\n"
909905
" \"bip9_softforks\": { (object) status of BIP9 softforks in progress\n"

0 commit comments

Comments
 (0)