lnd+config: add flags for mainnet

This commit is contained in:
Olaoluwa Osuntokun 2018-03-15 02:04:17 -07:00
parent c00880144c
commit 71a5fac9c7
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 85 additions and 10 deletions

View File

@ -82,6 +82,7 @@ type chainConfig struct {
Node string `long:"node" description:"The blockchain interface to use." choice:"btcd" choice:"bitcoind" choice:"neutrino" choice:"ltcd" choice:"litecoind"` Node string `long:"node" description:"The blockchain interface to use." choice:"btcd" choice:"bitcoind" choice:"neutrino" choice:"ltcd" choice:"litecoind"`
MainNet bool `long:"mainnet" description:"Use the main network"`
TestNet3 bool `long:"testnet" description:"Use the test network"` TestNet3 bool `long:"testnet" description:"Use the test network"`
SimNet bool `long:"simnet" description:"Use the simulation test network"` SimNet bool `long:"simnet" description:"Use the simulation test network"`
RegTest bool `long:"regtest" description:"Use the regression test network"` RegTest bool `long:"regtest" description:"Use the regression test network"`
@ -405,13 +406,41 @@ func loadConfig() (*config, error) {
minTimeLockDelta) minTimeLockDelta)
} }
// Multiple networks can't be selected simultaneously. Count
// number of network flags passed; assign active network params
// while we're at it.
numNets := 0
var ltcParams litecoinNetParams
if cfg.Litecoin.MainNet {
numNets++
ltcParams = litecoinMainNetParams
}
if cfg.Litecoin.TestNet3 {
numNets++
ltcParams = litecoinTestNetParams
}
if numNets > 1 {
str := "%s: The mainnet, testnet, and simnet params " +
"can't be used together -- choose one of the " +
"three"
err := fmt.Errorf(str, funcName)
return nil, err
}
// The target network must be provided, otherwise, we won't
// know how to initialize the daemon.
if numNets == 0 {
str := "%s: either --litecoin.mainnet, or " +
"litecoin.testnet must be specified"
err := fmt.Errorf(str, funcName)
return nil, err
}
// The litecoin chain is the current active chain. However // The litecoin chain is the current active chain. However
// throughout the codebase we required chaincfg.Params. So as a // throughout the codebase we required chaincfg.Params. So as a
// temporary hack, we'll mutate the default net params for // temporary hack, we'll mutate the default net params for
// bitcoin with the litecoin specific information. // bitcoin with the litecoin specific information.
paramCopy := bitcoinTestNetParams applyLitecoinParams(&activeNetParams, &ltcParams)
applyLitecoinParams(&paramCopy)
activeNetParams = paramCopy
switch cfg.Litecoin.Node { switch cfg.Litecoin.Node {
case "ltcd": case "ltcd":
@ -453,6 +482,10 @@ func loadConfig() (*config, error) {
// number of network flags passed; assign active network params // number of network flags passed; assign active network params
// while we're at it. // while we're at it.
numNets := 0 numNets := 0
if cfg.Bitcoin.MainNet {
numNets++
activeNetParams = bitcoinMainNetParams
}
if cfg.Bitcoin.TestNet3 { if cfg.Bitcoin.TestNet3 {
numNets++ numNets++
activeNetParams = bitcoinTestNetParams activeNetParams = bitcoinTestNetParams
@ -466,8 +499,26 @@ func loadConfig() (*config, error) {
activeNetParams = bitcoinSimNetParams activeNetParams = bitcoinSimNetParams
} }
if numNets > 1 { if numNets > 1 {
str := "%s: The testnet, segnet, and simnet params can't be " + str := "%s: The mainnet, testnet, regtest, and " +
"used together -- choose one of the three" "simnet params can't be used together -- " +
"choose one of the four"
err := fmt.Errorf(str, funcName)
return nil, err
}
// The target network must be provided, otherwise, we won't
// know how to initialize the daemon.
if numNets == 0 {
str := "%s: either --bitcoin.mainnet, or " +
"bitcoin.testnet, bitcoin.simnet, or bitcoin.regtest " +
"must be specified"
err := fmt.Errorf(str, funcName)
return nil, err
}
if cfg.Bitcoin.Node == "neutrino" && cfg.Bitcoin.MainNet {
str := "%s: neutrino isn't yet supported for " +
"bitcoin's mainnet"
err := fmt.Errorf(str, funcName) err := fmt.Errorf(str, funcName)
return nil, err return nil, err
} }
@ -479,8 +530,9 @@ func loadConfig() (*config, error) {
switch cfg.Bitcoin.Node { switch cfg.Bitcoin.Node {
case "btcd": case "btcd":
err := parseRPCParams(cfg.Bitcoin, cfg.BtcdMode, err := parseRPCParams(
bitcoinChain, funcName) cfg.Bitcoin, cfg.BtcdMode, bitcoinChain, funcName,
)
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC "+ err := fmt.Errorf("unable to load RPC "+
"credentials for btcd: %v", err) "credentials for btcd: %v", err)
@ -491,8 +543,10 @@ func loadConfig() (*config, error) {
return nil, fmt.Errorf("%s: bitcoind does not "+ return nil, fmt.Errorf("%s: bitcoind does not "+
"support simnet", funcName) "support simnet", funcName)
} }
err := parseRPCParams(cfg.Bitcoin, cfg.BitcoindMode,
bitcoinChain, funcName) err := parseRPCParams(
cfg.Bitcoin, cfg.BitcoindMode, bitcoinChain, funcName,
)
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC "+ err := fmt.Errorf("unable to load RPC "+
"credentials for bitcoind: %v", err) "credentials for bitcoind: %v", err)
@ -997,7 +1051,7 @@ func normalizeAddresses(addrs []string, defaultPort string) []string {
// interface. // interface.
func enforceSafeAuthentication(addrs []string, macaroonsActive bool) error { func enforceSafeAuthentication(addrs []string, macaroonsActive bool) error {
isLoopback := func(addr string) bool { isLoopback := func(addr string) bool {
loopBackAddrs := []string{"localhost", "127.0.0.1"} loopBackAddrs := []string{"localhost", "127.0.0.1", "[::1]"}
for _, loopback := range loopBackAddrs { for _, loopback := range loopBackAddrs {
if strings.Contains(addr, loopback) { if strings.Contains(addr, loopback) {
return true return true

21
lnd.go
View File

@ -23,6 +23,7 @@ import (
"path/filepath" "path/filepath"
"runtime" "runtime"
"runtime/pprof" "runtime/pprof"
"strings"
"sync" "sync"
"time" "time"
@ -105,6 +106,26 @@ func lndMain() error {
// Show version at startup. // Show version at startup.
ltndLog.Infof("Version %s", version()) ltndLog.Infof("Version %s", version())
var network string
switch {
case cfg.Bitcoin.TestNet3 || cfg.Litecoin.TestNet3:
network = "testnet"
case cfg.Bitcoin.MainNet || cfg.Litecoin.MainNet:
network = "mainnet"
case cfg.Bitcoin.SimNet:
network = "simmnet"
case cfg.Bitcoin.RegTest:
network = "regtest"
}
ltndLog.Infof("Active chain: %v (network=%v)",
strings.Title(registeredChains.PrimaryChain().String()),
network,
)
// Enable http profiling server if requested. // Enable http profiling server if requested.
if cfg.Profile != "" { if cfg.Profile != "" {
go func() { go func() {