25
25
MSG_WITNESS_FLAG ,
26
26
NODE_NETWORK ,
27
27
NODE_WITNESS ,
28
- msg_block ,
28
+ msg_no_witness_block ,
29
29
msg_getdata ,
30
30
msg_headers ,
31
31
msg_inv ,
32
32
msg_tx ,
33
- msg_witness_block ,
33
+ msg_block ,
34
34
msg_witness_tx ,
35
35
ser_uint256 ,
36
36
ser_vector ,
@@ -111,7 +111,7 @@ def get_virtual_size(witness_block):
111
111
112
112
Virtual size is base + witness/4."""
113
113
base_size = len (witness_block .serialize (with_witness = False ))
114
- total_size = len (witness_block .serialize (with_witness = True ))
114
+ total_size = len (witness_block .serialize ())
115
115
# the "+3" is so we round up
116
116
vsize = int ((3 * base_size + total_size + 3 ) / 4 )
117
117
return vsize
@@ -134,7 +134,7 @@ def test_witness_block(node, p2p, block, accepted, with_witness=True, reason=Non
134
134
- use the getbestblockhash rpc to check for acceptance."""
135
135
reason = [reason ] if reason else []
136
136
with node .assert_debug_log (expected_msgs = reason ):
137
- p2p .send_message (msg_witness_block (block ) if with_witness else msg_block (block ))
137
+ p2p .send_message (msg_block (block ) if with_witness else msg_no_witness_block (block ))
138
138
p2p .sync_with_ping ()
139
139
assert_equal (node .getbestblockhash () == block .hash , accepted )
140
140
@@ -298,7 +298,7 @@ def test_non_witness_transaction(self):
298
298
299
299
block = self .build_next_block (version = 1 )
300
300
block .solve ()
301
- self .test_node .send_message (msg_block (block ))
301
+ self .test_node .send_message (msg_no_witness_block (block ))
302
302
self .test_node .sync_with_ping () # make sure the block was processed
303
303
txid = block .vtx [0 ].sha256
304
304
@@ -345,7 +345,7 @@ def test_unnecessary_witness_before_segwit_activation(self):
345
345
346
346
# But it should not be permanently marked bad...
347
347
# Resend without witness information.
348
- self .test_node .send_message (msg_block (block ))
348
+ self .test_node .send_message (msg_no_witness_block (block ))
349
349
self .test_node .sync_with_ping ()
350
350
assert_equal (self .nodes [0 ].getbestblockhash (), block .hash )
351
351
@@ -403,7 +403,7 @@ def test_block_relay(self):
403
403
block_hash = int (block_hash , 16 )
404
404
block = self .test_node .request_block (block_hash , 2 )
405
405
wit_block = self .test_node .request_block (block_hash , 2 | MSG_WITNESS_FLAG )
406
- assert_equal (block .serialize (True ), wit_block .serialize (True ))
406
+ assert_equal (block .serialize (), wit_block .serialize ())
407
407
assert_equal (block .serialize (), hex_str_to_bytes (rpc_block ))
408
408
else :
409
409
# After activation, witness blocks and non-witness blocks should
@@ -419,15 +419,15 @@ def test_block_relay(self):
419
419
rpc_block = self .nodes [0 ].getblock (block .hash , False )
420
420
non_wit_block = self .test_node .request_block (block .sha256 , 2 )
421
421
wit_block = self .test_node .request_block (block .sha256 , 2 | MSG_WITNESS_FLAG )
422
- assert_equal (wit_block .serialize (True ), hex_str_to_bytes (rpc_block ))
422
+ assert_equal (wit_block .serialize (), hex_str_to_bytes (rpc_block ))
423
423
assert_equal (wit_block .serialize (False ), non_wit_block .serialize ())
424
- assert_equal (wit_block .serialize (True ), block .serialize (True ))
424
+ assert_equal (wit_block .serialize (), block .serialize ())
425
425
426
426
# Test size, vsize, weight
427
427
rpc_details = self .nodes [0 ].getblock (block .hash , True )
428
- assert_equal (rpc_details ["size" ], len (block .serialize (True )))
428
+ assert_equal (rpc_details ["size" ], len (block .serialize ()))
429
429
assert_equal (rpc_details ["strippedsize" ], len (block .serialize (False )))
430
- weight = 3 * len (block .serialize (False )) + len (block .serialize (True ))
430
+ weight = 3 * len (block .serialize (False )) + len (block .serialize ())
431
431
assert_equal (rpc_details ["weight" ], weight )
432
432
433
433
# Upgraded node should not ask for blocks from unupgraded
@@ -791,7 +791,7 @@ def test_witness_commitments(self):
791
791
block .solve ()
792
792
793
793
# Test the test -- witness serialization should be different
794
- assert msg_witness_block (block ).serialize () != msg_block (block ).serialize ()
794
+ assert msg_block (block ).serialize () != msg_no_witness_block (block ).serialize ()
795
795
796
796
# This empty block should be valid.
797
797
test_witness_block (self .nodes [0 ], self .test_node , block , accepted = True )
@@ -884,13 +884,13 @@ def test_block_malleability(self):
884
884
885
885
# We can't send over the p2p network, because this is too big to relay
886
886
# TODO: repeat this test with a block that can be relayed
887
- self .nodes [0 ].submitblock (block .serialize (True ).hex ())
887
+ self .nodes [0 ].submitblock (block .serialize ().hex ())
888
888
889
889
assert self .nodes [0 ].getbestblockhash () != block .hash
890
890
891
891
block .vtx [0 ].wit .vtxinwit [0 ].scriptWitness .stack .pop ()
892
892
assert get_virtual_size (block ) < MAX_BLOCK_BASE_SIZE
893
- self .nodes [0 ].submitblock (block .serialize (True ).hex ())
893
+ self .nodes [0 ].submitblock (block .serialize ().hex ())
894
894
895
895
assert self .nodes [0 ].getbestblockhash () == block .hash
896
896
@@ -969,7 +969,7 @@ def test_witness_block_size(self):
969
969
assert_equal (vsize , MAX_BLOCK_BASE_SIZE + 1 )
970
970
# Make sure that our test case would exceed the old max-network-message
971
971
# limit
972
- assert len (block .serialize (True )) > 2 * 1024 * 1024
972
+ assert len (block .serialize ()) > 2 * 1024 * 1024
973
973
974
974
test_witness_block (self .nodes [0 ], self .test_node , block , accepted = False )
975
975
@@ -997,14 +997,14 @@ def test_submit_block(self):
997
997
add_witness_commitment (block , nonce = 1 )
998
998
block .vtx [0 ].wit = CTxWitness () # drop the nonce
999
999
block .solve ()
1000
- self .nodes [0 ].submitblock (block .serialize (True ).hex ())
1000
+ self .nodes [0 ].submitblock (block .serialize ().hex ())
1001
1001
assert self .nodes [0 ].getbestblockhash () != block .hash
1002
1002
1003
1003
# Now redo commitment with the standard nonce, but let bitcoind fill it in.
1004
1004
add_witness_commitment (block , nonce = 0 )
1005
1005
block .vtx [0 ].wit = CTxWitness ()
1006
1006
block .solve ()
1007
- self .nodes [0 ].submitblock (block .serialize (True ).hex ())
1007
+ self .nodes [0 ].submitblock (block .serialize ().hex ())
1008
1008
assert_equal (self .nodes [0 ].getbestblockhash (), block .hash )
1009
1009
1010
1010
# This time, add a tx with non-empty witness, but don't supply
@@ -1019,7 +1019,7 @@ def test_submit_block(self):
1019
1019
block_2 .vtx [0 ].vout .pop ()
1020
1020
block_2 .vtx [0 ].wit = CTxWitness ()
1021
1021
1022
- self .nodes [0 ].submitblock (block_2 .serialize (True ).hex ())
1022
+ self .nodes [0 ].submitblock (block_2 .serialize ().hex ())
1023
1023
# Tip should not advance!
1024
1024
assert self .nodes [0 ].getbestblockhash () != block_2 .hash
1025
1025
0 commit comments