@@ -120,6 +120,12 @@ type Config struct {
120120 LitDir string `long:"lit-dir" description:"The main directory where LiT looks for its configuration file. If LiT is running in 'remote' lnd mode, this is also the directory where the TLS certificates and log files are stored by default."`
121121 ConfigFile string `long:"configfile" description:"Path to LiT's configuration file."`
122122
123+ // Network is the Bitcoin network we're running on. This will be parsed
124+ // before the configuration is loaded and will set the correct flag on
125+ // `lnd.bitcoin.mainnet|testnet|regtest` and also for the other daemons.
126+ // That way only one global network flag is needed.
127+ Network string `long:"network" description:"The network the UI and all its components run on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet"`
128+
123129 Remote * RemoteConfig `group:"Remote mode options (use when lnd-mode=remote)" namespace:"remote"`
124130
125131 Faraday * faraday.Config `group:"Faraday options" namespace:"faraday"`
@@ -131,11 +137,6 @@ type Config struct {
131137 // faradayRpcConfig is a subset of faraday's full configuration that is
132138 // passed into faraday's RPC server.
133139 faradayRpcConfig * frdrpc.Config
134-
135- // network is the Bitcoin network we're running on. This will be parsed
136- // and set when the configuration is loaded, either from
137- // `lnd.bitcoin.mainnet|testnet|regtest` or from `remote.lnd.network`.
138- network string
139140}
140141
141142// RemoteConfig holds the configuration parameters that are needed when running
@@ -156,8 +157,6 @@ type RemoteConfig struct {
156157// RemoteDaemonConfig holds the configuration parameters that are needed to
157158// connect to a remote daemon like lnd for example.
158159type RemoteDaemonConfig struct {
159- Network string `long:"network" description:"The network the remote daemon runs on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet"`
160-
161160 // RPCServer is host:port that the remote daemon's RPC server is
162161 // listening on.
163162 RPCServer string `long:"rpcserver" description:"The host:port that the remote daemon is listening for RPC connections on."`
@@ -183,7 +182,7 @@ func (c *Config) lndConnectParams() (string, lndclient.Network, string,
183182 // remote section of the lnd config.
184183 if c .LndMode == ModeRemote {
185184 return c .Remote .Lnd .RPCServer ,
186- lndclient .Network (c .network ),
185+ lndclient .Network (c .Network ),
187186 lncfg .CleanAndExpandPath (c .Remote .Lnd .TLSCertPath ),
188187 lncfg .CleanAndExpandPath (c .Remote .Lnd .MacaroonPath )
189188 }
@@ -206,7 +205,7 @@ func (c *Config) lndConnectParams() (string, lndclient.Network, string,
206205 )
207206 }
208207
209- return lndDialAddr , lndclient .Network (c .network ),
208+ return lndDialAddr , lndclient .Network (c .Network ),
210209 c .Lnd .TLSCertPath , c .Lnd .AdminMacPath
211210}
212211
@@ -222,12 +221,12 @@ func defaultConfig() *Config {
222221 LitMaxLogFiles : defaultMaxLogFiles ,
223222 LitMaxLogFileSize : defaultMaxLogFileSize ,
224223 Lnd : & RemoteDaemonConfig {
225- Network : defaultNetwork ,
226224 RPCServer : defaultRemoteLndRpcServer ,
227225 MacaroonPath : lndDefaultConfig .AdminMacPath ,
228226 TLSCertPath : lndDefaultConfig .TLSCertPath ,
229227 },
230228 },
229+ Network : defaultNetwork ,
231230 LndMode : defaultLndMode ,
232231 Lnd : & lndDefaultConfig ,
233232 LitDir : defaultLitDir ,
@@ -317,17 +316,14 @@ func loadAndValidateConfig() (*Config, error) {
317316 // (like the log or lnd options) as they will be taken from lnd's config
318317 // struct. Others we want to force to be the same as lnd so the user
319318 // doesn't have to set them manually, like the network for example.
320- cfg .Loop .Network = cfg .network
321319 if err := loopd .Validate (cfg .Loop ); err != nil {
322320 return nil , err
323321 }
324322
325- cfg .Pool .Network = cfg .network
326323 if err := pool .Validate (cfg .Pool ); err != nil {
327324 return nil , err
328325 }
329326
330- cfg .Faraday .Network = cfg .network
331327 if err := faraday .ValidateConfig (cfg .Faraday ); err != nil {
332328 return nil , err
333329 }
@@ -389,6 +385,12 @@ func loadConfigFile(preCfg *Config, usageMessage string) (*Config, error) {
389385 return nil , err
390386 }
391387
388+ // Parse the global/top-level network and propagate it to all sub config
389+ // structs.
390+ if err := setNetwork (cfg ); err != nil {
391+ return nil , err
392+ }
393+
392394 switch cfg .LndMode {
393395 // In case we are running lnd in-process, let's make sure its
394396 // configuration is fully valid. This also sets up the main logger that
@@ -399,10 +401,6 @@ func loadConfigFile(preCfg *Config, usageMessage string) (*Config, error) {
399401 if err != nil {
400402 return nil , err
401403 }
402- cfg .network , err = getNetwork (cfg .Lnd .Bitcoin )
403- if err != nil {
404- return nil , err
405- }
406404
407405 // In remote lnd mode we skip the validation of the lnd configuration
408406 // and instead just set up the logging (that would be done by lnd if it
@@ -431,13 +429,6 @@ func loadConfigFile(preCfg *Config, usageMessage string) (*Config, error) {
431429func validateRemoteModeConfig (cfg * Config ) error {
432430 r := cfg .Remote
433431
434- // Validate the network as in the remote node it's provided as a string
435- // instead of a series of boolean flags.
436- if _ , err := lndclient .Network (r .Lnd .Network ).ChainParams (); err != nil {
437- return fmt .Errorf ("error validating lnd remote network: %v" , err )
438- }
439- cfg .network = r .Lnd .Network
440-
441432 // When referring to the default lnd configuration later on, let's make
442433 // sure we use the actual default values and not the lndDefaultConfig
443434 // variable which could've been overwritten by the user. Otherwise this
@@ -448,12 +439,12 @@ func validateRemoteModeConfig(cfg *Config) error {
448439 // need to adjust the default macaroon directory so the user can only
449440 // specify --network=testnet for example if everything else is using
450441 // the defaults.
451- if r . Lnd .Network != defaultNetwork &&
442+ if cfg .Network != defaultNetwork &&
452443 r .Lnd .MacaroonPath == defaultLndCfg .AdminMacPath {
453444
454445 r .Lnd .MacaroonPath = filepath .Join (
455446 defaultLndCfg .DataDir , defaultLndChainSubDir ,
456- defaultLndChain , r . Lnd .Network ,
447+ defaultLndChain , cfg .Network ,
457448 path .Base (defaultLndCfg .AdminMacPath ),
458449 )
459450 }
@@ -486,7 +477,7 @@ func validateRemoteModeConfig(cfg *Config) error {
486477 logWriter := build .NewRotatingLogWriter ()
487478 cfg .Lnd .LogWriter = logWriter
488479 err := logWriter .InitLogRotator (
489- filepath .Join (r .LitLogDir , cfg .network , defaultLogFilename ),
480+ filepath .Join (r .LitLogDir , cfg .Network , defaultLogFilename ),
490481 r .LitMaxLogFileSize , r .LitMaxLogFiles ,
491482 )
492483 if err != nil {
@@ -499,23 +490,33 @@ func validateRemoteModeConfig(cfg *Config) error {
499490 )
500491}
501492
502- func getNetwork (cfg * lncfg.Chain ) (string , error ) {
503- switch {
504- case cfg .MainNet :
505- return "mainnet" , nil
493+ // setNetwork parses the top-level network config options and, if valid, sets it
494+ // in all sub configuration structs. We also set the Bitcoin chain to active by
495+ // default as LiT won't support Litecoin in the foreseeable future.
496+ func setNetwork (cfg * Config ) error {
497+ switch cfg .Network {
498+ case "mainnet" :
499+ cfg .Lnd .Bitcoin .MainNet = true
506500
507- case cfg . TestNet3 :
508- return "testnet" , nil
501+ case "testnet" , "testnet3" :
502+ cfg . Lnd . Bitcoin . TestNet3 = true
509503
510- case cfg . RegTest :
511- return "regtest" , nil
504+ case "regtest" :
505+ cfg . Lnd . Bitcoin . RegTest = true
512506
513- case cfg . SimNet :
514- return "simnet" , nil
507+ case "simnet" :
508+ cfg . Lnd . Bitcoin . SimNet = true
515509
516510 default :
517- return "" , fmt .Errorf ("no network selected" )
511+ return fmt .Errorf ("unknown network: %v" , cfg . Network )
518512 }
513+
514+ cfg .Lnd .Bitcoin .Active = true
515+ cfg .Faraday .Network = cfg .Network
516+ cfg .Loop .Network = cfg .Network
517+ cfg .Pool .Network = cfg .Network
518+
519+ return nil
519520}
520521
521522// readUIPassword reads the password for the UI either from the command line
0 commit comments