Skip to content

Commit 5d83e7d

Browse files
committed
Merge bitcoin/bitcoin#21090: Default to NODE_WITNESS in nLocalServices
a806647 [validation] Always include merkle root in coinbase commitment (Dhruv Mehta) 189128c [validation] Set witness script flag with p2sh for blocks (Dhruv Mehta) ac82b99 [p2p] remove redundant NODE_WITNESS checks (Dhruv Mehta) 6f8b198 [p2p] remove unused segwitheight=-1 option (Dhruv Mehta) eba5b1c [test] remove or move tests using `-segwitheight=-1` (Dhruv Mehta) Pull request description: Builds on #21009 and makes progress on remaining items in #17862 Removing `RewindBlockIndex()` in #21009 allows the following: - removal of tests using `segwitheight=-1` in `p2p_segwit.py`. - move `test_upgrade_after_activation()` out of `p2p_segwit.py` reducing runtime - in turn, that allows us to drop support for `-segwitheight=-1`, which is only supported for that test. - that allows us to always set `NODE_WITNESS` in our local services. The only reason we don't do that is to support `-segwitheight=-1`. - that in turn allows us to drop all of the `GetLocalServices() & NODE_WITNESS` checks inside `net_processing.cpp`, since our local services would always include `NODE_WITNESS` ACKs for top commit: mzumsande: Code-Review ACK a806647 laanwj: Code review ACK a806647, nice cleanup jnewbery: utACK a806647 theStack: ACK a806647 Tree-SHA512: 73e1a69d1d7eca1f5c38558ec6672decd0b60b16c2ef6134df6f6af71bb159e6eea160f9bb5ab0eb6723c6632d29509811e29469d0d87abbe9b69a2890fbc73e
2 parents bfa52cb + a806647 commit 5d83e7d

File tree

9 files changed

+103
-127
lines changed

9 files changed

+103
-127
lines changed

