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
parent 73ecb5997b
commit 3eac153437
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
3 changed files with 56 additions and 5 deletions

View File

@ -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)

2
doc.go
View File

@ -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)

View File

@ -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