Skip to content

Commit aab22dd

Browse files
committed
apply functional tests to block height changes
1 parent 3f3b3ab commit aab22dd

23 files changed

+178
-165
lines changed

src/chainparams.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class CMainParams : public CChainParams {
118118

119119
genesis = CreateGenesisBlock(1231006505, 2083236893, 0x1d00ffff, 1, 50 * COIN);
120120
consensus.hashGenesisBlock = genesis.GetHash();
121-
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", false);
121+
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", true);
122122
// Serialization will not match if true
123123
if (!consensus.blockheight_in_header) {
124124
assert(consensus.hashGenesisBlock == uint256S("0x000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f"));
@@ -231,7 +231,7 @@ class CTestNetParams : public CChainParams {
231231

232232
genesis = CreateGenesisBlock(1296688602, 414098458, 0x1d00ffff, 1, 50 * COIN);
233233
consensus.hashGenesisBlock = genesis.GetHash();
234-
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", false);
234+
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", true);
235235
// Serialization will not match if true
236236
if (!consensus.blockheight_in_header) {
237237
assert(consensus.hashGenesisBlock == uint256S("0x000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"));
@@ -326,7 +326,7 @@ class CRegTestParams : public CChainParams {
326326

327327
genesis = CreateGenesisBlock(1296688602, 2, 0x207fffff, 1, 50 * COIN);
328328
consensus.hashGenesisBlock = genesis.GetHash();
329-
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", false);
329+
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", true);
330330
// Serialization will not match if true
331331
if (!consensus.blockheight_in_header) {
332332
assert(consensus.hashGenesisBlock == uint256S("0x0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206"));
@@ -434,7 +434,7 @@ class CCustomParams : public CRegTestParams {
434434

435435
// Note: This gArg is accessed one more time in block.h for serialization to avoid
436436
// circular dependency
437-
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", false);
437+
consensus.blockheight_in_header = gArgs.GetBoolArg("-con_blockheightinheader", true);
438438

439439
// All non-zero coinbase outputs must go to this scriptPubKey
440440
std::vector<unsigned char> man_bytes = ParseHex(gArgs.GetArg("-con_mandatorycoinbase", ""));

src/primitives/block.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class CBlockHeader
4646
READWRITE(hashMerkleRoot);
4747
READWRITE(nTime);
4848
// Also found in consensus params as blockheight_in_header (circular dep otherwise)
49-
if (gArgs.GetBoolArg("-con_blockheightinheader", false)) {
49+
if (gArgs.GetBoolArg("-con_blockheightinheader", true)) {
5050
READWRITE(block_height);
5151
}
5252
READWRITE(nBits);

src/txdb.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
263263
CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
264264
pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
265265
pindexNew->nHeight = diskindex.nHeight;
266+
pindexNew->block_height = diskindex.block_height;
266267
pindexNew->nFile = diskindex.nFile;
267268
pindexNew->nDataPos = diskindex.nDataPos;
268269
pindexNew->nUndoPos = diskindex.nUndoPos;

test/functional/data/rpc_getblockstats.json

Lines changed: 114 additions & 114 deletions
Large diffs are not rendered by default.

test/functional/feature_block.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ def run_test(self):
535535
b44.hashPrevBlock = self.tip.sha256
536536
b44.nBits = 0x207fffff
537537
b44.vtx.append(coinbase)
538+
b44.block_height = height
538539
b44.hashMerkleRoot = b44.calc_merkle_root()
539540
b44.solve()
540541
self.tip = b44
@@ -549,6 +550,7 @@ def run_test(self):
549550
b45.hashPrevBlock = self.tip.sha256
550551
b45.nBits = 0x207fffff
551552
b45.vtx.append(non_coinbase)
553+
b45.block_height = height+1
552554
b45.hashMerkleRoot = b45.calc_merkle_root()
553555
b45.calc_sha256()
554556
b45.solve()
@@ -564,6 +566,7 @@ def run_test(self):
564566
b46.hashPrevBlock = b44.sha256
565567
b46.nBits = 0x207fffff
566568
b46.vtx = []
569+
b46.block_height = height+1
567570
b46.hashMerkleRoot = 0
568571
b46.solve()
569572
self.block_heights[b46.sha256] = self.block_heights[b44.sha256] + 1
@@ -1242,11 +1245,11 @@ def next_block(self, number, spend=None, additional_coinbase_value=0, script=CSc
12421245
coinbase.vout[0].nValue += additional_coinbase_value
12431246
coinbase.rehash()
12441247
if spend is None:
1245-
block = create_block(base_block_hash, coinbase, block_time)
1248+
block = create_block(base_block_hash, coinbase, height, block_time)
12461249
else:
12471250
coinbase.vout[0].nValue += spend.vout[0].nValue - 1 # all but one satoshi to fees
12481251
coinbase.rehash()
1249-
block = create_block(base_block_hash, coinbase, block_time)
1252+
block = create_block(base_block_hash, coinbase, height, block_time)
12501253
tx = self.create_tx(spend, 0, 1, script) # spend 1 satoshi
12511254
self.sign_tx(tx, spend)
12521255
self.add_transactions_to_block(block, [tx])

test/functional/feature_cltv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def run_test(self):
7373

7474
tip = self.nodes[0].getbestblockhash()
7575
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
76-
block = create_block(int(tip, 16), create_coinbase(CLTV_HEIGHT - 1), block_time)
76+
block = create_block(int(tip, 16), create_coinbase(CLTV_HEIGHT - 1), CLTV_HEIGHT-1, block_time)
7777
block.nVersion = 3
7878
block.vtx.append(spendtx)
7979
block.hashMerkleRoot = block.calc_merkle_root()
@@ -85,7 +85,7 @@ def run_test(self):
8585
self.log.info("Test that blocks must now be at least version 4")
8686
tip = block.sha256
8787
block_time += 1
88-
block = create_block(tip, create_coinbase(CLTV_HEIGHT), block_time)
88+
block = create_block(tip, create_coinbase(CLTV_HEIGHT), CLTV_HEIGHT, block_time)
8989
block.nVersion = 3
9090
block.solve()
9191
self.nodes[0].p2p.send_and_ping(msg_block(block))

test/functional/feature_csv_activation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def generate_blocks(self, number, version, test_blocks=None):
157157
return test_blocks
158158

159159
def create_test_block(self, txs, version=536870912):
160-
block = create_block(self.tip, create_coinbase(self.tipheight + 1), self.last_block_time + 600)
160+
block = create_block(self.tip, create_coinbase(self.tipheight + 1), self.tipheight + 1, self.last_block_time + 600)
161161
block.nVersion = version
162162
block.vtx.extend(txs)
163163
block.hashMerkleRoot = block.calc_merkle_root()

test/functional/feature_dersig.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def run_test(self):
6161

6262
tip = self.nodes[0].getbestblockhash()
6363
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
64-
block = create_block(int(tip, 16), create_coinbase(DERSIG_HEIGHT - 1), block_time)
64+
block = create_block(int(tip, 16), create_coinbase(DERSIG_HEIGHT - 1), DERSIG_HEIGHT-1, block_time)
6565
block.nVersion = 2
6666
block.vtx.append(spendtx)
6767
block.hashMerkleRoot = block.calc_merkle_root()
@@ -74,7 +74,7 @@ def run_test(self):
7474
self.log.info("Test that blocks must now be at least version 3")
7575
tip = block.sha256
7676
block_time += 1
77-
block = create_block(tip, create_coinbase(DERSIG_HEIGHT), block_time)
77+
block = create_block(tip, create_coinbase(DERSIG_HEIGHT), DERSIG_HEIGHT, block_time)
7878
block.nVersion = 2
7979
block.rehash()
8080
block.solve()

test/functional/feature_nulldummy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def run_test(self):
9898

9999

100100
def block_submit(self, node, txs, witness = False, accept = False):
101-
block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblocktime + 1)
101+
block = create_block(self.tip, create_coinbase(self.lastblockheight + 1), self.lastblockheight + 1, self.lastblocktime + 1)
102102
block.nVersion = 4
103103
for tx in txs:
104104
tx.rehash()

test/functional/feature_versionbits_warning.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def send_blocks_with_version(self, peer, numblocks, version):
4747
tip = int(tip, 16)
4848

4949
for _ in range(numblocks):
50-
block = create_block(tip, create_coinbase(height + 1), block_time)
50+
block = create_block(tip, create_coinbase(height + 1), height+1, block_time)
5151
block.nVersion = version
5252
block.solve()
5353
peer.send_message(msg_block(block))

0 commit comments

Comments
 (0)