@@ -236,6 +236,8 @@ func New() *LightningTerminal {
236
236
// Run starts everything and then blocks until either the application is shut
237
237
// down or a critical error happens.
238
238
func (g * LightningTerminal ) Run () error {
239
+ ctx := context .TODO ()
240
+
239
241
// Hook interceptor for os signals.
240
242
shutdownInterceptor , err := signal .Intercept ()
241
243
if err != nil {
@@ -345,15 +347,15 @@ func (g *LightningTerminal) Run() error {
345
347
// We'll also create a REST proxy that'll convert any REST calls to gRPC
346
348
// calls and forward them to the internal listener.
347
349
if g .cfg .EnableREST {
348
- if err := g .createRESTProxy (); err != nil {
350
+ if err := g .createRESTProxy (ctx ); err != nil {
349
351
return fmt .Errorf ("error creating REST proxy: %v" , err )
350
352
}
351
353
}
352
354
353
355
// Attempt to start Lit and all of its sub-servers. If an error is
354
356
// returned, it means that either one of Lit's internal sub-servers
355
357
// could not start or LND could not start or be connected to.
356
- startErr := g .start ()
358
+ startErr := g .start (ctx )
357
359
if startErr != nil {
358
360
g .statusMgr .SetErrored (
359
361
subservers .LIT , "could not start Lit: %v" , startErr ,
@@ -380,7 +382,7 @@ func (g *LightningTerminal) Run() error {
380
382
// If any of the sub-servers managed by the subServerMgr error while starting
381
383
// up, these are considered non-fatal and will not result in an error being
382
384
// returned.
383
- func (g * LightningTerminal ) start () error {
385
+ func (g * LightningTerminal ) start (ctx context. Context ) error {
384
386
var err error
385
387
386
388
accountServiceErrCallback := func (err error ) {
@@ -658,7 +660,7 @@ func (g *LightningTerminal) start() error {
658
660
659
661
// Now that we have started the main UI web server, show some useful
660
662
// information to the user so they can access the web UI easily.
661
- if err := g .showStartupInfo (); err != nil {
663
+ if err := g .showStartupInfo (ctx ); err != nil {
662
664
return fmt .Errorf ("error displaying startup info: %v" , err )
663
665
}
664
666
@@ -713,7 +715,7 @@ func (g *LightningTerminal) start() error {
713
715
}
714
716
715
717
// Set up all the LND clients required by LiT.
716
- err = g .setUpLNDClients (lndQuit )
718
+ err = g .setUpLNDClients (ctx , lndQuit )
717
719
if err != nil {
718
720
g .statusMgr .SetErrored (
719
721
subservers .LND , "could not set up LND clients: %v" , err ,
@@ -773,7 +775,9 @@ func (g *LightningTerminal) basicLNDClient() (lnrpc.LightningClient, error) {
773
775
}
774
776
775
777
// setUpLNDClients sets up the various LND clients required by LiT.
776
- func (g * LightningTerminal ) setUpLNDClients (lndQuit chan struct {}) error {
778
+ func (g * LightningTerminal ) setUpLNDClients (ctx context.Context ,
779
+ lndQuit chan struct {}) error {
780
+
777
781
var (
778
782
err error
779
783
insecure bool
@@ -873,7 +877,7 @@ func (g *LightningTerminal) setUpLNDClients(lndQuit chan struct{}) error {
873
877
// subservers. This will just block until lnd signals readiness. But we
874
878
// still want to react to shutdown requests, so we need to listen for
875
879
// those.
876
- ctxc , cancel := context .WithCancel (context . Background () )
880
+ ctxc , cancel := context .WithCancel (ctx )
877
881
defer cancel ()
878
882
879
883
// Make sure the context is canceled if the user requests shutdown.
@@ -940,7 +944,6 @@ func (g *LightningTerminal) setUpLNDClients(lndQuit chan struct{}) error {
940
944
// Create a super macaroon that can be used to control lnd,
941
945
// faraday, loop, and pool, all at the same time.
942
946
log .Infof ("Baking internal super macaroon" )
943
- ctx := context .Background ()
944
947
superMacaroon , err := BakeSuperMacaroon (
945
948
ctx , g .basicClient , session .NewSuperMacaroonRootKeyID (
946
949
[4 ]byte {},
@@ -1657,7 +1660,7 @@ func (g *LightningTerminal) startMainWebServer() error {
1657
1660
// createRESTProxy creates a grpc-gateway based REST proxy that takes any call
1658
1661
// identified as a REST call, converts it to a gRPC request and forwards it to
1659
1662
// our local main server for further triage/forwarding.
1660
- func (g * LightningTerminal ) createRESTProxy () error {
1663
+ func (g * LightningTerminal ) createRESTProxy (ctx context. Context ) error {
1661
1664
// The default JSON marshaler of the REST proxy only sets OrigName to
1662
1665
// true, which instructs it to use the same field names as specified in
1663
1666
// the proto file and not switch to camel case. What we also want is
@@ -1700,7 +1703,7 @@ func (g *LightningTerminal) createRESTProxy() error {
1700
1703
// wildcard to prevent certificate issues when accessing the proxy
1701
1704
// externally.
1702
1705
restMux := restProxy .NewServeMux (customMarshalerOption )
1703
- ctx , cancel := context .WithCancel (context . Background () )
1706
+ ctx , cancel := context .WithCancel (ctx )
1704
1707
g .restCancel = cancel
1705
1708
1706
1709
// Enable WebSocket and CORS support as well. A request will pass
@@ -1926,7 +1929,7 @@ func allowCORS(handler http.Handler, origins []string) http.Handler {
1926
1929
1927
1930
// showStartupInfo shows useful information to the user to easily access the
1928
1931
// web UI that was just started.
1929
- func (g * LightningTerminal ) showStartupInfo () error {
1932
+ func (g * LightningTerminal ) showStartupInfo (ctx context. Context ) error {
1930
1933
info := struct {
1931
1934
mode string
1932
1935
status string
@@ -1958,7 +1961,6 @@ func (g *LightningTerminal) showStartupInfo() error {
1958
1961
return fmt .Errorf ("error querying remote node: %v" , err )
1959
1962
}
1960
1963
1961
- ctx := context .Background ()
1962
1964
res , err := basicClient .GetInfo (ctx , & lnrpc.GetInfoRequest {})
1963
1965
if err != nil {
1964
1966
if ! lndclient .IsUnlockError (err ) {
0 commit comments