Skip to content

Commit

Permalink
wire+chaincfg: add signet params
Browse files Browse the repository at this point in the history
This commit adds all necessary chain parameters for connecting to the
public signet network.
Reference: bitcoin/bitcoin#18267
  • Loading branch information
guggero committed Feb 14, 2021
1 parent dff2198 commit 2f74446
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 0 deletions.
28 changes: 28 additions & 0 deletions chaincfg/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,31 @@ var simNetGenesisBlock = wire.MsgBlock{
},
Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
}

// sigNetGenesisHash is the hash of the first block in the block chain for the
// signet test network.
var sigNetGenesisHash = chainhash.Hash([chainhash.HashSize]byte{ // Make go vet happy.
0xf6, 0x1e, 0xee, 0x3b, 0x63, 0xa3, 0x80, 0xa4,
0x77, 0xa0, 0x63, 0xaf, 0x32, 0xb2, 0xbb, 0xc9,
0x7c, 0x9f, 0xf9, 0xf0, 0x1f, 0x2c, 0x42, 0x25,
0xe9, 0x73, 0x98, 0x81, 0x08, 0x00, 0x00, 0x00,
})

// sigNetGenesisMerkleRoot is the hash of the first transaction in the genesis
// block for the signet test network. It is the same as the merkle root for
// the main network.
var sigNetGenesisMerkleRoot = genesisMerkleRoot

// sigNetGenesisBlock defines the genesis block of the block chain which serves
// as the public transaction ledger for the signet test network.
var sigNetGenesisBlock = wire.MsgBlock{
Header: wire.BlockHeader{
Version: 1,
PrevBlock: chainhash.Hash{}, // 0000000000000000000000000000000000000000000000000000000000000000
MerkleRoot: sigNetGenesisMerkleRoot, // 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b
Timestamp: time.Unix(1598918400, 0), // 2020-09-01 00:00:00 +0000 UTC
Bits: 0x1e0377ae, // 503543726 [000000377ae00000000000000000000000000000000000000000000000000000]
Nonce: 52613770,
},
Transactions: []*wire.MsgTx{&genesisCoinbaseTx},
}
94 changes: 94 additions & 0 deletions chaincfg/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ var (
// simNetPowLimit is the highest proof of work value a Bitcoin block
// can have for the simulation test network. It is the value 2^255 - 1.
simNetPowLimit = new(big.Int).Sub(new(big.Int).Lsh(bigOne, 255), bigOne)

// sigNetPowLimit is the highest proof of work value a bitcoin block can
// have for the signet test network. It is the value
sigNetPowLimit = new(big.Int).Lsh(new(big.Int).SetInt64(0x0377ae), 212)
)

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

// DeploymentTaproot defines the rule change deployment ID for the
// Taproot (+Schnorr) soft-fork package. The taproot package includes
// the deployment of BIPS 340, 341 and 342.
DeploymentTaproot

// NOTE: DefinedDeployments must always come last since it is used to
// determine how many defined deployments there currently are.

Expand Down Expand Up @@ -578,6 +587,91 @@ var SimNetParams = Params{
HDCoinType: 115, // ASCII for s
}

// SigNetParams defines the network parameters for the signet Bitcoin network.
// Not to be confused with the regression test network, this network is
// sometimes simply called "signet".
var SigNetParams = Params{
Name: "signet",
Net: wire.SigNet,
DefaultPort: "38333",
DNSSeeds: []DNSSeed{
{"178.128.221.177", false},
{"2a01:7c8:d005:390::5", false},
{"v7ajjeirttkbnt32wpy3c6w3emwnfr3fkla7hpxcfokr3ysd3kqtzmqd.onion:38333", false},
},

// Chain parameters
GenesisBlock: &sigNetGenesisBlock,
GenesisHash: &sigNetGenesisHash,
PowLimit: sigNetPowLimit,
PowLimitBits: 0x1e0377ae,
BIP0034Height: 1,
BIP0065Height: 1,
BIP0066Height: 1,
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: nil,

// Consensus rule change deployments.
//
// The miner confirmation window is defined as:
// target proof of work timespan / target proof of work spacing
RuleChangeActivationThreshold: 1512, // 95% of 2016
MinerConfirmationWindow: 2016,
Deployments: [DefinedDeployments]ConsensusDeployment{
DeploymentTestDummy: {
BitNumber: 28,
StartTime: 1199145601, // January 1, 2008 UTC
ExpireTime: 1230767999, // December 31, 2008 UTC
},
DeploymentCSV: {
BitNumber: 0,
StartTime: 0, // Always available for vote
ExpireTime: math.MaxInt64, // Never expires
},
DeploymentSegwit: {
BitNumber: 1,
StartTime: 0, // Always available for vote
ExpireTime: math.MaxInt64, // Never expires.
},
DeploymentTaproot: {
BitNumber: 2,
StartTime: 0, // Always available for vote
ExpireTime: math.MaxInt64, // Never expires.
},
},

// 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,
}

var (
// ErrDuplicateNet describes an error where the parameters for a Bitcoin
// network could not be set due to the network already being a standard
Expand Down
13 changes: 13 additions & 0 deletions chaincfg/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package chaincfg

import (
"bytes"
"encoding/hex"
"math/big"
"testing"
)

Expand Down Expand Up @@ -84,3 +86,14 @@ func TestInvalidHDKeyID(t *testing.T) {
t.Fatalf("HDPrivateKeyToPublicKeyID: want err ErrUnknownHDKeyID, got %v", err)
}
}

func TestSigNetPowLimit(t *testing.T) {
sigNetPowLimitHex, _ := hex.DecodeString(
"000000377ae00000000000000000000000000000000000000000000000000000",
)
powLimit := new(big.Int).SetBytes(sigNetPowLimitHex)
if sigNetPowLimit.Cmp(powLimit) != 0 {
t.Fatalf("Signet PoW limit bits (%s) not equal to big int (%s)",
sigNetPowLimit.Text(16), powLimit.Text(16))
}
}
4 changes: 4 additions & 0 deletions wire/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ const (

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

// SigNet represents the signet test network.
SigNet BitcoinNet = 0xe7ca5a64
)

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

// String returns the BitcoinNet in human-readable form.
Expand Down

0 comments on commit 2f74446

Please sign in to comment.