Skip to content

Commit acbe1dd

Browse files
committed
terminal: add disable accounts service cfg option
1 parent bc1e1a1 commit acbe1dd

File tree

2 files changed

+40
-19
lines changed

2 files changed

+40
-19
lines changed

config.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ const (
4242

4343
ModeIntegrated = "integrated"
4444
ModeRemote = "remote"
45+
ModeEnable = "enable"
4546
ModeDisable = "disable"
4647

47-
DefaultLndMode = ModeRemote
48-
defaultFaradayMode = ModeIntegrated
49-
defaultLoopMode = ModeIntegrated
50-
defaultPoolMode = ModeIntegrated
51-
defaultTapMode = ModeIntegrated
48+
DefaultLndMode = ModeRemote
49+
defaultFaradayMode = ModeIntegrated
50+
defaultLoopMode = ModeIntegrated
51+
defaultPoolMode = ModeIntegrated
52+
defaultTapMode = ModeIntegrated
53+
defaultAccountsMode = ModeEnable
5254

5355
defaultConfigFilename = "lit.conf"
5456

@@ -199,6 +201,8 @@ type Config struct {
199201
TaprootAssetsMode string `long:"taproot-assets-mode" description:"The mode to run taproot assets in, either 'integrated' (default), 'remote' or 'disable'. 'integrated' means tapd is started alongside the UI and everything is stored in tap's main data directory, configure everything by using the --taproot-assets.* flags. 'remote' means the UI connects to an existing tapd node and acts as a proxy for gRPC calls to it. 'disable' means that LiT is started without tapd" choice:"integrated" choice:"disable"`
200202
TaprootAssets *tapcfg.Config `group:"Integrated taproot assets options (use when taproot-assets=integrated)" namespace:"taproot-assets"`
201203

204+
AccountsMode string `long:"accounts-mode" description:"The mode to run the accounts service in, either 'enable' (default), or 'disable'. 'enable' means that LiT is started with the integrated the accounts service enabled and running. 'disable' means that LiT is started with the accounts service disabled, and all requests to the accounts service will be rejected." choice:"enable" choice:"disable"`
205+
202206
RPCMiddleware *mid.Config `group:"RPC middleware options" namespace:"rpcmiddleware"`
203207

204208
Autopilot *autopilotserver.Config `group:"Autopilot server options" namespace:"autopilot"`
@@ -314,6 +318,7 @@ func defaultConfig() *Config {
314318
Pool: &poolDefaultConfig,
315319
TaprootAssetsMode: defaultTapMode,
316320
TaprootAssets: &tapDefaultConfig,
321+
AccountsMode: defaultAccountsMode,
317322
RPCMiddleware: mid.DefaultConfig(),
318323
FirstLNCConnDeadline: defaultFirstLNCConnTimeout,
319324
Autopilot: &autopilotserver.Config{

terminal.go

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,12 @@ func (g *LightningTerminal) Run() error {
236236
// Register LND, LiT and Accounts with the status manager.
237237
g.statusMgr.RegisterAndEnableSubServer(subservers.LND)
238238
g.statusMgr.RegisterAndEnableSubServer(subservers.LIT)
239-
g.statusMgr.RegisterAndEnableSubServer(subservers.ACCOUNTS)
239+
g.statusMgr.RegisterSubServer(subservers.ACCOUNTS)
240+
241+
// Also enable the accounts subserver if it's not disabled.
242+
if g.cfg.AccountsMode != ModeDisable {
243+
g.statusMgr.SetEnabled(subservers.ACCOUNTS)
244+
}
240245

241246
// Create the instances of our subservers now so we can hook them up to
242247
// lnd once it's fully started.
@@ -850,22 +855,33 @@ func (g *LightningTerminal) startInternalSubServers(
850855
return nil
851856
}
852857

858+
stopAccountService := func() {
859+
if err := g.accountService.Stop(); err != nil {
860+
// We only log the error if we fail to stop the service,
861+
// as it's not critical that this succeeds in order to
862+
// keep litd running
863+
log.Errorf("Error stopping account service: %v", err)
864+
}
865+
}
866+
853867
log.Infof("Starting LiT account service")
854-
err = g.accountService.Start(
855-
g.lndClient.Client, g.lndClient.Router,
856-
g.lndClient.ChainParams,
857-
)
858-
if err != nil {
859-
log.Errorf("error starting account service: %v, disabling "+
860-
"account service", err)
861-
g.statusMgr.SetErrored(subservers.ACCOUNTS, err.Error())
868+
if g.cfg.AccountsMode != ModeDisable {
869+
err = g.accountService.Start(
870+
g.lndClient.Client, g.lndClient.Router,
871+
g.lndClient.ChainParams,
872+
)
873+
if err != nil {
874+
log.Errorf("error starting account service: %v, "+
875+
"disabling account service", err)
876+
g.statusMgr.SetErrored(subservers.ACCOUNTS, err.Error())
877+
stopAccountService()
878+
} else {
879+
g.statusMgr.SetRunning(subservers.ACCOUNTS)
880+
g.accountServiceStarted = true
881+
}
862882
} else {
863-
g.statusMgr.SetRunning(subservers.ACCOUNTS)
883+
stopAccountService()
864884
}
865-
// Even if we error on accountService.Start, we still want to mark the
866-
// service as started so that we can properly shut it down in the
867-
// shutdownSubServers call.
868-
g.accountServiceStarted = true
869885

870886
requestLogger, err := firewall.NewRequestLogger(
871887
g.cfg.Firewall.RequestLogger, g.firewallDB,

0 commit comments

Comments
 (0)