diff --git a/config.go b/config.go index c44f3a83..7124fe92 100644 --- a/config.go +++ b/config.go @@ -8,6 +8,7 @@ import ( "bufio" "crypto/rand" "encoding/base64" + "encoding/hex" "errors" "fmt" "io" @@ -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"` @@ -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) @@ -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) diff --git a/doc.go b/doc.go index 8b9b9977..70d0d9e4 100644 --- a/doc.go +++ b/doc.go @@ -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) diff --git a/params.go b/params.go index 14eeff07..b4d1453d 100644 --- a/params.go +++ b/params.go @@ -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