@@ -120,6 +120,12 @@ type Config struct {
120
120
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."`
121
121
ConfigFile string `long:"configfile" description:"Path to LiT's configuration file."`
122
122
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
+
123
129
Remote * RemoteConfig `group:"Remote mode options (use when lnd-mode=remote)" namespace:"remote"`
124
130
125
131
Faraday * faraday.Config `group:"Faraday options" namespace:"faraday"`
@@ -131,11 +137,6 @@ type Config struct {
131
137
// faradayRpcConfig is a subset of faraday's full configuration that is
132
138
// passed into faraday's RPC server.
133
139
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
139
140
}
140
141
141
142
// RemoteConfig holds the configuration parameters that are needed when running
@@ -156,8 +157,6 @@ type RemoteConfig struct {
156
157
// RemoteDaemonConfig holds the configuration parameters that are needed to
157
158
// connect to a remote daemon like lnd for example.
158
159
type RemoteDaemonConfig struct {
159
- Network string `long:"network" description:"The network the remote daemon runs on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet"`
160
-
161
160
// RPCServer is host:port that the remote daemon's RPC server is
162
161
// listening on.
163
162
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,
183
182
// remote section of the lnd config.
184
183
if c .LndMode == ModeRemote {
185
184
return c .Remote .Lnd .RPCServer ,
186
- lndclient .Network (c .network ),
185
+ lndclient .Network (c .Network ),
187
186
lncfg .CleanAndExpandPath (c .Remote .Lnd .TLSCertPath ),
188
187
lncfg .CleanAndExpandPath (c .Remote .Lnd .MacaroonPath )
189
188
}
@@ -206,7 +205,7 @@ func (c *Config) lndConnectParams() (string, lndclient.Network, string,
206
205
)
207
206
}
208
207
209
- return lndDialAddr , lndclient .Network (c .network ),
208
+ return lndDialAddr , lndclient .Network (c .Network ),
210
209
c .Lnd .TLSCertPath , c .Lnd .AdminMacPath
211
210
}
212
211
@@ -222,12 +221,12 @@ func defaultConfig() *Config {
222
221
LitMaxLogFiles : defaultMaxLogFiles ,
223
222
LitMaxLogFileSize : defaultMaxLogFileSize ,
224
223
Lnd : & RemoteDaemonConfig {
225
- Network : defaultNetwork ,
226
224
RPCServer : defaultRemoteLndRpcServer ,
227
225
MacaroonPath : lndDefaultConfig .AdminMacPath ,
228
226
TLSCertPath : lndDefaultConfig .TLSCertPath ,
229
227
},
230
228
},
229
+ Network : defaultNetwork ,
231
230
LndMode : defaultLndMode ,
232
231
Lnd : & lndDefaultConfig ,
233
232
LitDir : defaultLitDir ,
@@ -317,17 +316,14 @@ func loadAndValidateConfig() (*Config, error) {
317
316
// (like the log or lnd options) as they will be taken from lnd's config
318
317
// struct. Others we want to force to be the same as lnd so the user
319
318
// doesn't have to set them manually, like the network for example.
320
- cfg .Loop .Network = cfg .network
321
319
if err := loopd .Validate (cfg .Loop ); err != nil {
322
320
return nil , err
323
321
}
324
322
325
- cfg .Pool .Network = cfg .network
326
323
if err := pool .Validate (cfg .Pool ); err != nil {
327
324
return nil , err
328
325
}
329
326
330
- cfg .Faraday .Network = cfg .network
331
327
if err := faraday .ValidateConfig (cfg .Faraday ); err != nil {
332
328
return nil , err
333
329
}
@@ -389,6 +385,12 @@ func loadConfigFile(preCfg *Config, usageMessage string) (*Config, error) {
389
385
return nil , err
390
386
}
391
387
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
+
392
394
switch cfg .LndMode {
393
395
// In case we are running lnd in-process, let's make sure its
394
396
// configuration is fully valid. This also sets up the main logger that
@@ -399,10 +401,6 @@ func loadConfigFile(preCfg *Config, usageMessage string) (*Config, error) {
399
401
if err != nil {
400
402
return nil , err
401
403
}
402
- cfg .network , err = getNetwork (cfg .Lnd .Bitcoin )
403
- if err != nil {
404
- return nil , err
405
- }
406
404
407
405
// In remote lnd mode we skip the validation of the lnd configuration
408
406
// 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) {
431
429
func validateRemoteModeConfig (cfg * Config ) error {
432
430
r := cfg .Remote
433
431
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
-
441
432
// When referring to the default lnd configuration later on, let's make
442
433
// sure we use the actual default values and not the lndDefaultConfig
443
434
// variable which could've been overwritten by the user. Otherwise this
@@ -448,12 +439,12 @@ func validateRemoteModeConfig(cfg *Config) error {
448
439
// need to adjust the default macaroon directory so the user can only
449
440
// specify --network=testnet for example if everything else is using
450
441
// the defaults.
451
- if r . Lnd .Network != defaultNetwork &&
442
+ if cfg .Network != defaultNetwork &&
452
443
r .Lnd .MacaroonPath == defaultLndCfg .AdminMacPath {
453
444
454
445
r .Lnd .MacaroonPath = filepath .Join (
455
446
defaultLndCfg .DataDir , defaultLndChainSubDir ,
456
- defaultLndChain , r . Lnd .Network ,
447
+ defaultLndChain , cfg .Network ,
457
448
path .Base (defaultLndCfg .AdminMacPath ),
458
449
)
459
450
}
@@ -486,7 +477,7 @@ func validateRemoteModeConfig(cfg *Config) error {
486
477
logWriter := build .NewRotatingLogWriter ()
487
478
cfg .Lnd .LogWriter = logWriter
488
479
err := logWriter .InitLogRotator (
489
- filepath .Join (r .LitLogDir , cfg .network , defaultLogFilename ),
480
+ filepath .Join (r .LitLogDir , cfg .Network , defaultLogFilename ),
490
481
r .LitMaxLogFileSize , r .LitMaxLogFiles ,
491
482
)
492
483
if err != nil {
@@ -499,23 +490,33 @@ func validateRemoteModeConfig(cfg *Config) error {
499
490
)
500
491
}
501
492
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
506
500
507
- case cfg . TestNet3 :
508
- return "testnet" , nil
501
+ case "testnet" , "testnet3" :
502
+ cfg . Lnd . Bitcoin . TestNet3 = true
509
503
510
- case cfg . RegTest :
511
- return "regtest" , nil
504
+ case "regtest" :
505
+ cfg . Lnd . Bitcoin . RegTest = true
512
506
513
- case cfg . SimNet :
514
- return "simnet" , nil
507
+ case "simnet" :
508
+ cfg . Lnd . Bitcoin . SimNet = true
515
509
516
510
default :
517
- return "" , fmt .Errorf ("no network selected" )
511
+ return fmt .Errorf ("unknown network: %v" , cfg . Network )
518
512
}
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
519
520
}
520
521
521
522
// readUIPassword reads the password for the UI either from the command line
0 commit comments