Skip to content

Commit a8a4da8

Browse files
committed
config: add remote modes for Faraday, Loop and Pool
As a first step towards making it possible to only run the UI itself and have all daemons run on another host (or in another process), we add new remote configuration options for each of the remaining daemons.
1 parent e84fd92 commit a8a4da8

File tree

1 file changed

+108
-22
lines changed

1 file changed

+108
-22
lines changed

config.go

Lines changed: 108 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ const (
3737
ModeIntegrated = "integrated"
3838
ModeRemote = "remote"
3939

40-
defaultLndMode = ModeRemote
40+
defaultLndMode = ModeRemote
41+
defaultFaradayMode = ModeIntegrated
42+
defaultLoopMode = ModeIntegrated
43+
defaultPoolMode = ModeIntegrated
4144

4245
defaultConfigFilename = "lit.conf"
4346

@@ -55,10 +58,13 @@ const (
5558
defaultTLSCertFilename = "tls.cert"
5659
defaultTLSKeyFilename = "tls.key"
5760

58-
defaultNetwork = "mainnet"
59-
defaultRemoteLndRpcServer = "localhost:10009"
60-
defaultLndChainSubDir = "chain"
61-
defaultLndChain = "bitcoin"
61+
defaultNetwork = "mainnet"
62+
defaultRemoteLndRpcServer = "localhost:10009"
63+
defaultRemoteFaradayRpcServer = "localhost:8465"
64+
defaultRemoteLoopRpcServer = "localhost:11010"
65+
defaultRemotePoolRpcServer = "localhost:12010"
66+
defaultLndChainSubDir = "chain"
67+
defaultLndChain = "bitcoin"
6268
)
6369

6470
var (
@@ -115,8 +121,6 @@ type Config struct {
115121
LetsEncryptDir string `long:"letsencryptdir" description:"The directory where the Let's Encrypt library will store its key and certificate."`
116122
LetsEncryptListen string `long:"letsencryptlisten" description:"The IP:port on which LiT will listen for Let's Encrypt challenges. Let's Encrypt will always try to contact on port 80. Often non-root processes are not allowed to bind to ports lower than 1024. This configuration option allows a different port to be used, but must be used in combination with port forwarding from port 80. This configuration can also be used to specify another IP address to listen on, for example an IPv6 address."`
117123

118-
LndMode string `long:"lnd-mode" description:"The mode to run lnd in, either 'integrated' (default) or 'remote'. 'integrated' means lnd is started alongside the UI and everything is stored in lnd's main data directory, configure everything by using the --lnd.* flags. 'remote' means the UI connects to an existing lnd node and acts as a proxy for gRPC calls to it. In the remote node LiT creates its own directory for log and configuration files, configure everything using the --remote.* flags." choice:"integrated" choice:"remote"`
119-
120124
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."`
121125
ConfigFile string `long:"configfile" description:"Path to LiT's configuration file."`
122126

@@ -128,15 +132,34 @@ type Config struct {
128132

129133
Remote *RemoteConfig `group:"Remote mode options (use when lnd-mode=remote)" namespace:"remote"`
130134

131-
Faraday *faraday.Config `group:"Faraday options" namespace:"faraday"`
132-
Loop *loopd.Config `group:"Loop options" namespace:"loop"`
133-
Pool *pool.Config `group:"pool" namespace:"pool"`
135+
// LndMode is the selected mode to run lnd in. The supported modes are
136+
// 'integrated' and 'remote'. We only use a string instead of a bool
137+
// here (and for all the other daemons) to make the CLI more user
138+
// friendly. Because then we can reference the explicit modes in the
139+
// help descriptions of the section headers. We'll parse the mode into
140+
// a bool for internal use for better code readability.
141+
LndMode string `long:"lnd-mode" description:"The mode to run lnd in, either 'integrated' (default) or 'remote'. 'integrated' means lnd is started alongside the UI and everything is stored in lnd's main data directory, configure everything by using the --lnd.* flags. 'remote' means the UI connects to an existing lnd node and acts as a proxy for gRPC calls to it. In the remote node LiT creates its own directory for log and configuration files, configure everything using the --remote.* flags." choice:"integrated" choice:"remote"`
142+
Lnd *lnd.Config `group:"Integrated lnd (use when lnd-mode=integrated)" namespace:"lnd"`
143+
144+
FaradayMode string `long:"faraday-mode" description:"The mode to run faraday in, either 'integrated' (default) or 'remote'. 'integrated' means faraday is started alongside the UI and everything is stored in faraday's main data directory, configure everything by using the --faraday.* flags. 'remote' means the UI connects to an existing faraday node and acts as a proxy for gRPC calls to it." choice:"integrated" choice:"remote"`
145+
Faraday *faraday.Config `group:"Integrated faraday options (use when faraday-mode=integrated)" namespace:"faraday"`
134146

135-
Lnd *lnd.Config `group:"Integrated lnd (use when lnd-mode=integrated)" namespace:"lnd"`
147+
LoopMode string `long:"loop-mode" description:"The mode to run loop in, either 'integrated' (default) or 'remote'. 'integrated' means loopd is started alongside the UI and everything is stored in loop's main data directory, configure everything by using the --loop.* flags. 'remote' means the UI connects to an existing loopd node and acts as a proxy for gRPC calls to it." choice:"integrated" choice:"remote"`
148+
Loop *loopd.Config `group:"Integrated loop options (use when loop-mode=integrated)" namespace:"loop"`
149+
150+
PoolMode string `long:"pool-mode" description:"The mode to run pool in, either 'integrated' (default) or 'remote'. 'integrated' means poold is started alongside the UI and everything is stored in pool's main data directory, configure everything by using the --pool.* flags. 'remote' means the UI connects to an existing poold node and acts as a proxy for gRPC calls to it." choice:"integrated" choice:"remote"`
151+
Pool *pool.Config `group:"Integrated pool options (use when pool-mode=integrated)" namespace:"pool"`
136152

137153
// faradayRpcConfig is a subset of faraday's full configuration that is
138154
// passed into faraday's RPC server.
139155
faradayRpcConfig *frdrpc.Config
156+
157+
// lndRemote is a convenience bool variable that is parsed from the
158+
// LndMode string variable on startup.
159+
lndRemote bool
160+
faradayRemote bool
161+
loopRemote bool
162+
poolRemote bool
140163
}
141164

142165
// RemoteConfig holds the configuration parameters that are needed when running
@@ -151,7 +174,10 @@ type RemoteConfig struct {
151174

152175
LitDebugLevel string `long:"lit-debuglevel" description:"For lnd remote mode only: Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,... to set the log level for individual subsystems."`
153176

154-
Lnd *RemoteDaemonConfig `group:"Remote lnd (use when lnd-mode=remote)" namespace:"lnd"`
177+
Lnd *RemoteDaemonConfig `group:"Remote lnd (use when lnd-mode=remote)" namespace:"lnd"`
178+
Faraday *RemoteDaemonConfig `group:"Remote faraday (use when faraday-mode=remote)" namespace:"faraday"`
179+
Loop *RemoteDaemonConfig `group:"Remote loop (use when loop-mode=remote)" namespace:"loop"`
180+
Pool *RemoteDaemonConfig `group:"Remote pool (use when pool-mode=remote)" namespace:"pool"`
155181
}
156182

157183
// RemoteDaemonConfig holds the configuration parameters that are needed to
@@ -225,6 +251,21 @@ func defaultConfig() *Config {
225251
MacaroonPath: lndDefaultConfig.AdminMacPath,
226252
TLSCertPath: lndDefaultConfig.TLSCertPath,
227253
},
254+
Faraday: &RemoteDaemonConfig{
255+
RPCServer: defaultRemoteFaradayRpcServer,
256+
MacaroonPath: faradayDefaultConfig.MacaroonPath,
257+
TLSCertPath: faradayDefaultConfig.TLSCertPath,
258+
},
259+
Loop: &RemoteDaemonConfig{
260+
RPCServer: defaultRemoteLoopRpcServer,
261+
MacaroonPath: loopDefaultConfig.MacaroonPath,
262+
TLSCertPath: loopDefaultConfig.TLSCertPath,
263+
},
264+
Pool: &RemoteDaemonConfig{
265+
RPCServer: defaultRemotePoolRpcServer,
266+
MacaroonPath: poolDefaultConfig.MacaroonPath,
267+
TLSCertPath: poolDefaultConfig.TLSCertPath,
268+
},
228269
},
229270
Network: defaultNetwork,
230271
LndMode: defaultLndMode,
@@ -233,9 +274,12 @@ func defaultConfig() *Config {
233274
LetsEncryptListen: defaultLetsEncryptListen,
234275
LetsEncryptDir: defaultLetsEncryptDir,
235276
ConfigFile: defaultConfigFile,
277+
FaradayMode: defaultFaradayMode,
236278
Faraday: &faradayDefaultConfig,
237279
faradayRpcConfig: &frdrpc.Config{},
280+
LoopMode: defaultLoopMode,
238281
Loop: &loopDefaultConfig,
282+
PoolMode: defaultPoolMode,
239283
Pool: &poolDefaultConfig,
240284
}
241285
}
@@ -274,6 +318,13 @@ func loadAndValidateConfig() (*Config, error) {
274318
// system of lnd is initialized and we can hook up our own loggers now.
275319
SetupLoggers(cfg.Lnd.LogWriter)
276320

321+
// Translate the more user friendly string modes into the more developer
322+
// friendly internal bool variables now.
323+
cfg.lndRemote = cfg.LndMode == ModeRemote
324+
cfg.faradayRemote = cfg.FaradayMode == ModeRemote
325+
cfg.loopRemote = cfg.LoopMode == ModeRemote
326+
cfg.poolRemote = cfg.PoolMode == ModeRemote
327+
277328
// Validate the lightning-terminal config options.
278329
litDir := lnd.CleanAndExpandPath(preCfg.LitDir)
279330
cfg.LetsEncryptDir = lncfg.CleanAndExpandPath(cfg.LetsEncryptDir)
@@ -319,24 +370,59 @@ func loadAndValidateConfig() (*Config, error) {
319370
if err := loopd.Validate(cfg.Loop); err != nil {
320371
return nil, err
321372
}
322-
323373
if err := pool.Validate(cfg.Pool); err != nil {
324374
return nil, err
325375
}
326-
327376
if err := faraday.ValidateConfig(cfg.Faraday); err != nil {
328377
return nil, err
329378
}
330-
cfg.faradayRpcConfig.FaradayDir = cfg.Faraday.FaradayDir
331-
cfg.faradayRpcConfig.MacaroonPath = cfg.Faraday.MacaroonPath
379+
380+
// We've set the network before and have now validated the loop config
381+
// which updated its default paths for that network. So if we're in
382+
// remote mode and not mainnet, we want to update our default paths for
383+
// the remote connection as well.
384+
defaultFaradayCfg := faraday.DefaultConfig()
385+
if cfg.faradayRemote && cfg.Network != defaultNetwork {
386+
if cfg.Remote.Faraday.MacaroonPath == defaultFaradayCfg.MacaroonPath {
387+
cfg.Remote.Faraday.MacaroonPath = cfg.Faraday.MacaroonPath
388+
}
389+
if cfg.Remote.Faraday.TLSCertPath == defaultFaradayCfg.TLSCertPath {
390+
cfg.Remote.Faraday.TLSCertPath = cfg.Faraday.TLSCertPath
391+
}
392+
}
332393

333394
// If the client chose to connect to a bitcoin client, get one now.
334-
if cfg.Faraday.ChainConn {
335-
cfg.faradayRpcConfig.BitcoinClient, err = chain.NewBitcoinClient(
336-
cfg.Faraday.Bitcoin,
337-
)
338-
if err != nil {
339-
return nil, err
395+
if !cfg.faradayRemote {
396+
cfg.faradayRpcConfig.FaradayDir = cfg.Faraday.FaradayDir
397+
cfg.faradayRpcConfig.MacaroonPath = cfg.Faraday.MacaroonPath
398+
399+
if cfg.Faraday.ChainConn {
400+
cfg.faradayRpcConfig.BitcoinClient, err = chain.NewBitcoinClient(
401+
cfg.Faraday.Bitcoin,
402+
)
403+
if err != nil {
404+
return nil, err
405+
}
406+
}
407+
}
408+
409+
defaultLoopCfg := loopd.DefaultConfig()
410+
if cfg.loopRemote && cfg.Network != defaultNetwork {
411+
if cfg.Remote.Loop.MacaroonPath == defaultLoopCfg.MacaroonPath {
412+
cfg.Remote.Loop.MacaroonPath = cfg.Loop.MacaroonPath
413+
}
414+
if cfg.Remote.Loop.TLSCertPath == defaultLoopCfg.TLSCertPath {
415+
cfg.Remote.Loop.TLSCertPath = cfg.Loop.TLSCertPath
416+
}
417+
}
418+
419+
defaultPoolCfg := pool.DefaultConfig()
420+
if cfg.poolRemote && cfg.Network != defaultNetwork {
421+
if cfg.Remote.Pool.MacaroonPath == defaultPoolCfg.MacaroonPath {
422+
cfg.Remote.Pool.MacaroonPath = cfg.Pool.MacaroonPath
423+
}
424+
if cfg.Remote.Pool.TLSCertPath == defaultPoolCfg.TLSCertPath {
425+
cfg.Remote.Pool.TLSCertPath = cfg.Pool.TLSCertPath
340426
}
341427
}
342428

0 commit comments

Comments
 (0)