mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
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:
parent
6f9f3244fb
commit
ec2a7a39b4
4 changed files with 31 additions and 27 deletions
|
|
@ -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
|
||||
|
|
|
|||
13
rpc_proxy.go
13
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,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
12
terminal.go
12
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue