Skip to content

Commit faa4698

Browse files
author
MarcoFalke
committed
test: Remove version argument from build_next_block in p2p_segwit test
The block version does not have any effect on the segwit consensus rules or block relay logic. Same for feature_dersig.
1 parent fa086ef commit faa4698

File tree

2 files changed

+10
-21
lines changed

2 files changed

+10
-21
lines changed

test/functional/feature_dersig.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def run_test(self):
8383
tip = self.nodes[0].getbestblockhash()
8484
block_time = self.nodes[0].getblockheader(tip)['mediantime'] + 1
8585
block = create_block(int(tip, 16), create_coinbase(DERSIG_HEIGHT - 1), block_time)
86-
block.nVersion = 2
8786
block.vtx.append(spendtx)
8887
block.hashMerkleRoot = block.calc_merkle_root()
8988
block.rehash()
@@ -110,7 +109,7 @@ def run_test(self):
110109
peer.sync_with_ping()
111110

112111
self.log.info("Test that transactions with non-DER signatures cannot appear in a block")
113-
block.nVersion = 3
112+
block.nVersion = 4
114113

115114
spendtx = self.create_tx(self.coinbase_txids[1])
116115
unDERify(spendtx)
@@ -139,7 +138,7 @@ def run_test(self):
139138
assert_equal(int(self.nodes[0].getbestblockhash(), 16), tip)
140139
peer.sync_with_ping()
141140

142-
self.log.info("Test that a version 3 block with a DERSIG-compliant transaction is accepted")
141+
self.log.info("Test that a block with a DERSIG-compliant transaction is accepted")
143142
block.vtx[1] = self.create_tx(self.coinbase_txids[1])
144143
block.hashMerkleRoot = block.calc_merkle_root()
145144
block.rehash()

test/functional/p2p_segwit.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@
8383
assert_raises_rpc_error,
8484
)
8585

86-
# The versionbit bit used to signal activation of SegWit
87-
VB_WITNESS_BIT = 1
88-
VB_TOP_BITS = 0x20000000
89-
9086
MAX_SIGOP_COST = 80000
9187

9288
SEGWIT_HEIGHT = 120
@@ -206,13 +202,13 @@ def skip_test_if_missing_module(self):
206202

207203
# Helper functions
208204

209-
def build_next_block(self, version=4):
205+
def build_next_block(self):
210206
"""Build a block on top of node0's tip."""
211207
tip = self.nodes[0].getbestblockhash()
212208
height = self.nodes[0].getblockcount() + 1
213209
block_time = self.nodes[0].getblockheader(tip)["mediantime"] + 1
214210
block = create_block(int(tip, 16), create_coinbase(height), block_time)
215-
block.nVersion = version
211+
block.nVersion = 4
216212
block.rehash()
217213
return block
218214

@@ -298,7 +294,7 @@ def test_non_witness_transaction(self):
298294
# Mine a block with an anyone-can-spend coinbase,
299295
# let it mature, then try to spend it.
300296

301-
block = self.build_next_block(version=1)
297+
block = self.build_next_block()
302298
block.solve()
303299
self.test_node.send_and_ping(msg_no_witness_block(block)) # make sure the block was processed
304300
txid = block.vtx[0].sha256
@@ -336,8 +332,8 @@ def test_unnecessary_witness_before_segwit_activation(self):
336332
tx.rehash()
337333
assert tx.sha256 != tx.calc_sha256(with_witness=True)
338334

339-
# Construct a segwit-signaling block that includes the transaction.
340-
block = self.build_next_block(version=(VB_TOP_BITS | (1 << VB_WITNESS_BIT)))
335+
# Construct a block that includes the transaction.
336+
block = self.build_next_block()
341337
self.update_witness_block_with_transactions(block, [tx])
342338
# Sending witness data before activation is not allowed (anti-spam
343339
# rule).
@@ -364,27 +360,21 @@ def test_block_relay(self):
364360
# test_node has set NODE_WITNESS, so all getdata requests should be for
365361
# witness blocks.
366362
# Test announcing a block via inv results in a getdata, and that
367-
# announcing a version 4 or random VB block with a header results in a getdata
363+
# announcing a block with a header results in a getdata
368364
block1 = self.build_next_block()
369365
block1.solve()
370366

371367
self.test_node.announce_block_and_wait_for_getdata(block1, use_header=False)
372368
assert self.test_node.last_message["getdata"].inv[0].type == blocktype
373369
test_witness_block(self.nodes[0], self.test_node, block1, True)
374370

375-
block2 = self.build_next_block(version=4)
371+
block2 = self.build_next_block()
376372
block2.solve()
377373

378374
self.test_node.announce_block_and_wait_for_getdata(block2, use_header=True)
379375
assert self.test_node.last_message["getdata"].inv[0].type == blocktype
380376
test_witness_block(self.nodes[0], self.test_node, block2, True)
381377

382-
block3 = self.build_next_block(version=(VB_TOP_BITS | (1 << 15)))
383-
block3.solve()
384-
self.test_node.announce_block_and_wait_for_getdata(block3, use_header=True)
385-
assert self.test_node.last_message["getdata"].inv[0].type == blocktype
386-
test_witness_block(self.nodes[0], self.test_node, block3, True)
387-
388378
# Check that we can getdata for witness blocks or regular blocks,
389379
# and the right thing happens.
390380
if not self.segwit_active:
@@ -429,7 +419,7 @@ def test_block_relay(self):
429419
assert_equal(rpc_details["weight"], block.get_weight())
430420

431421
# Upgraded node should not ask for blocks from unupgraded
432-
block4 = self.build_next_block(version=4)
422+
block4 = self.build_next_block()
433423
block4.solve()
434424
self.old_node.getdataset = set()
435425

0 commit comments

Comments
 (0)