Skip to content

Commit ebed910

Browse files
committed
qa: Correct coinbase input script height.
1 parent cae2d43 commit ebed910

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

test/functional/test_framework/blocktools.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"""Utilities for manipulating blocks and transactions."""
66

77
from test_framework.mininode import *
8-
from test_framework.script import CScript, OP_TRUE, OP_CHECKSIG
8+
from test_framework.script import CScript, CScriptNum, CScriptOp, OP_TRUE, OP_CHECKSIG, OP_1
99

1010

1111
# Create a block (with regtest difficulty)
@@ -42,19 +42,23 @@ def serialize_script_num(value):
4242
r[-1] |= 0x80
4343
return r
4444

45-
def cbase_scriptsig(height):
46-
return ser_string(serialize_script_num(height))
47-
4845
def cbase_value(height):
4946
#return ((50 * COIN) >> int(height/150))
5047
return (250 * COIN)
5148

49+
def script_BIP34_coinbase_height(height):
50+
if height <= 16:
51+
res = CScriptOp.encode_op_n(height)
52+
# Append dummy to increase scriptSig size above 2 (see bad-cb-length consensus rule)
53+
return CScript([res, OP_1])
54+
return CScript([CScriptNum(height)])
55+
5256
# Create a coinbase transaction, assuming no miner fees.
5357
# If pubkey is passed in, the coinbase output will be a P2PK output;
5458
# otherwise an anyone-can-spend output.
5559
def create_coinbase(height, pubkey = None):
5660
coinbase = CTransaction()
57-
coinbase.vin = [CTxIn(NullOutPoint, cbase_scriptsig(height), 0xffffffff)]
61+
coinbase.vin = [CTxIn(NullOutPoint, script_BIP34_coinbase_height(height), 0xffffffff)]
5862
coinbaseoutput = CTxOut()
5963
coinbaseoutput.nValue = cbase_value(height)
6064
if (pubkey != None):
@@ -100,7 +104,7 @@ def get_legacy_sigopcount_tx(tx, fAccurate=True):
100104
### PIVX specific blocktools ###
101105
def create_coinbase_pos(height):
102106
coinbase = CTransaction()
103-
coinbase.vin = [CTxIn(NullOutPoint, cbase_scriptsig(height), 0xffffffff)]
107+
coinbase.vin = [CTxIn(NullOutPoint, script_BIP34_coinbase_height(height), 0xffffffff)]
104108
coinbase.vout = [CTxOut(0, b"")]
105109
coinbase.calc_sha256()
106110
return coinbase

0 commit comments

Comments
 (0)