src/chainparams.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,8 @@ void CRegTestParams::UpdateActivationParametersFromArgs(const ArgsManager& args)
490490
{
491491
if (args.IsArgSet("-segwitheight")) {
492492
int64_t height = args.GetArg("-segwitheight", consensus.SegwitHeight);
493-
if (height < -1 || height >= std::numeric_limits<int>::max()) {
494-
throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range. Use -1 to disable segwit.", height));
495-
} else if (height == -1) {
496-
LogPrintf("Segwit disabled for testing\n");
497-
height = std::numeric_limits<int>::max();
493+
if (height < 0 || height >= std::numeric_limits<int>::max()) {
494+
throw std::runtime_error(strprintf("Activation height %ld for segwit is out of valid range.", height));
498495
}
499496
consensus.SegwitHeight = static_cast<int>(height);
500497
}

src/chainparamsbase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void SetupChainParamsBaseOptions(ArgsManager& argsman)
2020
argsman.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, signet, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2121
argsman.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
2222
"This is intended for regression testing tools and app development. Equivalent to -chain=regtest.", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
23-
argsman.AddArg("-segwitheight=<n>", "Set the activation height of segwit. -1 to disable. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
23+
argsman.AddArg("-segwitheight=<n>", "Set the activation height of segwit. (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
2424
argsman.AddArg("-testnet", "Use the test chain. Equivalent to -chain=test.", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2525
argsman.AddArg("-vbparams=deployment:start:end[:min_activation_height]", "Use given start/end times and min_activation_height for specified version bits deployment (regtest-only)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::CHAINPARAMS);
2626
argsman.AddArg("-signet", "Use the signet chain. Equivalent to -chain=signet. Note that the network is defined by the -signetchallenge parameter", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);

src/init.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ namespace { // Variables internal to initialization process only
715715
int nMaxConnections;
716716
int nUserMaxConnections;
717717
int nFD;
718-
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED);
718+
ServiceFlags nLocalServices = ServiceFlags(NODE_NETWORK | NODE_NETWORK_LIMITED | NODE_WITNESS);
719719
int64_t peer_connect_timeout;
720720
std::set<BlockFilterType> g_enabled_filter_types;
721721

@@ -1588,12 +1588,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
15881588
}
15891589
}
15901590

1591-
if (DeploymentEnabled(chainparams.GetConsensus(), Consensus::DEPLOYMENT_SEGWIT)) {
1592-
// Advertise witness capabilities.
1593-
// The option to not set NODE_WITNESS is only used in the tests and should be removed.
1594-
nLocalServices = ServiceFlags(nLocalServices | NODE_WITNESS);
1595-
}
1596-
15971591
// ********************************************************* Step 11: import blocks
15981592

15991593
if (!CheckDiskSpace(gArgs.GetDataDirNet())) {

src/net_processing.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ void PeerManagerImpl::MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid)
877877
}
878878
m_connman.ForNode(nodeid, [this](CNode* pfrom) EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
879879
AssertLockHeld(::cs_main);
880-
uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1;
880+
uint64_t nCMPCTBLOCKVersion = 2;
881881
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
882882
// As per BIP152, we only get 3 of our peers to announce
883883
// blocks using compact encodings.
@@ -1973,7 +1973,7 @@ void PeerManagerImpl::ProcessGetData(CNode& pfrom, Peer& peer, const std::atomic
19731973

19741974
static uint32_t GetFetchFlags(const CNode& pfrom) EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
19751975
uint32_t nFetchFlags = 0;
1976-
if ((pfrom.GetLocalServices() & NODE_WITNESS) && State(pfrom.GetId())->fHaveWitness) {
1976+
if (State(pfrom.GetId())->fHaveWitness) {
19771977
nFetchFlags |= MSG_WITNESS_FLAG;
19781978
}
19791979
return nFetchFlags;
@@ -2688,8 +2688,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
26882688
// they may wish to request compact blocks from us
26892689
bool fAnnounceUsingCMPCTBLOCK = false;
26902690
uint64_t nCMPCTBLOCKVersion = 2;
2691-
if (pfrom.GetLocalServices() & NODE_WITNESS)
2692-
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
2691+
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
26932692
nCMPCTBLOCKVersion = 1;
26942693
m_connman.PushMessage(&pfrom, msgMaker.Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion));
26952694
}
@@ -2707,7 +2706,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
27072706
bool fAnnounceUsingCMPCTBLOCK = false;
27082707
uint64_t nCMPCTBLOCKVersion = 0;
27092708
vRecv >> fAnnounceUsingCMPCTBLOCK >> nCMPCTBLOCKVersion;
2710-
if (nCMPCTBLOCKVersion == 1 || ((pfrom.GetLocalServices() & NODE_WITNESS) && nCMPCTBLOCKVersion == 2)) {
2709+
if (nCMPCTBLOCKVersion == 1 || nCMPCTBLOCKVersion == 2) {
27112710
LOCK(cs_main);
27122711
// fProvidesHeaderAndIDs is used to "lock in" version of compact blocks we send (fWantsCmpctWitness)
27132712
if (!State(pfrom.GetId())->fProvidesHeaderAndIDs) {
@@ -2721,10 +2720,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
27212720
pfrom.m_bip152_highbandwidth_from = fAnnounceUsingCMPCTBLOCK;
27222721
}
27232722
if (!State(pfrom.GetId())->fSupportsDesiredCmpctVersion) {
2724-
if (pfrom.GetLocalServices() & NODE_WITNESS)
2725-
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
2726-
else
2727-
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 1);
2723+
State(pfrom.GetId())->fSupportsDesiredCmpctVersion = (nCMPCTBLOCKVersion == 2);
27282724
}
27292725
}
27302726
return;

src/validation.cpp

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,13 +1645,8 @@ static unsigned int GetBlockScriptFlags(const CBlockIndex* pindex, const Consens
16451645
pindex->phashBlock == nullptr || // this is a new candidate block, eg from TestBlockValidity()
16461646
*pindex->phashBlock != consensusparams.BIP16Exception) // this block isn't the historical exception
16471647
{
1648-
flags |= SCRIPT_VERIFY_P2SH;
1649-
}
1650-
1651-
// Enforce WITNESS rules whenever P2SH is in effect (and the segwit
1652-
// deployment is defined).
1653-
if (flags & SCRIPT_VERIFY_P2SH && DeploymentEnabled(consensusparams, Consensus::DEPLOYMENT_SEGWIT)) {
1654-
flags |= SCRIPT_VERIFY_WITNESS;
1648+
// Enforce WITNESS rules whenever P2SH is in effect
1649+
flags |= SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_WITNESS;
16551650
}
16561651

16571652
// Enforce the DERSIG (BIP66) rule
@@ -3101,25 +3096,23 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
31013096
std::vector<unsigned char> commitment;
31023097
int commitpos = GetWitnessCommitmentIndex(block);
31033098
std::vector<unsigned char> ret(32, 0x00);
3104-
if (DeploymentEnabled(consensusParams, Consensus::DEPLOYMENT_SEGWIT)) {
3105-
if (commitpos == NO_WITNESS_COMMITMENT) {
3106-
uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr);
3107-
CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot);
3108-
CTxOut out;
3109-
out.nValue = 0;
3110-
out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
3111-
out.scriptPubKey[0] = OP_RETURN;
3112-
out.scriptPubKey[1] = 0x24;
3113-
out.scriptPubKey[2] = 0xaa;
3114-
out.scriptPubKey[3] = 0x21;
3115-
out.scriptPubKey[4] = 0xa9;
3116-
out.scriptPubKey[5] = 0xed;
3117-
memcpy(&out.scriptPubKey[6], witnessroot.begin(), 32);
3118-
commitment = std::vector<unsigned char>(out.scriptPubKey.begin(), out.scriptPubKey.end());
3119-
CMutableTransaction tx(*block.vtx[0]);
3120-
tx.vout.push_back(out);
3121-
block.vtx[0] = MakeTransactionRef(std::move(tx));
3122-
}
3099+
if (commitpos == NO_WITNESS_COMMITMENT) {
3100+
uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr);
3101+
CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot);
3102+
CTxOut out;
3103+
out.nValue = 0;
3104+
out.scriptPubKey.resize(MINIMUM_WITNESS_COMMITMENT);
3105+
out.scriptPubKey[0] = OP_RETURN;
3106+
out.scriptPubKey[1] = 0x24;
3107+
out.scriptPubKey[2] = 0xaa;
3108+
out.scriptPubKey[3] = 0x21;
3109+
out.scriptPubKey[4] = 0xa9;
3110+
out.scriptPubKey[5] = 0xed;
3111+
memcpy(&out.scriptPubKey[6], witnessroot.begin(), 32);
3112+
commitment = std::vector<unsigned char>(out.scriptPubKey.begin(), out.scriptPubKey.end());
3113+
CMutableTransaction tx(*block.vtx[0]);
3114+
tx.vout.push_back(out);
3115+
block.vtx[0] = MakeTransactionRef(std::move(tx));
31233116
}
31243117
UpdateUncommittedBlockStructures(block, pindexPrev, consensusParams);
31253118
return commitment;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2017-2020 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 a pre-segwit node upgrading to segwit consensus"""
6+
7+
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import (
9+
assert_equal,
10+
softfork_active,
11+
)
12+
13+
class SegwitUpgradeTest(BitcoinTestFramework):
14+
def set_test_params(self):
15+
self.setup_clean_chain = True
16+
self.num_nodes = 1
17+
self.extra_args = [["-segwitheight=10"]]
18+
19+
def run_test(self):
20+
"""A pre-segwit node with insufficiently validated blocks needs to redownload blocks"""
21+
22+
self.log.info("Testing upgrade behaviour for pre-segwit node to segwit rules")
23+
node = self.nodes[0]
24+
25+
# Node hasn't been used or connected yet
26+
assert_equal(node.getblockcount(), 0)
27+
28+
assert not softfork_active(node, "segwit")
29+
30+
# Generate 8 blocks without witness data
31+
node.generate(8)
32+
assert_equal(node.getblockcount(), 8)
33+
34+
self.stop_node(0)
35+
# Restarting the node (with segwit activation height set to 5) should result in a shutdown
36+
# because the blockchain consists of 3 insufficiently validated blocks per segwit consensus rules.
37+
node.assert_start_raises_init_error(
38+
extra_args=["-segwitheight=5"],
39+
expected_msg=": Witness data for blocks after height 5 requires validation. Please restart with -reindex..\nPlease restart with -reindex or -reindex-chainstate to recover.")
40+
41+
# As directed, the user restarts the node with -reindex
42+
self.start_node(0, extra_args=["-reindex", "-segwitheight=5"])
43+
44+
# With the segwit consensus rules, the node is able to validate only up to block 4
45+
assert_equal(node.getblockcount(), 4)
46+
47+
# The upgraded node should now have segwit activated
48+
assert softfork_active(node, "segwit")
49+
50+
51+
if __name__ == '__main__':
52+
SegwitUpgradeTest().main()

test/functional/mining_basic.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313

1414
from test_framework.blocktools import (
1515
create_coinbase,
16+
get_witness_script,
1617
NORMAL_GBT_REQUEST_PARAMS,
1718
TIME_GENESIS_BLOCK,
1819
)
1920
from test_framework.messages import (
2021
CBlock,
2122
CBlockHeader,
2223
BLOCK_HEADER_SIZE,
24+
ser_uint256,
2325
)
2426
from test_framework.p2p import P2PDataStore
2527
from test_framework.test_framework import BitcoinTestFramework
@@ -49,6 +51,9 @@ def set_test_params(self):
4951
self.setup_clean_chain = True
5052
self.supports_cli = False
5153

54+
def skip_test_if_missing_module(self):
55+
self.skip_if_no_wallet()
56+
5257
def mine_chain(self):
5358
self.log.info('Create some old blocks')
5459
for t in range(TIME_GENESIS_BLOCK, TIME_GENESIS_BLOCK + 200 * 600, 600):
@@ -89,7 +94,21 @@ def assert_submitblock(block, result_str_1, result_str_2=None):
8994
assert_equal(mining_info['networkhashps'], Decimal('0.003333333333333334'))
9095
assert_equal(mining_info['pooledtx'], 0)
9196

92-
# Mine a block to leave initial block download
97+
self.log.info("getblocktemplate: Test default witness commitment")
98+
txid = int(node.sendtoaddress(node.getnewaddress(), 1), 16)
99+
tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
100+
101+
# Check that default_witness_commitment is present.
102+
assert 'default_witness_commitment' in tmpl
103+
witness_commitment = tmpl['default_witness_commitment']
104+
105+
# Check that default_witness_commitment is correct.
106+
witness_root = CBlock.get_merkle_root([ser_uint256(0),
107+
ser_uint256(txid)])
108+
script = get_witness_script(witness_root, 0)
109+
assert_equal(witness_commitment, script.hex())
110+
111+
# Mine a block to leave initial block download and clear the mempool
93112
node.generatetoaddress(1, node.get_deterministic_priv_key().address)
94113
tmpl = node.getblocktemplate(NORMAL_GBT_REQUEST_PARAMS)
95114
self.log.info("getblocktemplate: Test capability advertised")

test/functional/p2p_segwit.py

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
import struct
1010
import time
1111

12-
from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment, get_witness_script, WITNESS_COMMITMENT_HEADER
12+
from test_framework.blocktools import create_block, create_coinbase, add_witness_commitment, WITNESS_COMMITMENT_HEADER
1313
from test_framework.key import ECKey
1414
from test_framework.messages import (
1515
BIP125_SEQUENCE_NUMBER,
16-
CBlock,
1716
CBlockHeader,
1817
CInv,
1918
COutPoint,
@@ -206,24 +205,17 @@ def request_block(self, blockhash, inv_type, timeout=60):
206205
class SegWitTest(BitcoinTestFramework):
207206
def set_test_params(self):
208207
self.setup_clean_chain = True
209-
self.num_nodes = 3
208+
self.num_nodes = 2
210209
# This test tests SegWit both pre and post-activation, so use the normal BIP9 activation.
211210
self.extra_args = [
212211
["-acceptnonstdtxn=1", "-segwitheight={}".format(SEGWIT_HEIGHT), "[email protected]"],
213212
["-acceptnonstdtxn=0", "-segwitheight={}".format(SEGWIT_HEIGHT)],
214-
["-acceptnonstdtxn=1", "-segwitheight=-1"],
215213
]
216214
self.supports_cli = False
217215

218216
def skip_test_if_missing_module(self):
219217
self.skip_if_no_wallet()
220218

221-
def setup_network(self):
222-
self.setup_nodes()
223-
self.connect_nodes(0, 1)
224-
self.connect_nodes(0, 2)
225-
self.sync_all()
226-
227219
# Helper functions
228220

229221
def build_next_block(self, version=4):
@@ -264,7 +256,6 @@ def run_test(self):
264256
self.test_non_witness_transaction()
265257
self.test_v0_outputs_arent_spendable()
266258
self.test_block_relay()
267-
self.test_getblocktemplate_before_lockin()
268259
self.test_unnecessary_witness_before_segwit_activation()
269260
self.test_witness_tx_relay_before_segwit_activation()
270261
self.test_standardness_v0()
@@ -292,7 +283,6 @@ def run_test(self):
292283
self.test_signature_version_1()
293284
self.test_non_standard_witness_blinding()
294285
self.test_non_standard_witness()
295-
self.test_upgrade_after_activation()
296286
self.test_witness_sigops()
297287
self.test_superfluous_witness()
298288
self.test_wtxid_relay()
@@ -482,11 +472,6 @@ def test_v0_outputs_arent_spendable(self):
482472
witness, and so can't be spent before segwit activation (the point at which
483473
blocks are permitted to contain witnesses)."""
484474

485-
# node2 doesn't need to be connected for this test.
486-
# (If it's connected, node0 may propagate an invalid block to it over
487-
# compact blocks and the nodes would have inconsistent tips.)
488-
self.disconnect_nodes(0, 2)
489-
490475
# Create two outputs, a p2wsh and p2sh-p2wsh
491476
witness_program = CScript([OP_TRUE])
492477
script_pubkey = script_to_p2wsh_script(witness_program)
@@ -544,37 +529,9 @@ def test_v0_outputs_arent_spendable(self):
544529
# TODO: support multiple acceptable reject reasons.
545530
test_witness_block(self.nodes[0], self.test_node, block, accepted=False, with_witness=False)
546531

547-
self.connect_nodes(0, 2)
548-
549532
self.utxo.pop(0)
550533
self.utxo.append(UTXO(txid, 2, value))
551534

552-
@subtest # type: ignore
553-
def test_getblocktemplate_before_lockin(self):
554-
txid = int(self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1), 16)
555-
556-
for node in [self.nodes[0], self.nodes[2]]:
557-
gbt_results = node.getblocktemplate({"rules": ["segwit"]})
558-
if node == self.nodes[2]:
559-
# If this is a non-segwit node, we should not get a witness
560-
# commitment.
561-
assert 'default_witness_commitment' not in gbt_results
562-
else:
563-
# For segwit-aware nodes, check the witness
564-
# commitment is correct.
565-
assert 'default_witness_commitment' in gbt_results
566-
witness_commitment = gbt_results['default_witness_commitment']
567-
568-
# Check that default_witness_commitment is present.
569-
witness_root = CBlock.get_merkle_root([ser_uint256(0),
570-
ser_uint256(txid)])
571-
script = get_witness_script(witness_root, 0)
572-
assert_equal(witness_commitment, script.hex())
573-
574-
# Clear out the mempool
575-
self.nodes[0].generate(1)
576-
self.sync_blocks()
577-
578535
@subtest # type: ignore
579536
def test_witness_tx_relay_before_segwit_activation(self):
580537

