Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wire+chaincfg: add signet params #1692

Merged
merged 4 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
config+params: add signet config option
This commit adds the --signet command line flag (or signet config
option) for starting btcd in signet mode.
  • Loading branch information
guggero committed Apr 22, 2021
commit 3eac153437340fc90ec8a17d3e0fc6c64bc979b3
52 changes: 48 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"crypto/rand"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -159,6 +160,9 @@ type config struct {
RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"`
SigCacheMaxSize uint `long:"sigcachemaxsize" description:"The maximum number of entries in the signature verification cache"`
SimNet bool `long:"simnet" description:"Use the simulation test network"`
SigNet bool `long:"signet" description:"Use the signet test network"`
SigNetChallenge string `long:"signetchallenge" description:"Connect to a custom signet network defined by this challenge instead of using the global default signet test network -- Can be specified multiple times"`
SigNetSeedNode []string `long:"signetseednode" description:"Specify a seed node for the signet network instead of using the global default signet network seed nodes"`
TestNet3 bool `long:"testnet" description:"Use the test network"`
TorIsolation bool `long:"torisolation" description:"Enable Tor stream isolation by randomizing user credentials for each connection."`
TrickleInterval time.Duration `long:"trickleinterval" description:"Minimum time between attempts to send new inventory to a connected peer"`
Expand Down Expand Up @@ -475,8 +479,8 @@ func loadConfig() (*config, []string, error) {
// Load additional config from file.
var configFileError error
parser := newConfigParser(&cfg, &serviceOpts, flags.Default)
if !(preCfg.RegressionTest || preCfg.SimNet) || preCfg.ConfigFile !=
defaultConfigFile {
if !(preCfg.RegressionTest || preCfg.SimNet || preCfg.SigNet) ||
preCfg.ConfigFile != defaultConfigFile {

if _, err := os.Stat(preCfg.ConfigFile); os.IsNotExist(err) {
err := createDefaultConfigFile(preCfg.ConfigFile)
Expand Down Expand Up @@ -550,9 +554,49 @@ func loadConfig() (*config, []string, error) {
activeNetParams = &simNetParams
cfg.DisableDNSSeed = true
}
if cfg.SigNet {
numNets++
activeNetParams = &sigNetParams

// Let the user overwrite the default signet parameters. The
// challenge defines the actual signet network to join and the
// seed nodes are needed for network discovery.
sigNetChallenge := chaincfg.DefaultSignetChallenge
sigNetSeeds := chaincfg.DefaultSignetDNSSeeds
if cfg.SigNetChallenge != "" {
challenge, err := hex.DecodeString(cfg.SigNetChallenge)
if err != nil {
str := "%s: Invalid signet challenge, hex " +
"decode failed: %v"
err := fmt.Errorf(str, funcName, err)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
return nil, nil, err
}
sigNetChallenge = challenge
}

if len(cfg.SigNetSeedNode) > 0 {
sigNetSeeds = make(
[]chaincfg.DNSSeed, len(cfg.SigNetSeedNode),
)
for idx, seed := range cfg.SigNetSeedNode {
sigNetSeeds[idx] = chaincfg.DNSSeed{
Host: seed,
HasFiltering: false,
}
}
}

chainParams := chaincfg.CustomSignetParams(
sigNetChallenge, sigNetSeeds,
)
activeNetParams.Params = &chainParams
}
if numNets > 1 {
str := "%s: The testnet, regtest, segnet, and simnet params " +
"can't be used together -- choose one of the four"
str := "%s: The testnet, regtest, segnet, signet and simnet " +
"params can't be used together -- choose one of the " +
"five"
err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage)
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Application Options:
minute (default: 15)
--listen= Add an interface/port to listen for connections
(default all interfaces port: 8333, testnet:
18333)
18333, signet: 38333)
--logdir= Directory to log output
--maxorphantx= Max number of orphan transactions to keep in
memory (default: 100)
Expand Down
7 changes: 7 additions & 0 deletions params.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ var simNetParams = params{
rpcPort: "18556",
}

// sigNetParams contains parameters specific to the Signet network
// (wire.SigNet).
var sigNetParams = params{
Params: &chaincfg.SigNetParams,
rpcPort: "38332",
}

// netName returns the name used when referring to a bitcoin network. At the
// time of writing, btcd currently places blocks for testnet version 3 in the
// data and log directory "testnet", which does not match the Name field of the
Expand Down