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

View file

@ -623,6 +623,9 @@ func (p *rpcProxy) checkSubSystemStarted(requestURI string) error {
switch { switch {
case handled: case handled:
case isAccountsReq(requestURI):
system = subservers.ACCOUNTS
case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI): case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI):
system = subservers.LIT system = subservers.LIT
@ -694,3 +697,13 @@ func isProxyReq(uri string) bool {
uri, fmt.Sprintf("/%s", litrpc.Proxy_ServiceDesc.ServiceName), 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 ( const (
LND string = "lnd" LND string = "lnd"
LIT string = "lit" LIT string = "lit"
LOOP string = "loop" LOOP string = "loop"
POOL string = "pool" POOL string = "pool"
TAP string = "taproot-assets" TAP string = "taproot-assets"
FARADAY string = "faraday" FARADAY string = "faraday"
ACCOUNTS string = "accounts"
) )
// subServerWrapper is a wrapper around the SubServer interface and is used by // 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") 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.LND)
g.statusMgr.RegisterAndEnableSubServer(subservers.LIT) g.statusMgr.RegisterAndEnableSubServer(subservers.LIT)
g.statusMgr.RegisterAndEnableSubServer(subservers.ACCOUNTS)
// Create the instances of our subservers now so we can hook them up to // Create the instances of our subservers now so we can hook them up to
// lnd once it's fully started. // lnd once it's fully started.
@ -306,6 +307,11 @@ func (g *LightningTerminal) start() error {
var err error var err error
accountServiceErrCallback := func(err error) { accountServiceErrCallback := func(err error) {
g.statusMgr.SetErrored(
subservers.ACCOUNTS,
err.Error(),
)
log.Errorf("Error thrown in the accounts service, keeping "+ log.Errorf("Error thrown in the accounts service, keeping "+
"litd running: %v", err, "litd running: %v", err,
) )
@ -851,6 +857,10 @@ func (g *LightningTerminal) startInternalSubServers(
if err != nil { if err != nil {
log.Errorf("error starting account service: %v, disabling "+ log.Errorf("error starting account service: %v, disabling "+
"account service", err) "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 // 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 // service as started so that we can properly shut it down in the