Skip to content

Commit b0b052d

Browse files
committed
rpc_proxy+terminal: add LND and LiT to status server
1 parent 76ed920 commit b0b052d

File tree

2 files changed

+51
-19
lines changed

2 files changed

+51
-19
lines changed

rpc_proxy.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -587,18 +587,17 @@ func (p *rpcProxy) checkSubSystemStarted(requestURI string) error {
587587
return ErrWaitingToStart
588588
}
589589

590-
// Currently, Lit and LND are not registered with the sub-server
591-
// manager, so we let any request for them through.
592-
if p.permsMgr.IsSubServerURI(subservers.LIT, requestURI) ||
593-
p.permsMgr.IsSubServerURI(subservers.LND, requestURI) {
590+
handled, system := p.subServerMgr.Handles(requestURI)
591+
switch {
592+
case handled:
594593

595-
return nil
596-
}
594+
case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI):
595+
system = subservers.LIT
597596

598-
// Check that the sub-server manager does have a sub-server registered
599-
// that can handle the given URI.
600-
handled, system := p.subServerMgr.Handles(requestURI)
601-
if !handled {
597+
case p.permsMgr.IsSubServerURI(subservers.LND, requestURI):
598+
system = subservers.LND
599+
600+
default:
602601
return fmt.Errorf("unknown gRPC web request: %v", requestURI)
603602
}
604603

terminal.go

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ func (g *LightningTerminal) Run() error {
229229
return fmt.Errorf("could not create permissions manager")
230230
}
231231

232+
// Register LND and LiT with the status manager.
233+
g.statusMgr.RegisterSubServer(subservers.LND)
234+
g.statusMgr.RegisterSubServer(subservers.LIT)
235+
232236
// Create the instances of our subservers now so we can hook them up to
233237
// lnd once it's fully started.
234238
g.subServerMgr = subservers.NewManager(g.permsMgr, g.statusMgr)
@@ -268,8 +272,9 @@ func (g *LightningTerminal) Run() error {
268272
// could not start or LND could not start or be connected to.
269273
startErr := g.start()
270274
if startErr != nil {
271-
log.Errorf("Error starting Lightning Terminal: %v", startErr)
272-
return startErr
275+
g.statusMgr.SetErrored(
276+
subservers.LIT, "could not start Lit: %v", startErr,
277+
)
273278
}
274279

275280
// Now block until we receive an error or the main shutdown
@@ -301,7 +306,6 @@ func (g *LightningTerminal) Run() error {
301306
// returned.
302307
func (g *LightningTerminal) start() error {
303308
var err error
304-
305309
g.accountService, err = accounts.NewService(
306310
filepath.Dir(g.cfg.MacaroonPath), g.errQueue.ChanIn(),
307311
)
@@ -461,10 +465,18 @@ func (g *LightningTerminal) start() error {
461465
case <-readyChan:
462466

463467
case err := <-g.errQueue.ChanOut():
464-
return err
468+
g.statusMgr.SetErrored(
469+
subservers.LND, "error from errQueue channel",
470+
)
471+
472+
return fmt.Errorf("could not start LND: %v", err)
465473

466474
case <-lndQuit:
467-
return nil
475+
g.statusMgr.SetErrored(
476+
subservers.LND, "lndQuit channel closed",
477+
)
478+
479+
return fmt.Errorf("LND has stopped")
468480

469481
case <-interceptor.ShutdownChannel():
470482
return fmt.Errorf("received the shutdown signal")
@@ -494,6 +506,10 @@ func (g *LightningTerminal) start() error {
494506
// Connect to LND.
495507
g.lndConn, err = connectLND(g.cfg, bufRpcListener)
496508
if err != nil {
509+
g.statusMgr.SetErrored(
510+
subservers.LND, "could not connect to LND: %v", err,
511+
)
512+
497513
return fmt.Errorf("could not connect to LND")
498514
}
499515

@@ -522,7 +538,11 @@ func (g *LightningTerminal) start() error {
522538
return err
523539

524540
case <-lndQuit:
525-
return nil
541+
g.statusMgr.SetErrored(
542+
subservers.LND, "lndQuit channel closed",
543+
)
544+
545+
return fmt.Errorf("LND has stopped")
526546

527547
case <-interceptor.ShutdownChannel():
528548
return fmt.Errorf("received the shutdown signal")
@@ -538,10 +558,16 @@ func (g *LightningTerminal) start() error {
538558
// Set up all the LND clients required by LiT.
539559
err = g.setUpLNDClients()
540560
if err != nil {
541-
log.Errorf("Could not set up LND clients: %w", err)
542-
return err
561+
g.statusMgr.SetErrored(
562+
subservers.LND, "could not set up LND clients: %v", err,
563+
)
564+
565+
return fmt.Errorf("could not start LND")
543566
}
544567

568+
// We can now set the status of LND as running.
569+
g.statusMgr.SetRunning(subservers.LND)
570+
545571
// If we're in integrated and stateless init mode, we won't create
546572
// macaroon files in any of the subserver daemons.
547573
createDefaultMacaroons := true
@@ -568,14 +594,21 @@ func (g *LightningTerminal) start() error {
568594
return fmt.Errorf("could not start litd sub-servers: %v", err)
569595
}
570596

597+
// We can now set the status of LiT as running.
598+
g.statusMgr.SetRunning(subservers.LIT)
599+
571600
// Now block until we receive an error or the main shutdown signal.
572601
select {
573602
case err := <-g.errQueue.ChanOut():
574603
return fmt.Errorf("received critical error from subsystem, "+
575604
"shutting down: %v", err)
576605

577606
case <-lndQuit:
578-
return nil
607+
g.statusMgr.SetErrored(
608+
subservers.LND, "lndQuit channel closed",
609+
)
610+
611+
return fmt.Errorf("LND is not running")
579612

580613
case <-interceptor.ShutdownChannel():
581614
log.Infof("Shutdown signal received")

0 commit comments

Comments
 (0)