Skip to content

Commit

Permalink
Add Bitcoin testnet4
Browse files Browse the repository at this point in the history
  • Loading branch information
nikicat committed May 23, 2024
1 parent b44cd57 commit 1362124
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
32 changes: 32 additions & 0 deletions chaincfg/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,38 @@ var testNet3GenesisBlock = wire.MsgBlock{
Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
}

// genesisMerkleRoot is the hash of the first transaction in the genesis block
// for the testnet4 network.
var testNet4GenesisMerkleRoot = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0x7b, 0x67, 0x66, 0xe6, 0x7e, 0x57, 0xd5, 0xcd,
0x0c, 0x40, 0xe4, 0x7e, 0x07, 0x80, 0xb8, 0xcb,
0x4c, 0x14, 0x41, 0x34, 0x23, 0x22, 0xe2, 0x1e,
0xe1, 0xae, 0x7a, 0xa7, 0x0a, 0xa0, 0xaa, 0x7a,
})

// testNet4GenesisBlock defines the genesis block of the block chain which
// serves as the public transaction ledger for the test network (version 3).
var testNet4GenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
MerkleRoot: testNet4GenesisMerkleRoot, // 7aa0a7ae1e223414cb807e40cd57e667b718e42aaf9306db9102fe28912b7b4e
Timestamp: time.Unix(1714777860, 0), // ???
Bits: 0x1d00ffff, // 486604799 [00000000ffff0000000000000000000000000000000000000000000000000000]
Nonce: 0x17780CBB, // 393743547
},
Transactions: []*wire.MsgTx{&genesisCoinbaseTx}, // FIXME: tx is different
}

// testNet4GenesisHash is the hash of the first block in the block chain for the
// test network (version 4).
var testNet4GenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0xe5, 0xae, 0x2a, 0x72, 0xa7, 0x5a, 0x25, 0xe2,
0xee, 0xde, 0x3d, 0x53, 0xc5, 0xbc, 0xbb, 0xfb,
0xaf, 0xba, 0x2b, 0xf2, 0x4f, 0x84, 0xa8, 0xda,
0x0d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
})

// simNetGenesisHash is the hash of the first block in the block chain for the
// simulation test network.
var simNetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
Expand Down
72 changes: 72 additions & 0 deletions chaincfg/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/binary"
"encoding/hex"
"errors"
"math"
"math/big"
"strings"
"time"
Expand Down Expand Up @@ -671,6 +672,77 @@ var TestNet3Params = Params{
HDCoinType: 1,
}

// TestNet4Params defines the network parameters for the test Bitcoin network
// (version 4). Not to be confused with the regression test network, this
// network is sometimes simply called "testnet4".
var TestNet4Params = Params{
Name: "testnet4",
Net: wire.TestNet4,
DefaultPort: "48333",
DNSSeeds: []DNSSeed{
{"seed.testnet4.bitcoin.sprovoost.nl.", true},
{"seed.testnet4.wiz.biz.", true},
},

// Chain parameters
GenesisBlock: &testNet4GenesisBlock,
GenesisHash: &testNet4GenesisHash,
PowLimit: testNet3PowLimit,
PowLimitBits: 0x1d00ffff,
CoinbaseMaturity: 100,
SubsidyReductionInterval: 210000,
TargetTimespan: time.Hour * 24 * 14, // 14 days
TargetTimePerBlock: time.Minute * 10, // 10 minutes
RetargetAdjustmentFactor: 4, // 25% less, 400% more
ReduceMinDifficulty: true,
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
GenerateSupported: false,

// Checkpoints ordered from oldest to newest.
Checkpoints: []Checkpoint{},

// Consensus rule change deployments.
//
// The miner confirmation window is defined as:
// target proof of work timespan / target proof of work spacing
RuleChangeActivationThreshold: 1512, // 75% of MinerConfirmationWindow
MinerConfirmationWindow: 2016,
Deployments: [DefinedDeployments]ConsensusDeployment{
DeploymentTestDummy: {
BitNumber: 28,
DeploymentStarter: NewMedianTimeDeploymentStarter(time.Unix(math.MaxInt64, 0)), // Never active
DeploymentEnder: &MedianTimeDeploymentEnder{},
},
DeploymentTaproot: {
BitNumber: 2,
DeploymentStarter: &MedianTimeDeploymentStarter{}, // Always active
DeploymentEnder: &MedianTimeDeploymentEnder{},
},
},

// Mempool parameters
RelayNonStdTxs: true,

// Human-readable part for Bech32 encoded segwit addresses, as defined in
// BIP 173.
Bech32HRPSegwit: "tb", // always tb for test net

// Address encoding magics
PubKeyHashAddrID: 0x6f, // starts with m or n
ScriptHashAddrID: 0xc4, // starts with 2
WitnessPubKeyHashAddrID: 0x03, // starts with QW
WitnessScriptHashAddrID: 0x28, // starts with T7n
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)

// BIP32 hierarchical deterministic extended key magics
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub

// BIP44 coin type used in the hierarchical deterministic path for
// address generation.
HDCoinType: 1,
}

// SimNetParams defines the network parameters for the simulation test Bitcoin
// network. This network is similar to the normal test network except it is
// intended for private use within a group of individuals doing simulation
Expand Down
3 changes: 3 additions & 0 deletions wire/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ const (
// TestNet3 represents the test network (version 3).
TestNet3 BitcoinNet = 0x0709110b

// TestNet4 represents the test network (version 4).
TestNet4 BitcoinNet = 0x283f161c

// SimNet represents the simulation test network.
SimNet BitcoinNet = 0x12141c16
)
Expand Down

0 comments on commit 1362124

Please sign in to comment.