Skip to content

Commit d9b1cad

Browse files
committed
wire+chaincfg: add signet params
This commit adds all necessary chain parameters for connecting to the public signet network. Reference: bitcoin/bitcoin#18267
1 parent dff2198 commit d9b1cad

File tree

4 files changed

+139
-0
lines changed

4 files changed

+139
-0
lines changed

chaincfg/genesis.go

+28
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,31 @@ var simNetGenesisBlock = wire.MsgBlock{
170170
},
171171
Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
172172
}
173+
174+
// sigNetGenesisHash is the hash of the first block in the block chain for the
175+
// signet test network.
176+
var sigNetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
177+
0xf6, 0x1e, 0xee, 0x3b, 0x63, 0xa3, 0x80, 0xa4,
178+
0x77, 0xa0, 0x63, 0xaf, 0x32, 0xb2, 0xbb, 0xc9,
179+
0x7c, 0x9f, 0xf9, 0xf0, 0x1f, 0x2c, 0x42, 0x25,
180+
0xe9, 0x73, 0x98, 0x81, 0x08, 0x00, 0x00, 0x00,
181+
})
182+
183+
// sigNetGenesisMerkleRoot is the hash of the first transaction in the genesis
184+
// block for the signet test network. It is the same as the merkle root for
185+
// the main network.
186+
var sigNetGenesisMerkleRoot = genesisMerkleRoot
187+
188+
// sigNetGenesisBlock defines the genesis block of the block chain which serves
189+
// as the public transaction ledger for the signet test network.
190+
var sigNetGenesisBlock = wire.MsgBlock{
191+
Header: wire.BlockHeader{
192+
Version: 1,
193+
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
194+
MerkleRoot: sigNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
195+
Timestamp: time.Unix(1598918400, 0), // 2020-09-01 00:00:00 +0000 UTC
196+
Bits: 0x1e0377ae, // 503543726 [000000377ae00000000000000000000000000000000000000000000000000000]
197+
Nonce: 52613770,
198+
},
199+
Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
200+
}

chaincfg/params.go

+94
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ var (
3838
// simNetPowLimit is the highest proof of work value a Bitcoin block
3939
// can have for the simulation test network. It is the value 2^255 - 1.
4040
simNetPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne)
41+
42+
// sigNetPowLimit is the highest proof of work value a bitcoin block can
43+
// have for the signet test network. It is the value 0x0377ae << 212.
44+
sigNetPowLimit = new(big.Int).Lsh(new(big.Int).SetInt64(0x0377ae), 212)
4145
)
4246

