What changed, and why it matters
This commit fixes broken test code, not production code. After an earlier change made the regtest network follow stricter block-version and coinbase-height rules, several newer tests were still creating fake blocks the old way, causing them to fail. The patch updates those test helpers to produce valid regtest blocks and headers. There is no security issue in live software.
No security action required; treat as a normal test-maintenance commit. Reviewers may verify that CI passes after the change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit updates three Go test files (blockchain/accept_test.go, blockchain/process_test.go, netsync/manager_test.go) so their synthetic regtest blocks comply with BIP34/65/66 activation rules introduced by PR #2467. Changes include setting the genesis tip height to 0, raising block/header version from 1 to 4, and encoding the coinbase height with a minimal script integer plus a trailing OP_0 to satisfy length checks. These are purely test-fix changes; no consensus or networking production code is modified.
Changed components
blockchain/accept_test.goblockchain/process_test.gonetsync/manager_test.goInspect captured patch +18 / −8
diff --git a/blockchain/accept_test.go b/blockchain/accept_test.go
index 28a1ff6..ab96b42 100644
--- a/blockchain/accept_test.go
+++ b/blockchain/accept_test.go
@@ -26,6 +26,9 @@ func TestMaybeAcceptBlockReusesHeaderNode(t *testing.T) {
//
// genesis -> 1 -> 2 -> 3
tip := btcutil.NewBlock(params.GenesisBlock)
+ // Generated descendants must start at height 1 so the coinbase height
+ // encoding matches regtest's BIP34 rules.
+ tip.SetHeight(0)
_, _, err := addBlocks(3, chain, tip, []*testhelper.SpendableOut{})
if err != nil {
t.Fatalf("failed to build base chain: %v", err)
diff --git a/blockchain/process_test.go b/blockchain/process_test.go
index bc5de72..b24b4a0 100644
--- a/blockchain/process_test.go
+++ b/blockchain/process_test.go
@@ -36,7 +36,8 @@ func chainedHeaders(parent *wire.BlockHeader, chainParams *chaincfg.Params,
merkle := chainhash.HashH(randBytes[:])
header := wire.BlockHeader{
- Version: 1,
+ // Regtest enforces the BIP34/65/66 version floor from height 1.
+ Version: 4,
PrevBlock: tip.BlockHash(),
MerkleRoot: merkle,
Bits: chainParams.PowLimitBits,
diff --git a/netsync/manager_test.go b/netsync/manager_test.go
index 73eb0d5..b7e4b6b 100644
--- a/netsync/manager_test.go
+++ b/netsync/manager_test.go
@@ -557,11 +557,15 @@ func TestIsInIBDMode(t *testing.T) {
func createTestCoinbase(height int32, params *chaincfg.Params) *wire.MsgTx {
tx := wire.NewMsgTx(wire.TxVersion)
- // Push the height as data to guarantee unique txids per block.
- sigScript := []byte{
- 0x04,
- byte(height), byte(height >> 8),
- byte(height >> 16), byte(height >> 24),
+ // Encode the height as a minimally encoded script integer and add a trailing
+ // OP_0 so the script also satisfies the generic coinbase-length checks.
+ sigScript, err := txscript.NewScriptBuilder().
+ AddInt64(int64(height)).
+ AddInt64(0).
+ Script()
+ if err != nil {
+ panic(fmt.Sprintf("unable to encode coinbase height %d: %v",
+ height, err))
}
tx.AddTxIn(&wire.TxIn{
@@ -613,7 +617,8 @@ func generateTestBlocks(
merkleRoot := cb.TxHash()
header := wire.BlockHeader{
- Version: 1,
+ // Regtest enforces the BIP34/65/66 version floor from height 1.
+ Version: 4,
PrevBlock: *prevHash,
MerkleRoot: merkleRoot,
Timestamp: prevTime.Add(time.Minute),
@@ -1187,7 +1192,8 @@ func TestStartSyncChainCurrent(t *testing.T) {
// IsCurrent() returns true.
cb := createTestCoinbase(1, ¶ms)
header := wire.BlockHeader{
- Version: 1,
+ // Regtest enforces the BIP34/65/66 version floor from height 1.
+ Version: 4,
PrevBlock: *params.GenesisHash,
MerkleRoot: cb.TxHash(),
Timestamp: time.Now().Truncate(time.Second),
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.