Skip to content

Commit d02749a

Browse files
ellemoutonpositiveblue
authored andcommitted
subservers: add new package to manage the lit subservers
1 parent 30262f2 commit d02749a

File tree

7 files changed

+480
-40
lines changed

7 files changed

+480
-40
lines changed

config.go

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"github.com/lightninglabs/lightning-terminal/autopilotserver"
2121
"github.com/lightninglabs/lightning-terminal/firewall"
2222
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
23+
"github.com/lightninglabs/lightning-terminal/subservers"
2324
"github.com/lightninglabs/lndclient"
2425
"github.com/lightninglabs/loop/loopd"
2526
"github.com/lightninglabs/pool"
@@ -169,7 +170,7 @@ type Config struct {
169170
// That way only one global network flag is needed.
170171
Network string `long:"network" description:"The network the UI and all its components run on" choice:"regtest" choice:"testnet" choice:"mainnet" choice:"simnet"`
171172

172-
Remote *RemoteConfig `group:"Remote mode options (use when lnd-mode=remote)" namespace:"remote"`
173+
Remote *subservers.RemoteConfig `group:"Remote mode options (use when lnd-mode=remote)" namespace:"remote"`
173174

174175
// LndMode is the selected mode to run lnd in. The supported modes are
175176
// 'integrated' and 'remote'. We only use a string instead of a bool
@@ -212,40 +213,6 @@ type Config struct {
212213
lndAdminMacaroon []byte
213214
}
214215

215-
// RemoteConfig holds the configuration parameters that are needed when running
216-
// LiT in the "remote" lnd mode.
217-
type RemoteConfig struct {
218-
LitLogDir string `long:"lit-logdir" description:"For lnd remote mode only: Directory to log output."`
219-
LitMaxLogFiles int `long:"lit-maxlogfiles" description:"For lnd remote mode only: Maximum logfiles to keep (0 for no rotation)"`
220-
LitMaxLogFileSize int `long:"lit-maxlogfilesize" description:"For lnd remote mode only: Maximum logfile size in MB"`
221-
222-
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."`
223-
224-
Lnd *RemoteDaemonConfig `group:"Remote lnd (use when lnd-mode=remote)" namespace:"lnd"`
225-
Faraday *RemoteDaemonConfig `group:"Remote faraday (use when faraday-mode=remote)" namespace:"faraday"`
226-
Loop *RemoteDaemonConfig `group:"Remote loop (use when loop-mode=remote)" namespace:"loop"`
227-
Pool *RemoteDaemonConfig `group:"Remote pool (use when pool-mode=remote)" namespace:"pool"`
228-
}
229-
230-
// RemoteDaemonConfig holds the configuration parameters that are needed to
231-
// connect to a remote daemon like lnd for example.
232-
type RemoteDaemonConfig struct {
233-
// RPCServer is host:port that the remote daemon's RPC server is
234-
// listening on.
235-
RPCServer string `long:"rpcserver" description:"The host:port that the remote daemon is listening for RPC connections on."`
236-
237-
// MacaroonPath is the path to the single macaroon that should be used
238-
// instead of needing to specify the macaroon directory that contains
239-
// all of the daemon's macaroons. The specified macaroon MUST have all
240-
// permissions that all the subservers use, otherwise permission errors
241-
// will occur.
242-
MacaroonPath string `long:"macaroonpath" description:"The full path to the single macaroon to use, either the main (admin.macaroon in lnd's case) or a custom baked one. A custom macaroon must contain ALL permissions required for all subservers to work, otherwise permission errors will occur."`
243-
244-
// TLSCertPath is the path to the tls cert of the remote daemon that
245-
// should be used to verify the TLS identity of the remote RPC server.
246-
TLSCertPath string `long:"tlscertpath" description:"The full path to the remote daemon's TLS cert to use for RPC connection verification."`
247-
}
248-
249216
// lndConnectParams returns the connection parameters to connect to the local
250217
// lnd instance.
251218
func (c *Config) lndConnectParams() (string, lndclient.Network, string,
@@ -289,27 +256,27 @@ func defaultConfig() *Config {
289256
HTTPSListen: defaultHTTPSListen,
290257
TLSCertPath: DefaultTLSCertPath,
291258
TLSKeyPath: defaultTLSKeyPath,
292-
Remote: &RemoteConfig{
259+
Remote: &subservers.RemoteConfig{
293260
LitDebugLevel: defaultLogLevel,
294261
LitLogDir: defaultLogDir,
295262
LitMaxLogFiles: defaultMaxLogFiles,
296263
LitMaxLogFileSize: defaultMaxLogFileSize,
297-
Lnd: &RemoteDaemonConfig{
264+
Lnd: &subservers.RemoteDaemonConfig{
298265
RPCServer: defaultRemoteLndRpcServer,
299266
MacaroonPath: DefaultRemoteLndMacaroonPath,
300267
TLSCertPath: lndDefaultConfig.TLSCertPath,
301268
},
302-
Faraday: &RemoteDaemonConfig{
269+
Faraday: &subservers.RemoteDaemonConfig{
303270
RPCServer: defaultRemoteFaradayRpcServer,
304271
MacaroonPath: faradayDefaultConfig.MacaroonPath,
305272
TLSCertPath: faradayDefaultConfig.TLSCertPath,
306273
},
307-
Loop: &RemoteDaemonConfig{
274+
Loop: &subservers.RemoteDaemonConfig{
308275
RPCServer: defaultRemoteLoopRpcServer,
309276
MacaroonPath: loopDefaultConfig.MacaroonPath,
310277
TLSCertPath: loopDefaultConfig.TLSCertPath,
311278
},
312-
Pool: &RemoteDaemonConfig{
279+
Pool: &subservers.RemoteDaemonConfig{
313280
RPCServer: defaultRemotePoolRpcServer,
314281
MacaroonPath: poolDefaultConfig.MacaroonPath,
315282
TLSCertPath: poolDefaultConfig.TLSCertPath,

log.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
1111
"github.com/lightninglabs/lightning-terminal/rules"
1212
"github.com/lightninglabs/lightning-terminal/session"
13+
"github.com/lightninglabs/lightning-terminal/subservers"
1314
"github.com/lightninglabs/loop/loopd"
1415
"github.com/lightninglabs/pool"
1516
"github.com/lightningnetwork/lnd"
@@ -77,6 +78,10 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
7778
autopilotserver.UseLogger,
7879
)
7980

81+
lnd.AddSubLogger(
82+
root, subservers.Subsystem, intercept, subservers.UseLogger,
83+
)
84+
8085
// Add daemon loggers to lnd's root logger.
8186
faraday.SetupLoggers(root, intercept)
8287
loopd.SetupLoggers(root, intercept)

subservers/config.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package subservers
2+
3+
// RemoteConfig holds the configuration parameters that are needed when running
4+
// LiT in the "remote" lnd mode.
5+
type RemoteConfig struct {
6+
LitLogDir string `long:"lit-logdir" description:"For lnd remote mode only: Directory to log output."`
7+
LitMaxLogFiles int `long:"lit-maxlogfiles" description:"For lnd remote mode only: Maximum logfiles to keep (0 for no rotation)"`
8+
LitMaxLogFileSize int `long:"lit-maxlogfilesize" description:"For lnd remote mode only: Maximum logfile size in MB"`
9+
10+
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."`
11+
12+
Lnd *RemoteDaemonConfig `group:"Remote lnd (use when lnd-mode=remote)" namespace:"lnd"`
13+
Faraday *RemoteDaemonConfig `group:"Remote faraday (use when faraday-mode=remote)" namespace:"faraday"`
14+
Loop *RemoteDaemonConfig `group:"Remote loop (use when loop-mode=remote)" namespace:"loop"`
15+
Pool *RemoteDaemonConfig `group:"Remote pool (use when pool-mode=remote)" namespace:"pool"`
16+
}
17+
18+
// RemoteDaemonConfig holds the configuration parameters that are needed to
19+
// connect to a remote daemon like lnd for example.
20+
type RemoteDaemonConfig struct {
21+
// RPCServer is host:port that the remote daemon's RPC server is
22+
// listening on.
23+
RPCServer string `long:"rpcserver" description:"The host:port that the remote daemon is listening for RPC connections on."`
24+
25+
// MacaroonPath is the path to the single macaroon that should be used
26+
// instead of needing to specify the macaroon directory that contains
27+
// all of the daemon's macaroons. The specified macaroon MUST have all
28+
// permissions that all the subservers use, otherwise permission errors
29+
// will occur.
30+
MacaroonPath string `long:"macaroonpath" description:"The full path to the single macaroon to use, either the main (admin.macaroon in lnd's case) or a custom baked one. A custom macaroon must contain ALL permissions required for all subservers to work, otherwise permission errors will occur."`
31+
32+
// TLSCertPath is the path to the tls cert of the remote daemon that
33+
// should be used to verify the TLS identity of the remote RPC server.
34+
TLSCertPath string `long:"tlscertpath" description:"The full path to the remote daemon's TLS cert to use for RPC connection verification."`
35+
}

subservers/interface.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package subservers
2+
3+
import (
4+
"github.com/lightninglabs/lndclient"
5+
"github.com/lightningnetwork/lnd/lnrpc"
6+
"github.com/lightningnetwork/lnd/macaroons"
7+
"google.golang.org/grpc"
8+
)
9+
10+
// SubServer defines an interface that should be implemented by any sub-server
11+
// that the subServer manager should manage. A sub-server can be run in either
12+
// integrated or remote mode. A sub-server is considered non-fatal to LiT
13+
// meaning that if a sub-server fails to start, LiT can safely continue with its
14+
// operations and other sub-servers can too.
15+
type SubServer interface {
16+
macaroons.MacaroonValidator
17+
18+
// Name returns the name of the sub-server.
19+
Name() string
20+
21+
// Remote returns true if the sub-server is running remotely and so
22+
// should be connected to instead of spinning up an integrated server.
23+
Remote() bool
24+
25+
// RemoteConfig returns the config required to connect to the sub-server
26+
// if it is running in remote mode.
27+
RemoteConfig() *RemoteDaemonConfig
28+
29+
// Start starts the sub-server in integrated mode.
30+
Start(lnrpc.LightningClient, *lndclient.GrpcLndServices, bool) error
31+
32+
// Stop stops the sub-server in integrated mode.
33+
Stop() error
34+
35+
// RegisterGrpcService must register the sub-server's GRPC server with
36+
// the given registrar.
37+
RegisterGrpcService(grpc.ServiceRegistrar)
38+
39+
// ServerErrChan returns an error channel that should be listened on
40+
// after starting the sub-server to listen for any runtime errors. It
41+
// is optional and may be set to nil. This only applies in integrated
42+
// mode.
43+
ServerErrChan() chan error
44+
45+
// MacPath returns the path to the sub-server's macaroon if it is not
46+
// running in remote mode.
47+
MacPath() string
48+
}

subservers/log.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package subservers
2+
3+
import (
4+
"github.com/btcsuite/btclog"
5+
"github.com/lightningnetwork/lnd/build"
6+
)
7+
8+
const Subsystem = "SSVR"
9+
10+
// log is a logger that is initialized with no output filters. This
11+
// means the package will not perform any logging by default until the caller
12+
// requests it.
13+
var log btclog.Logger
14+
15+
// The default amount of logging is none.
16+
func init() {
17+
UseLogger(build.NewSubLogger(Subsystem, nil))
18+
}
19+
20+
// UseLogger uses a specified Logger to output package logging info.
21+
// This should be used in preference to SetLogWriter if the caller is also
22+
// using btclog.
23+
func UseLogger(logger btclog.Logger) {
24+
log = logger
25+
}

0 commit comments

Comments
 (0)