4347
// Checkpoint identifies a known good point in the block chain. Using
@@ -96,6 +100,11 @@ const (
96100
// includes the deployment of BIPS 141, 142, 144, 145, 147 and 173.
97101
DeploymentSegwit
98102

103+
// DeploymentTaproot defines the rule change deployment ID for the
104+
// Taproot (+Schnorr) soft-fork package. The taproot package includes
105+
// the deployment of BIPS 340, 341 and 342.
106+
DeploymentTaproot
107+
99108
// NOTE: DefinedDeployments must always come last since it is used to
100109
// determine how many defined deployments there currently are.
101110

@@ -578,6 +587,91 @@ var SimNetParams = Params{
578587
HDCoinType: 115, // ASCII for s
579588
}
580589

590+
// SigNetParams defines the network parameters for the signet Bitcoin network.
591+
// Not to be confused with the regression test network, this network is
592+
// sometimes simply called "signet".
593+
var SigNetParams = Params{
594+
Name: "signet",
595+
Net: wire.SigNet,
596+
DefaultPort: "38333",
597+
DNSSeeds: []DNSSeed{
598+
{"178.128.221.177", false},
599+
{"2a01:7c8:d005:390::5", false},
600+
{"v7ajjeirttkbnt32wpy3c6w3emwnfr3fkla7hpxcfokr3ysd3kqtzmqd.onion:38333", false},
601+
},
602+
603+
// Chain parameters
604+
GenesisBlock: &sigNetGenesisBlock,
605+
GenesisHash: &sigNetGenesisHash,
606+
PowLimit: sigNetPowLimit,
607+
PowLimitBits: 0x1e0377ae,
608+
BIP0034Height: 1,
609+
BIP0065Height: 1,
610+
BIP0066Height: 1,
611+
CoinbaseMaturity: 100,
612+
SubsidyReductionInterval: 210000,
613+
TargetTimespan: time.Hour * 24 * 14, // 14 days
614+
TargetTimePerBlock: time.Minute * 10, // 10 minutes
615+
RetargetAdjustmentFactor: 4, // 25% less, 400% more
616+
ReduceMinDifficulty: true,
617+
MinDiffReductionTime: time.Minute * 20, // TargetTimePerBlock * 2
618+
GenerateSupported: false,
619+
620+
// Checkpoints ordered from oldest to newest.
621+
Checkpoints: nil,
622+
623+
// Consensus rule change deployments.
624+
//
625+
// The miner confirmation window is defined as:
626+
// target proof of work timespan / target proof of work spacing
627+
RuleChangeActivationThreshold: 1512, // 95% of 2016
628+
MinerConfirmationWindow: 2016,
629+
Deployments: [DefinedDeployments]ConsensusDeployment{
630+
DeploymentTestDummy: {
631+
BitNumber: 28,
632+
StartTime: 1199145601, // January 1, 2008 UTC
633+
ExpireTime: 1230767999, // December 31, 2008 UTC
634+
},
635+
DeploymentCSV: {
636+
BitNumber: 0,
637+
StartTime: 0, // Always available for vote
638+
ExpireTime: math.MaxInt64, // Never expires
639+
},
640+
DeploymentSegwit: {
641+
BitNumber: 1,
642+
StartTime: 0, // Always available for vote
643+
ExpireTime: math.MaxInt64, // Never expires.
644+
},
645+
DeploymentTaproot: {
646+
BitNumber: 2,
647+
StartTime: 0, // Always available for vote
648+
ExpireTime: math.MaxInt64, // Never expires.
649+
},
650+
},
651+
652+
// Mempool parameters
653+
RelayNonStdTxs: true,
654+
655+
// Human-readable part for Bech32 encoded segwit addresses, as defined in
656+
// BIP 173.
657+
Bech32HRPSegwit: "tb", // always tb for test net
658+
659+
// Address encoding magics
660+
PubKeyHashAddrID: 0x6f, // starts with m or n
661+
ScriptHashAddrID: 0xc4, // starts with 2
662+
WitnessPubKeyHashAddrID: 0x03, // starts with QW
663+
WitnessScriptHashAddrID: 0x28, // starts with T7n
664+
PrivateKeyID: 0xef, // starts with 9 (uncompressed) or c (compressed)
665+
666+
// BIP32 hierarchical deterministic extended key magics
667+
HDPrivateKeyID: [4]byte{0x04, 0x35, 0x83, 0x94}, // starts with tprv
668+
HDPublicKeyID: [4]byte{0x04, 0x35, 0x87, 0xcf}, // starts with tpub
669+
670+
// BIP44 coin type used in the hierarchical deterministic path for
671+
// address generation.
672+
HDCoinType: 1,
673+
}
674+
581675
var (
582676
// ErrDuplicateNet describes an error where the parameters for a Bitcoin
583677
// network could not be set due to the network already being a standard

chaincfg/params_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package chaincfg
66

77
import (
88
"bytes"
9+
"encoding/hex"
10+
"math/big"
911
"testing"
1012
)
1113

@@ -84,3 +86,14 @@ func TestInvalidHDKeyID(t *testing.T) {
8486
t.Fatalf("HDPrivateKeyToPublicKeyID: want err ErrUnknownHDKeyID, got %v", err)
8587
}
8688
}
89+
90+
func TestSigNetPowLimit(t *testing.T) {
91+
sigNetPowLimitHex, _ := hex.DecodeString(
92+
"000000377ae00000000000000000000000000000000000000000000000000000",
93+
)
94+
powLimit := new(big.Int).SetBytes(sigNetPowLimitHex)
95+
if sigNetPowLimit.Cmp(powLimit) != 0 {
96+
t.Fatalf("Signet PoW limit bits (%s) not equal to big int (%s)",
97+
sigNetPowLimit.Text(16), powLimit.Text(16))
98+
}
99+
}

wire/protocol.go

+4
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ const (
157157

158158
// SimNet represents the simulation test network.
159159
SimNet BitcoinNet = 0x12141c16
160+
161+
// SigNet represents the signet test network.
162+
SigNet BitcoinNet = 0xe7ca5a64
160163
)
161164

162165
// bnStrings is a map of bitcoin networks back to their constant names for
@@ -166,6 +169,7 @@ var bnStrings = map[BitcoinNet]string{
166169
TestNet: "TestNet",
167170
TestNet3: "TestNet3",
168171
SimNet: "SimNet",
172+
SigNet: "SigNet",
169173
}
170174

171175
// String returns the BitcoinNet in human-readable form.

0 commit comments

Comments
 (0)