Skip to content

Commit ec2a7a3

Browse files
multi: add accounts service to status manager
Add the accounts service to status manager. This will allow us to query the status of the accounts service and see if it is running or not. For incoming gRPC requests to the accounts service, we also use the status manager to check if the accounts service is running or not to determine if we should let the request through or not.
1 parent 6f9f324 commit ec2a7a3

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

accounts/rpcserver.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ func (s *RPCServer) CreateAccount(ctx context.Context,
5353
log.Infof("[createaccount] label=%v, balance=%d, expiration=%d",
5454
req.Label, req.AccountBalance, req.ExpirationDate)
5555

56-
if !s.service.IsRunning() {
57-
return nil, ErrAccountServiceDisabled
58-
}
59-
6056
var (
6157
balanceMsat lnwire.MilliSatoshi
6258
expirationDate time.Time
@@ -119,10 +115,6 @@ func (s *RPCServer) UpdateAccount(_ context.Context,
119115
log.Infof("[updateaccount] id=%s, label=%v, balance=%d, expiration=%d",
120116
req.Id, req.Label, req.AccountBalance, req.ExpirationDate)
121117

122-
if !s.service.IsRunning() {
123-
return nil, ErrAccountServiceDisabled
124-
}
125-
126118
accountID, err := s.findAccount(req.Id, req.Label)
127119
if err != nil {
128120
return nil, err
@@ -146,10 +138,6 @@ func (s *RPCServer) ListAccounts(context.Context,
146138

147139
log.Info("[listaccounts]")
148140

149-
if !s.service.IsRunning() {
150-
return nil, ErrAccountServiceDisabled
151-
}
152-
153141
// Retrieve all accounts from the macaroon account store.
154142
accts, err := s.service.Accounts()
155143
if err != nil {
@@ -175,10 +163,6 @@ func (s *RPCServer) AccountInfo(_ context.Context,
175163

176164
log.Infof("[accountinfo] id=%v, label=%v", req.Id, req.Label)
177165

178-
if !s.service.IsRunning() {
179-
return nil, ErrAccountServiceDisabled
180-
}
181-
182166
accountID, err := s.findAccount(req.Id, req.Label)
183167
if err != nil {
184168
return nil, err
@@ -199,10 +183,6 @@ func (s *RPCServer) RemoveAccount(_ context.Context,
199183

200184
log.Infof("[removeaccount] id=%v, label=%v", req.Id, req.Label)
201185

202-
if !s.service.IsRunning() {
203-
return nil, ErrAccountServiceDisabled
204-
}
205-
206186
accountID, err := s.findAccount(req.Id, req.Label)
207187
if err != nil {
208188
return nil, err

rpc_proxy.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,9 @@ func (p *rpcProxy) checkSubSystemStarted(requestURI string) error {
623623
switch {
624624
case handled:
625625

626+
case isAccountsReq(requestURI):
627+
system = subservers.ACCOUNTS
628+
626629
case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI):
627630
system = subservers.LIT
628631

@@ -694,3 +697,13 @@ func isProxyReq(uri string) bool {
694697
uri, fmt.Sprintf("/%s", litrpc.Proxy_ServiceDesc.ServiceName),
695698
)
696699
}
700+
701+
// isAccountsReq returns true if the given request is intended for the
702+
// litrpc.Accounts service.
703+
func isAccountsReq(uri string) bool {
704+
return strings.HasPrefix(
705+
uri, fmt.Sprintf(
706+
"/%s", litrpc.Accounts_ServiceDesc.ServiceName,
707+
),
708+
)
709+
}

subservers/subserver.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import (
1111
)
1212

1313
const (
14-
LND string = "lnd"
15-
LIT string = "lit"
16-
LOOP string = "loop"
17-
POOL string = "pool"
18-
TAP string = "taproot-assets"
19-
FARADAY string = "faraday"
14+
LND string = "lnd"
15+
LIT string = "lit"
16+
LOOP string = "loop"
17+
POOL string = "pool"
18+
TAP string = "taproot-assets"
19+
FARADAY string = "faraday"
20+
ACCOUNTS string = "accounts"
2021
)
2122

2223
// subServerWrapper is a wrapper around the SubServer interface and is used by

terminal.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,10 @@ func (g *LightningTerminal) Run() error {
232232
return fmt.Errorf("could not create permissions manager")
233233
}
234234

235-
// Register LND and LiT with the status manager.
235+
// 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)
238239

239240
// Create the instances of our subservers now so we can hook them up to
240241
// lnd once it's fully started.
@@ -306,6 +307,11 @@ func (g *LightningTerminal) start() error {
306307
var err error
307308

308309
accountServiceErrCallback := func(err error) {
310+
g.statusMgr.SetErrored(
311+
subservers.ACCOUNTS,
312+
err.Error(),
313+
)
314+
309315
log.Errorf("Error thrown in the accounts service, keeping "+
310316
"litd running: %v", err,
311317
)
@@ -851,6 +857,10 @@ func (g *LightningTerminal) startInternalSubServers(
851857
if err != nil {
852858
log.Errorf("error starting account service: %v, disabling "+
853859
"account service", err)
860+
861+
g.statusMgr.SetErrored(subservers.ACCOUNTS, err.Error())
862+
} else {
863+
g.statusMgr.SetRunning(subservers.ACCOUNTS)
854864
}
855865
// Even if we error on accountService.Start, we still want to mark the
856866
// service as started so that we can properly shut it down in the

0 commit comments

Comments
 (0)