@@ -1927,39 +1884,6 @@ def test_non_standard_witness(self):
19271884

19281885
self.utxo.pop(0)
19291886

1930-
@subtest # type: ignore
1931-
def test_upgrade_after_activation(self):
1932-
"""Test the behavior of starting up a segwit-aware node after the softfork has activated."""
1933-
1934-
# All nodes are caught up and node 2 is a pre-segwit node that will soon upgrade.
1935-
for n in range(2):
1936-
assert_equal(self.nodes[n].getblockcount(), self.nodes[2].getblockcount())
1937-
assert softfork_active(self.nodes[n], "segwit")
1938-
assert SEGWIT_HEIGHT < self.nodes[2].getblockcount()
1939-
assert 'segwit' not in self.nodes[2].getblockchaininfo()['softforks']
1940-
1941-
# Restarting node 2 should result in a shutdown because the blockchain consists of
1942-
# insufficiently validated blocks per segwit consensus rules.
1943-
self.stop_node(2)
1944-
self.nodes[2].assert_start_raises_init_error(
1945-
extra_args=[f"-segwitheight={SEGWIT_HEIGHT}"],
1946-
expected_msg=f": Witness data for blocks after height {SEGWIT_HEIGHT} requires validation. Please restart with -reindex..\nPlease restart with -reindex or -reindex-chainstate to recover.",
1947-
)
1948-
1949-
# As directed, the user restarts the node with -reindex
1950-
self.start_node(2, extra_args=["-reindex", f"-segwitheight={SEGWIT_HEIGHT}"])
1951-
1952-
# With the segwit consensus rules, the node is able to validate only up to SEGWIT_HEIGHT - 1
1953-
assert_equal(self.nodes[2].getblockcount(), SEGWIT_HEIGHT - 1)
1954-
self.connect_nodes(0, 2)
1955-
1956-
# We reconnect more than 100 blocks, give it plenty of time
1957-
# sync_blocks() also verifies the best block hash is the same for all nodes
1958-
self.sync_blocks(timeout=240)
1959-
1960-
# The upgraded node should now have segwit activated
1961-
assert softfork_active(self.nodes[2], "segwit")
1962-
19631887
@subtest # type: ignore
19641888
def test_witness_sigops(self):
19651889
"""Test sigop counting is correct inside witnesses."""

0 commit comments

Comments
 (0)