config: add config to toggle light client for bitcoin only

This commit is contained in:
Olaoluwa Osuntokun 2017-05-18 11:48:59 -07:00
parent 7283befe2a
commit 42a50224aa
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -10,6 +10,7 @@ import (
"sort" "sort"
"strconv" "strconv"
"strings" "strings"
"time"
flags "github.com/btcsuite/go-flags" flags "github.com/btcsuite/go-flags"
"github.com/lightningnetwork/lnd/brontide" "github.com/lightningnetwork/lnd/brontide"
@ -57,6 +58,15 @@ type chainConfig struct {
SimNet bool `long:"simnet" description:"Use the simulation test network"` SimNet bool `long:"simnet" description:"Use the simulation test network"`
} }
type spvConfig struct {
Active bool `long:"active" destination:"If SPV mode should be active or not."`
AddPeers []string `short:"a" long:"addpeer" description:"Add a peer to connect with at startup"`
ConnectPeers []string `long:"connect" description:"Connect only to the specified peers at startup"`
MaxPeers int `long:"maxpeers" description:"Max number of inbound and outbound peers"`
BanDuration time.Duration `long:"banduration" description:"How long to ban misbehaving peers. Valid time units are {s, m, h}. Minimum 1 second"`
BanThreshold uint32 `long:"banthreshold" description:"Maximum allowed ban score before disconnecting and banning misbehaving peers."`
}
// config defines the configuration options for lnd. // config defines the configuration options for lnd.
// //
// See loadConfig for further details regarding the configuration // See loadConfig for further details regarding the configuration
@ -82,6 +92,8 @@ type config struct {
Litecoin *chainConfig `group:"Litecoin" namespace:"litecoin"` Litecoin *chainConfig `group:"Litecoin" namespace:"litecoin"`
Bitcoin *chainConfig `group:"Bitcoin" namespace:"bitcoin"` Bitcoin *chainConfig `group:"Bitcoin" namespace:"bitcoin"`
SpvMode *spvConfig `group:"SPV" namespace:"spv"`
} }
// loadConfig initializes and parses the config using a config file and command // loadConfig initializes and parses the config using a config file and command
@ -166,6 +178,15 @@ func loadConfig() (*config, error) {
return nil, err return nil, err
} }
// The SPV mode implemented currently doesn't support Litecoin, so the
// two modes are incompatible.
if cfg.SpvMode.Active && cfg.Litecoin.Active {
str := "%s: The light client mode currently supported does " +
"not yet support execution on the Litecoin network"
err := fmt.Errorf(str, funcName)
return nil, err
}
if cfg.Litecoin.Active { if cfg.Litecoin.Active {
if cfg.Litecoin.SimNet { if cfg.Litecoin.SimNet {
str := "%s: simnet mode for litecoin not currently supported" str := "%s: simnet mode for litecoin not currently supported"
@ -180,14 +201,17 @@ func loadConfig() (*config, error) {
applyLitecoinParams(&paramCopy) applyLitecoinParams(&paramCopy)
activeNetParams = paramCopy activeNetParams = paramCopy
// Attempt to parse out the RPC credentials for the litecoin if !cfg.SpvMode.Active {
// chain if the information wasn't specified // Attempt to parse out the RPC credentials for the
// litecoin chain if the information wasn't specified
err := parseRPCParams(cfg.Litecoin, litecoinChain, funcName) err := parseRPCParams(cfg.Litecoin, litecoinChain, funcName)
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC credentials for "+ err := fmt.Errorf("unable to load RPC credentials for "+
"ltcd: %v", err) "ltcd: %v", err)
return nil, err return nil, err
} }
}
cfg.Litecoin.ChainDir = filepath.Join(cfg.DataDir, litecoinChain.String()) cfg.Litecoin.ChainDir = filepath.Join(cfg.DataDir, litecoinChain.String())
// Finally we'll register the litecoin chain as our current // Finally we'll register the litecoin chain as our current
@ -213,14 +237,17 @@ func loadConfig() (*config, error) {
return nil, err return nil, err
} }
// If needed, we'll attempt to automatically configure the RPC if !cfg.SpvMode.Active {
// control plan for the target btcd node. // If needed, we'll attempt to automatically configure
// the RPC control plan for the target btcd node.
err := parseRPCParams(cfg.Bitcoin, bitcoinChain, funcName) err := parseRPCParams(cfg.Bitcoin, bitcoinChain, funcName)
if err != nil { if err != nil {
err := fmt.Errorf("unable to load RPC credentials for "+ err := fmt.Errorf("unable to load RPC credentials for "+
"btcd: %v", err) "btcd: %v", err)
return nil, err return nil, err
} }
}
cfg.Bitcoin.ChainDir = filepath.Join(cfg.DataDir, bitcoinChain.String()) cfg.Bitcoin.ChainDir = filepath.Join(cfg.DataDir, bitcoinChain.String())
// Finally we'll register the bitcoin chain as our current // Finally we'll register the bitcoin chain as our current