diff --git a/accounts/rpcserver.go b/accounts/rpcserver.go index 7556a95d..22135f63 100644 --- a/accounts/rpcserver.go +++ b/accounts/rpcserver.go @@ -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 diff --git a/rpc_proxy.go b/rpc_proxy.go index 798f8592..f1be7593 100644 --- a/rpc_proxy.go +++ b/rpc_proxy.go @@ -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, + ), + ) +} diff --git a/subservers/subserver.go b/subservers/subserver.go index 8605eb42..82ba2229 100644 --- a/subservers/subserver.go +++ b/subservers/subserver.go @@ -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 diff --git a/terminal.go b/terminal.go index c141e1d6..571c9dc5 100644 --- a/terminal.go +++ b/terminal.go @@ -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