Skip to content

Commit 0f53f43

Browse files
committed
rpc_proxy+terminal: add LND and LiT to status server
1 parent 75cfa0b commit 0f53f43

File tree

2 files changed

+59
-19
lines changed

2 files changed

+59
-19
lines changed

rpc_proxy.go

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

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

627-
return nil
628-
}
626+
case p.permsMgr.IsSubServerURI(subservers.LIT, requestURI):
627+
system = subservers.LIT
629628

630-
// Check that the sub-server manager does have a sub-server registered
631-
// that can handle the given URI.
632-
handled, system := p.subServerMgr.Handles(requestURI)
633-
if !handled {
629+
case p.permsMgr.IsSubServerURI(subservers.LND, requestURI):
630+
system = subservers.LND
631+
632+
default:
634633
return fmt.Errorf("unknown gRPC web request: %v", requestURI)
635634
}
636635

terminal.go

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,10 @@ func (g *LightningTerminal) Run() error {
232232
return fmt.Errorf("could not create permissions manager")
233233
}
234234

235+
// Register LND and LiT with the status manager.
236+
g.statusMgr.RegisterAndEnableSubServer(subservers.LND)
237+
g.statusMgr.RegisterAndEnableSubServer(subservers.LIT)
238+
235239
// Create the instances of our subservers now so we can hook them up to
236240
// lnd once it's fully started.
237241
g.subServerMgr = subservers.NewManager(g.permsMgr, g.statusMgr)
@@ -273,8 +277,9 @@ func (g *LightningTerminal) Run() error {
273277
// could not start or LND could not start or be connected to.
274278
startErr := g.start()
275279
if startErr != nil {
276-
log.Errorf("Error starting Lightning Terminal: %v", startErr)
277-
return startErr
280+
g.statusMgr.SetErrored(
281+
subservers.LIT, "could not start Lit: %v", startErr,
282+
)
278283
}
279284

280285
// Now block until we receive an error or the main shutdown
@@ -447,8 +452,13 @@ func (g *LightningTerminal) start() error {
447452
if e, ok := err.(*flags.Error); err != nil &&
448453
(!ok || e.Type != flags.ErrHelp) {
449454

450-
log.Errorf("Error running main lnd: %v", err)
455+
errStr := fmt.Sprintf("Error running main "+
456+
"lnd: %v", err)
457+
log.Errorf(errStr)
458+
459+
g.statusMgr.SetErrored(subservers.LND, errStr)
451460
g.errQueue.ChanIn() <- err
461+
452462
return
453463
}
454464

@@ -474,10 +484,18 @@ func (g *LightningTerminal) start() error {
474484
case <-readyChan:
475485

476486
case err := <-g.errQueue.ChanOut():
477-
return err
487+
g.statusMgr.SetErrored(
488+
subservers.LND, "error from errQueue channel",
489+
)
490+
491+
return fmt.Errorf("could not start LND: %v", err)
478492

479493
case <-lndQuit:
480-
return nil
494+
g.statusMgr.SetErrored(
495+
subservers.LND, "lndQuit channel closed",
496+
)
497+
498+
return fmt.Errorf("LND has stopped")
481499

482500
case <-interceptor.ShutdownChannel():
483501
return fmt.Errorf("received the shutdown signal")
@@ -507,6 +525,10 @@ func (g *LightningTerminal) start() error {
507525
// Connect to LND.
508526
g.lndConn, err = connectLND(g.cfg, bufRpcListener)
509527
if err != nil {
528+
g.statusMgr.SetErrored(
529+
subservers.LND, "could not connect to LND: %v", err,
530+
)
531+
510532
return fmt.Errorf("could not connect to LND")
511533
}
512534

@@ -537,6 +559,11 @@ func (g *LightningTerminal) start() error {
537559
err)
538560
}
539561

562+
// We can now set the status of LND as running.
563+
// This is done _before_ we wait for the macaroon so that
564+
// LND commands to create and unlock a wallet can be allowed.
565+
g.statusMgr.SetRunning(subservers.LND)
566+
540567
// Now that we have started the main UI web server, show some useful
541568
// information to the user so they can access the web UI easily.
542569
if err := g.showStartupInfo(); err != nil {
@@ -556,7 +583,11 @@ func (g *LightningTerminal) start() error {
556583
return err
557584

558585
case <-lndQuit:
559-
return nil
586+
g.statusMgr.SetErrored(
587+
subservers.LND, "lndQuit channel closed",
588+
)
589+
590+
return fmt.Errorf("LND has stopped")
560591

561592
case <-interceptor.ShutdownChannel():
562593
return fmt.Errorf("received the shutdown signal")
@@ -592,8 +623,11 @@ func (g *LightningTerminal) start() error {
592623
// Set up all the LND clients required by LiT.
593624
err = g.setUpLNDClients()
594625
if err != nil {
595-
log.Errorf("Could not set up LND clients: %v", err)
596-
return err
626+
g.statusMgr.SetErrored(
627+
subservers.LND, "could not set up LND clients: %v", err,
628+
)
629+
630+
return fmt.Errorf("could not start LND")
597631
}
598632

599633
// If we're in integrated and stateless init mode, we won't create
@@ -622,6 +656,9 @@ func (g *LightningTerminal) start() error {
622656
return fmt.Errorf("could not start litd sub-servers: %v", err)
623657
}
624658

659+
// We can now set the status of LiT as running.
660+
g.statusMgr.SetRunning(subservers.LIT)
661+
625662
// Now block until we receive an error or the main shutdown signal.
626663
select {
627664
case err := <-g.errQueue.ChanOut():
@@ -631,7 +668,11 @@ func (g *LightningTerminal) start() error {
631668
}
632669

633670
case <-lndQuit:
634-
return nil
671+
g.statusMgr.SetErrored(
672+
subservers.LND, "lndQuit channel closed",
673+
)
674+
675+
return fmt.Errorf("LND is not running")
635676

636677
case <-interceptor.ShutdownChannel():
637678
log.Infof("Shutdown signal received")

0 commit comments

Comments
 (0)