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.
This commit is contained in:
Viktor Tigerström 2023-09-21 02:01:38 +02:00
parent 6f9f3244fb
commit ec2a7a39b4
No known key found for this signature in database
GPG key ID: B984570980684DCC
4 changed files with 31 additions and 27 deletions

View file

@ -53,10 +53,6 @@ func (s *RPCServer) CreateAccount(ctx context.Context,
log.Infof("[createaccount] label=%v, balance=%d, expiration=%d",
req.Label, req.AccountBalance, req.ExpirationDate)
if !s.service.IsRunning() {
return nil, ErrAccountServiceDisabled
}
var (
balanceMsat lnwire.MilliSatoshi
expirationDate time.Time
@ -119,10 +115,6 @@ func (s *RPCServer) UpdateAccount(_ context.Context,
log.Infof("[updateaccount] id=%s, label=%v, balance=%d, expiration=%d",
req.Id, req.Label, req.AccountBalance, req.ExpirationDate)
if !s.service.IsRunning() {
return nil, ErrAccountServiceDisabled
}
accountID, err := s.findAccount(req.Id, req.Label)
if err != nil {
return nil, err
@ -146,10 +138,6 @@ func (s *RPCServer) ListAccounts(context.Context,
log.Info("[listaccounts]")
if !s.service.IsRunning() {
return nil, ErrAccountServiceDisabled
}
// Retrieve all accounts from the macaroon account store.
accts, err := s.service.Accounts()
if err != nil {
@ -175,10 +163,6 @@ func (s *RPCServer) AccountInfo(_ context.Context,
log.Infof("[accountinfo] id=%v, label=%v", req.Id, req.Label)
if !s.service.IsRunning() {
return nil, ErrAccountServiceDisabled
}
accountID, err := s.findAccount(req.Id, req.Label)
if err != nil {
return nil, err
@ -199,10 +183,6 @@ func (s *RPCServer) RemoveAccount(_ context.Context,
log.Infof("[removeaccount] id=%v, label=%v", req.Id, req.Label)
if !s.service.IsRunning() {
return nil, ErrAccountServiceDisabled
}
accountID, err := s.findAccount(req.Id, req.Label)
if err != nil {
return nil, err

View file

@ -623,6 +623,9 @@ func (p *rpcProxy) checkSubSystemStarted(requestURI string) error {
switch {
case handled:
case isAccountsReq(requestURI):
system = subservers.ACCOUNTS
case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI):
system = subservers.LIT
@ -694,3 +697,13 @@ func isProxyReq(uri string) bool {
uri, fmt.Sprintf("/%s", litrpc.Proxy_ServiceDesc.ServiceName),
)
}
// isAccountsReq returns true if the given request is intended for the
// litrpc.Accounts service.
func isAccountsReq(uri string) bool {
return strings.HasPrefix(
uri, fmt.Sprintf(
"/%s", litrpc.Accounts_ServiceDesc.ServiceName,
),
)
}

View file

@ -11,12 +11,13 @@ import (
)
const (
LND string = "lnd"
LIT string = "lit"
LOOP string = "loop"
POOL string = "pool"
TAP string = "taproot-assets"
FARADAY string = "faraday"
LND string = "lnd"
LIT string = "lit"
LOOP string = "loop"
POOL string = "pool"
TAP string = "taproot-assets"
FARADAY string = "faraday"
ACCOUNTS string = "accounts"
)
// subServerWrapper is a wrapper around the SubServer interface and is used by

View file

@ -232,9 +232,10 @@ func (g *LightningTerminal) Run() error {
return fmt.Errorf("could not create permissions manager")
}
// Register LND and LiT with the status manager.
// Register LND, LiT and Accounts with the status manager.
g.statusMgr.RegisterAndEnableSubServer(subservers.LND)
g.statusMgr.RegisterAndEnableSubServer(subservers.LIT)
g.statusMgr.RegisterAndEnableSubServer(subservers.ACCOUNTS)
// Create the instances of our subservers now so we can hook them up to
// lnd once it's fully started.
@ -306,6 +307,11 @@ func (g *LightningTerminal) start() error {
var err error
accountServiceErrCallback := func(err error) {
g.statusMgr.SetErrored(
subservers.ACCOUNTS,
err.Error(),
)
log.Errorf("Error thrown in the accounts service, keeping "+
"litd running: %v", err,
)
@ -851,6 +857,10 @@ func (g *LightningTerminal) startInternalSubServers(
if err != nil {
log.Errorf("error starting account service: %v, disabling "+
"account service", err)
g.statusMgr.SetErrored(subservers.ACCOUNTS, err.Error())
} else {
g.statusMgr.SetRunning(subservers.ACCOUNTS)
}
// Even if we error on accountService.Start, we still want to mark the
// service as started so that we can properly shut it down in the