Skip to content

Commit 20fa2c0

Browse files
terminal: add disable accounts service cfg option
1 parent ec2a7a3 commit 20fa2c0

File tree

3 files changed

+60
-20
lines changed

3 files changed

+60
-20
lines changed

accounts/service.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import (
1616
"github.com/lightningnetwork/lnd/lnwire"
1717
)
1818

19+
// Config holds the configuration options for the accounts service.
20+
type Config struct {
21+
// Disable will disable the accounts service if set.
22+
Disable bool `long:"disable" description:"disable the accounts service"`
23+
}
24+
1925
// trackedPayment is a struct that holds all information that identifies a
2026
// payment that we are tracking in the service.
2127
type trackedPayment struct {

config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightninglabs/faraday"
1818
"github.com/lightninglabs/faraday/chain"
1919
"github.com/lightninglabs/faraday/frdrpcserver"
20+
"github.com/lightninglabs/lightning-terminal/accounts"
2021
"github.com/lightninglabs/lightning-terminal/autopilotserver"
2122
"github.com/lightninglabs/lightning-terminal/firewall"
2223
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
@@ -205,6 +206,8 @@ type Config struct {
205206

206207
Firewall *firewall.Config `group:"Firewall options" namespace:"firewall"`
207208

209+
Accounts *accounts.Config `group:"Accounts options" namespace:"accounts"`
210+
208211
// faradayRpcConfig is a subset of faraday's full configuration that is
209212
// passed into faraday's RPC server.
210213
faradayRpcConfig *frdrpcserver.Config
@@ -320,6 +323,7 @@ func defaultConfig() *Config {
320323
PingCadence: time.Hour,
321324
},
322325
Firewall: firewall.DefaultConfig(),
326+
Accounts: &accounts.Config{},
323327
}
324328
}
325329

terminal.go

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

240245
// Create the instances of our subservers now so we can hook them up to
241246
// lnd once it's fully started.
@@ -849,23 +854,41 @@ func (g *LightningTerminal) startInternalSubServers(
849854
return nil
850855
}
851856

857+
// Even if the accounts service fails on the Start function, or the
858+
// accounts service is disabled, we still want to call Stop function as
859+
// this closes the contexts and the db store which were opened with the
860+
// accounts.NewService function call in the LightningTerminal start
861+
// function above.
862+
closeAccountService := func() {
863+
if err := g.accountService.Stop(); err != nil {
864+
// We only log the error if we fail to stop the service,
865+
// as it's not critical that this succeeds in order to
866+
// keep litd running
867+
log.Errorf("Error stopping account service: %v", err)
868+
}
869+
}
870+
852871
log.Infof("Starting LiT account service")
853-
err = g.accountService.Start(
854-
g.lndClient.Client, g.lndClient.Router,
855-
g.lndClient.ChainParams,
856-
)
857-
if err != nil {
858-
log.Errorf("error starting account service: %v, disabling "+
859-
"account service", err)
872+
if !g.cfg.Accounts.Disable {
873+
err = g.accountService.Start(
874+
g.lndClient.Client, g.lndClient.Router,
875+
g.lndClient.ChainParams,
876+
)
877+
if err != nil {
878+
log.Errorf("error starting account service: %v, "+
879+
"disabling account service", err)
880+
881+
g.statusMgr.SetErrored(subservers.ACCOUNTS, err.Error())
882+
883+
closeAccountService()
884+
} else {
885+
g.statusMgr.SetRunning(subservers.ACCOUNTS)
860886

861-
g.statusMgr.SetErrored(subservers.ACCOUNTS, err.Error())
887+
g.accountServiceStarted = true
888+
}
862889
} else {
863-
g.statusMgr.SetRunning(subservers.ACCOUNTS)
890+
closeAccountService()
864891
}
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
869892

870893
requestLogger, err := firewall.NewRequestLogger(
871894
g.cfg.Firewall.RequestLogger, g.firewallDB,
@@ -952,7 +975,12 @@ func (g *LightningTerminal) registerSubDaemonGrpcServers(server *grpc.Server,
952975
litrpc.RegisterStatusServer(server, g.statusMgr)
953976
} else {
954977
litrpc.RegisterSessionsServer(server, g.sessionRpcServer)
955-
litrpc.RegisterAccountsServer(server, g.accountRpcServer)
978+
979+
if !g.cfg.Accounts.Disable {
980+
litrpc.RegisterAccountsServer(
981+
server, g.accountRpcServer,
982+
)
983+
}
956984
}
957985

958986
litrpc.RegisterFirewallServer(server, g.sessionRpcServer)
@@ -979,11 +1007,13 @@ func (g *LightningTerminal) RegisterRestSubserver(ctx context.Context,
9791007
return err
9801008
}
9811009

982-
err = litrpc.RegisterAccountsHandlerFromEndpoint(
983-
ctx, mux, endpoint, dialOpts,
984-
)
985-
if err != nil {
986-
return err
1010+
if !g.cfg.Accounts.Disable {
1011+
err = litrpc.RegisterAccountsHandlerFromEndpoint(
1012+
ctx, mux, endpoint, dialOpts,
1013+
)
1014+
if err != nil {
1015+
return err
1016+
}
9871017
}
9881018

9891019
err = litrpc.RegisterFirewallHandlerFromEndpoint(

0 commit comments

Comments
 (0)