Skip to content

Commit e04f6c7

Browse files
committed
Activate BIPs 34, 65, 66 at block 0
- Reinstate Bitcoin BIP activation heights for tests - Add tests for block v4 after genesis block
1 parent 8a472b9 commit e04f6c7

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

src/chainparams.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,10 @@ class CCustomParams : public CRegTestParams {
417417

418418
consensus.nSubsidyHalvingInterval = args.GetArg("-con_nsubsidyhalvinginterval", consensus.nSubsidyHalvingInterval);
419419
consensus.BIP16Exception = uint256S(args.GetArg("-con_bip16exception", "0x0"));
420-
consensus.BIP34Height = args.GetArg("-con_bip34height", consensus.BIP34Height);
420+
consensus.BIP34Height = args.GetArg("-con_bip34height", 0);
421421
consensus.BIP34Hash = uint256S(args.GetArg("-con_bip34hash", "0x0"));
422-
consensus.BIP65Height = args.GetArg("-con_bip65height", consensus.BIP65Height);
423-
consensus.BIP66Height = args.GetArg("-con_bip66height", consensus.BIP66Height);
422+
consensus.BIP65Height = args.GetArg("-con_bip65height", 0);
423+
consensus.BIP66Height = args.GetArg("-con_bip66height", 0);
424424
consensus.powLimit = uint256S(args.GetArg("-con_powlimit", "7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"));
425425
consensus.nPowTargetTimespan = args.GetArg("-con_npowtargettimespan", consensus.nPowTargetTimespan);
426426
consensus.nPowTargetSpacing = args.GetArg("-con_npowtargetspacing", consensus.nPowTargetSpacing);

test/bitcoin_functional/functional/test_framework/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,9 @@ def initialize_datadir(dirname, n, chain):
309309
f.write("con_connect_coinbase=0\n")
310310
f.write("anyonecanspendaremine=0\n")
311311
f.write("con_blockheightinheader=0\n")
312+
f.write("con_bip34height=100000000\n")
313+
f.write("con_bip65height=1351\n")
314+
f.write("con_bip66height=1251\n")
312315
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
313316
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
314317
return datadir
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2015-2018 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test BIP 34, 65, 66 activation at block 0"""
6+
7+
from test_framework.blocktools import create_coinbase, create_block, create_transaction
8+
from test_framework.messages import msg_block
9+
from test_framework.mininode import mininode_lock, P2PInterface
10+
from test_framework.test_framework import BitcoinTestFramework
11+
from test_framework.util import assert_equal, wait_until
12+
13+
from feature_cltv import cltv_validate, REJECT_OBSOLETE
14+
15+
class BlockV4Test(BitcoinTestFramework):
16+
def set_test_params(self):
17+
self.num_nodes = 1
18+
self.extra_args = [['-whitelist=127.0.0.1', '-con_bip34height=0', '-con_bip65height=0', '-con_bip66height=0']]
19+
self.setup_clean_chain = True
20+
21+
def run_test(self):
22+
self.nodes[0].add_p2p_connection(P2PInterface())
23+
24+
self.nodeaddress = self.nodes[0].getnewaddress()
25+
26+
self.log.info("Test that blocks past the genesis block must be at least version 4")
27+
28+
# Create a v3 block
29+
tip = self.nodes[0].getbestblockhash()
30+
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
31+
block = create_block(int(tip, 16), create_coinbase(1), block_time)
32+
block.nVersion = 3
33+
block.solve()
34+
35+
# Send it to the node
36+
self.nodes[0].p2p.send_and_ping(msg_block(block))
37+
38+
# The best block should not have changed, because...
39+
assert_equal(self.nodes[0].getbestblockhash(), tip)
40+
41+
# ... we rejected it because it is v3
42+
wait_until(lambda: "reject" in self.nodes[0].p2p.last_message.keys(), lock=mininode_lock)
43+
with mininode_lock:
44+
assert_equal(self.nodes[0].p2p.last_message["reject"].code, REJECT_OBSOLETE)
45+
assert_equal(self.nodes[0].p2p.last_message["reject"].reason, b'bad-version(0x00000003)')
46+
assert_equal(self.nodes[0].p2p.last_message["reject"].data, block.sha256)
47+
del self.nodes[0].p2p.last_message["reject"]
48+
49+
self.log.info("Test that a version 4 block with a valid-according-to-CLTV transaction is accepted")
50+
51+
# Generate 100 blocks so that first coinbase matures
52+
generated_blocks = self.nodes[0].generate(100)
53+
spendable_coinbase_txid = self.nodes[0].getblock(generated_blocks[0])['tx'][0]
54+
tip = generated_blocks[-1]
55+
56+
# Construct a v4 block
57+
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
58+
block = create_block(int(tip, 16), create_coinbase(len(generated_blocks) + 1), block_time)
59+
block.nVersion = 4
60+
61+
# Create a CLTV transaction
62+
spendtx = create_transaction(self.nodes[0], spendable_coinbase_txid,
63+
self.nodeaddress, amount=1.0)
64+
spendtx = cltv_validate(self.nodes[0], spendtx, 1)
65+
spendtx.rehash()
66+
67+
# Add the CLTV transaction and prepare for sending
68+
block.vtx.append(spendtx)
69+
block.hashMerkleRoot = block.calc_merkle_root()
70+
block.solve()
71+
72+
# Send block and check that it becomes new best block
73+
self.nodes[0].p2p.send_and_ping(msg_block(block))
74+
assert_equal(int(self.nodes[0].getbestblockhash(), 16), block.sha256)
75+
76+
if __name__ == '__main__':
77+
BlockV4Test().main()

test/functional/test_framework/util.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,9 @@ def initialize_datadir(dirname, n, chain):
308308
f.write("con_blocksubsidy=5000000000\n")
309309
f.write("con_connect_coinbase=0\n")
310310
f.write("anyonecanspendaremine=0\n")
311+
f.write("con_bip34height=100000000\n")
312+
f.write("con_bip65height=1351\n")
313+
f.write("con_bip66height=1251\n")
311314
os.makedirs(os.path.join(datadir, 'stderr'), exist_ok=True)
312315
os.makedirs(os.path.join(datadir, 'stdout'), exist_ok=True)
313316
return datadir

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
'feature_mandatory_coinbase.py',
171171
'feature_block_subsidy.py',
172172
'feature_connect_coinbase.py',
173+
'feature_block_v4.py'
173174
# Don't append tests at the end to avoid merge conflicts
174175
# Put them in a random line within the section that fits their approximate run-time
175176
]

0 commit comments

Comments
 (0)