config+params: add signet config option

This commit adds the --signet command line flag (or signet config
option) for starting btcd in signet mode.
This commit is contained in:
Oliver Gugger 2021-02-14 15:49:11 +01:00 committed by Roy Lee
parent d17e62ae3e
commit a0a92386e6
3 changed files with 56 additions and 5 deletions

View file

@ -8,6 +8,7 @@ import (
"bufio" "bufio"
"crypto/rand" "crypto/rand"
"encoding/base64" "encoding/base64"
"encoding/hex"
"errors" "errors"
"fmt" "fmt"
"io" "io"
@ -159,6 +160,9 @@ type config struct {
RPCUser string `short:"u" long:"rpcuser" description:"Username for RPC connections"` 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"` 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"` 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"` 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."` 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"` 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. // Load additional config from file.
var configFileError error var configFileError error
parser := newConfigParser(&cfg, &serviceOpts, flags.Default) parser := newConfigParser(&cfg, &serviceOpts, flags.Default)
if !(preCfg.RegressionTest || preCfg.SimNet) || preCfg.ConfigFile != if !(preCfg.RegressionTest || preCfg.SimNet || preCfg.SigNet) ||
defaultConfigFile { preCfg.ConfigFile != defaultConfigFile {
if _, err := os.Stat(preCfg.ConfigFile); os.IsNotExist(err) { if _, err := os.Stat(preCfg.ConfigFile); os.IsNotExist(err) {
err := createDefaultConfigFile(preCfg.ConfigFile) err := createDefaultConfigFile(preCfg.ConfigFile)
@ -550,9 +554,49 @@ func loadConfig() (*config, []string, error) {
activeNetParams = &simNetParams activeNetParams = &simNetParams
cfg.DisableDNSSeed = true 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 { if numNets > 1 {
str := "%s: The testnet, regtest, segnet, and simnet params " + str := "%s: The testnet, regtest, segnet, signet and simnet " +
"can't be used together -- choose one of the four" "params can't be used together -- choose one of the " +
"five"
err := fmt.Errorf(str, funcName) err := fmt.Errorf(str, funcName)
fmt.Fprintln(os.Stderr, err) fmt.Fprintln(os.Stderr, err)
fmt.Fprintln(os.Stderr, usageMessage) fmt.Fprintln(os.Stderr, usageMessage)

2
doc.go
View file

@ -72,7 +72,7 @@ Application Options:
minute (default: 15) minute (default: 15)
--listen= Add an interface/port to listen for connections --listen= Add an interface/port to listen for connections
(default all interfaces port: 8333, testnet: (default all interfaces port: 8333, testnet:
18333) 18333, signet: 38333)
--logdir= Directory to log output --logdir= Directory to log output
--maxorphantx= Max number of orphan transactions to keep in --maxorphantx= Max number of orphan transactions to keep in
memory (default: 100) memory (default: 100)

View file

@ -55,6 +55,13 @@ var simNetParams = params{
rpcPort: "18556", 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 // 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 // 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 // data and log directory "testnet", which does not match the Name field of the