@@ -135,12 +135,21 @@ def add_witness_commitment(block, nonce=0):
135135 block .rehash ()
136136
137137
138- def script_BIP34_coinbase_height (height ):
138+ def script_BIP34_coinbase_height (height , pad = False ):
139139 if height <= 16 :
140140 res = CScriptOp .encode_op_n (height )
141141 # Append dummy to increase scriptSig size to 2 (see bad-cb-length consensus rule)
142- return CScript ([res , OP_0 ])
143- return CScript ([CScriptNum (height )])
142+ script_array = [res , OP_0 ]
143+ if pad :
144+ script_array .append (OP_0 )
145+ script_array .append (OP_0 )
146+ return CScript (script_array )
147+
148+ script_array = [CScriptNum (height )]
149+ if pad :
150+ script_array .append (OP_0 )
151+ script_array .append (OP_0 )
152+ return CScript (script_array )
144153
145154
146155def create_coinbase (height , pubkey = None , * , script_pubkey = None , extra_output_script = None , fees = 0 , nValue = 50 , retarget_period = REGTEST_RETARGET_PERIOD ):
@@ -171,6 +180,11 @@ def create_coinbase(height, pubkey=None, *, script_pubkey=None, extra_output_scr
171180 coinbaseoutput2 .nValue = 0
172181 coinbaseoutput2 .scriptPubKey = extra_output_script
173182 coinbase .vout .append (coinbaseoutput2 )
183+
184+ # Add padding if coinbase is exactly 64 bytes long to comply with XEP consensus rules
185+ if len (coinbase .serialize_without_witness ()) == 64 :
186+ coinbase .vin = [CTxIn (COutPoint (0 , 0xffffffff ), script_BIP34_coinbase_height (height , True ), SEQUENCE_FINAL )]
187+
174188 coinbase .calc_sha256 ()
175189 return coinbase
176190
0 commit comments