@@ -236,6 +236,8 @@ func New() *LightningTerminal {
236236// Run starts everything and then blocks until either the application is shut
237237// down or a critical error happens.
238238func (g * LightningTerminal ) Run () error {
239+ ctx := context .TODO ()
240+
239241 // Hook interceptor for os signals.
240242 shutdownInterceptor , err := signal .Intercept ()
241243 if err != nil {
@@ -345,15 +347,15 @@ func (g *LightningTerminal) Run() error {
345347 // We'll also create a REST proxy that'll convert any REST calls to gRPC
346348 // calls and forward them to the internal listener.
347349 if g .cfg .EnableREST {
348- if err := g .createRESTProxy (); err != nil {
350+ if err := g .createRESTProxy (ctx ); err != nil {
349351 return fmt .Errorf ("error creating REST proxy: %v" , err )
350352 }
351353 }
352354
353355 // Attempt to start Lit and all of its sub-servers. If an error is
354356 // returned, it means that either one of Lit's internal sub-servers
355357 // could not start or LND could not start or be connected to.
356- startErr := g .start ()
358+ startErr := g .start (ctx )
357359 if startErr != nil {
358360 g .statusMgr .SetErrored (
359361 subservers .LIT , "could not start Lit: %v" , startErr ,
@@ -380,7 +382,7 @@ func (g *LightningTerminal) Run() error {
380382// If any of the sub-servers managed by the subServerMgr error while starting
381383// up, these are considered non-fatal and will not result in an error being
382384// returned.
383- func (g * LightningTerminal ) start () error {
385+ func (g * LightningTerminal ) start (ctx context. Context ) error {
384386 var err error
385387
386388 accountServiceErrCallback := func (err error ) {
@@ -658,7 +660,7 @@ func (g *LightningTerminal) start() error {
658660
659661 // Now that we have started the main UI web server, show some useful
660662 // 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 {
662664 return fmt .Errorf ("error displaying startup info: %v" , err )
663665 }
664666
@@ -713,7 +715,7 @@ func (g *LightningTerminal) start() error {
713715 }
714716
715717 // Set up all the LND clients required by LiT.
716- err = g .setUpLNDClients (lndQuit )
718+ err = g .setUpLNDClients (ctx , lndQuit )
717719 if err != nil {
718720 g .statusMgr .SetErrored (
719721 subservers .LND , "could not set up LND clients: %v" , err ,
@@ -773,7 +775,9 @@ func (g *LightningTerminal) basicLNDClient() (lnrpc.LightningClient, error) {
773775}
774776
775777// 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+
777781 var (
778782 err error
779783 insecure bool
@@ -873,7 +877,7 @@ func (g *LightningTerminal) setUpLNDClients(lndQuit chan struct{}) error {
873877 // subservers. This will just block until lnd signals readiness. But we
874878 // still want to react to shutdown requests, so we need to listen for
875879 // those.
876- ctxc , cancel := context .WithCancel (context . Background () )
880+ ctxc , cancel := context .WithCancel (ctx )
877881 defer cancel ()
878882
879883 // Make sure the context is canceled if the user requests shutdown.
@@ -940,7 +944,6 @@ func (g *LightningTerminal) setUpLNDClients(lndQuit chan struct{}) error {
940944 // Create a super macaroon that can be used to control lnd,
941945 // faraday, loop, and pool, all at the same time.
942946 log .Infof ("Baking internal super macaroon" )
943- ctx := context .Background ()
944947 superMacaroon , err := BakeSuperMacaroon (
945948 ctx , g .basicClient , session .NewSuperMacaroonRootKeyID (
946949 [4 ]byte {},
@@ -1657,7 +1660,7 @@ func (g *LightningTerminal) startMainWebServer() error {
16571660// createRESTProxy creates a grpc-gateway based REST proxy that takes any call
16581661// identified as a REST call, converts it to a gRPC request and forwards it to
16591662// our local main server for further triage/forwarding.
1660- func (g * LightningTerminal ) createRESTProxy () error {
1663+ func (g * LightningTerminal ) createRESTProxy (ctx context. Context ) error {
16611664 // The default JSON marshaler of the REST proxy only sets OrigName to
16621665 // true, which instructs it to use the same field names as specified in
16631666 // the proto file and not switch to camel case. What we also want is
@@ -1700,7 +1703,7 @@ func (g *LightningTerminal) createRESTProxy() error {
17001703 // wildcard to prevent certificate issues when accessing the proxy
17011704 // externally.
17021705 restMux := restProxy .NewServeMux (customMarshalerOption )
1703- ctx , cancel := context .WithCancel (context . Background () )
1706+ ctx , cancel := context .WithCancel (ctx )
17041707 g .restCancel = cancel
17051708
17061709 // Enable WebSocket and CORS support as well. A request will pass
@@ -1926,7 +1929,7 @@ func allowCORS(handler http.Handler, origins []string) http.Handler {
19261929
19271930// showStartupInfo shows useful information to the user to easily access the
19281931// web UI that was just started.
1929- func (g * LightningTerminal ) showStartupInfo () error {
1932+ func (g * LightningTerminal ) showStartupInfo (ctx context. Context ) error {
19301933 info := struct {
19311934 mode string
19321935 status string
@@ -1958,7 +1961,6 @@ func (g *LightningTerminal) showStartupInfo() error {
19581961 return fmt .Errorf ("error querying remote node: %v" , err )
19591962 }
19601963
1961- ctx := context .Background ()
19621964 res , err := basicClient .GetInfo (ctx , & lnrpc.GetInfoRequest {})
19631965 if err != nil {
19641966 if ! lndclient .IsUnlockError (err ) {
0 commit comments