Skip to content

Commit a5f52cf

Browse files
committed
qa: timelock coinbase transactions created in functional tests
1 parent 80e6ad9 commit a5f52cf

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

test/functional/feature_block.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,7 @@ def run_test(self):
831831
self.log.info("Reject a block with a transaction with a duplicate hash of a previous transaction (BIP30)")
832832
self.move_tip(60)
833833
b61 = self.next_block(61)
834+
b61.vtx[0].nLockTime = 0
834835
b61.vtx[0].vin[0].scriptSig = DUPLICATE_COINBASE_SCRIPT_SIG
835836
b61.vtx[0].rehash()
836837
b61 = self.update_block(61, [])
@@ -853,6 +854,7 @@ def run_test(self):
853854
b_spend_dup_cb = self.update_block('spend_dup_cb', [tx])
854855

855856
b_dup_2 = self.next_block('dup_2')
857+
b_dup_2.vtx[0].nLockTime = 0
856858
b_dup_2.vtx[0].vin[0].scriptSig = DUPLICATE_COINBASE_SCRIPT_SIG
857859
b_dup_2.vtx[0].rehash()
858860
b_dup_2 = self.update_block('dup_2', [])

test/functional/mining_mainnet.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
from test_framework.messages import (
3232
CBlock,
33+
SEQUENCE_FINAL,
3334
)
3435

3536
import json
@@ -61,6 +62,10 @@ def mine(self, height, prev_hash, blocks, node, fees=0):
6162
block.nBits = DIFF_1_N_BITS
6263
block.nNonce = blocks['nonces'][height - 1]
6364
block.vtx = [create_coinbase(height=height, script_pubkey=bytes.fromhex(COINBASE_SCRIPT_PUBKEY), retarget_period=2016)]
65+
# The alternate mainnet chain was mined with non-timelocked coinbase txs.
66+
block.vtx[0].nLockTime = 0
67+
block.vtx[0].vin[0].nSequence = SEQUENCE_FINAL
68+
block.vtx[0].rehash()
6469
block.hashMerkleRoot = block.calc_merkle_root()
6570
block.rehash()
6671
block_hex = block.serialize(with_witness=False).hex()

test/functional/test_framework/blocktools.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
tx_from_hex,
3030
uint256_from_compact,
3131
WITNESS_SCALE_FACTOR,
32+
MAX_SEQUENCE_NONFINAL,
3233
)
3334
from .script import (
3435
CScript,
@@ -151,7 +152,8 @@ def create_coinbase(height, pubkey=None, *, script_pubkey=None, extra_output_scr
151152
If extra_output_script is given, make a 0-value output to that
152153
script. This is useful to pad block weight/sigops as needed. """
153154
coinbase = CTransaction()
154-
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff), script_BIP34_coinbase_height(height), SEQUENCE_FINAL))
155+
coinbase.nLockTime = height - 1
156+
coinbase.vin.append(CTxIn(COutPoint(0, 0xffffffff), script_BIP34_coinbase_height(height), MAX_SEQUENCE_NONFINAL))
155157
coinbaseoutput = CTxOut()
156158
coinbaseoutput.nValue = nValue * COIN
157159
if nValue == 50:

0 commit comments

Comments
 (0)