Skip to content

Commit 30262f2

Browse files
ellemoutonpositiveblue
authored andcommitted
terminal: start the webserver as soon as possible
Since all the relevant dependancies have been accouted for, we know move the starting of the main webserver to earlier on in the Run function. This is in preparation for later when the webserver will be "always-on" and will be used to server status information about the rest of the LiT subservers.
1 parent 7166877 commit 30262f2

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

terminal.go

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,31 @@ func (g *LightningTerminal) Run() error {
238238
return fmt.Errorf("could not create permissions manager")
239239
}
240240

241+
// Construct the rpcProxy. It must be initialised before the main web
242+
// server is started.
243+
g.rpcProxy = newRpcProxy(g.cfg, g, g.validateSuperMacaroon, g.permsMgr)
244+
245+
// Start the main web server that dispatches requests either to the
246+
// static UI file server or the RPC proxy. This makes it possible to
247+
// unlock lnd through the UI.
248+
if err := g.startMainWebServer(); err != nil {
249+
return fmt.Errorf("error starting main proxy HTTP server: %v",
250+
err)
251+
}
252+
253+
// We'll also create a REST proxy that'll convert any REST calls to gRPC
254+
// calls and forward them to the internal listener.
255+
if g.cfg.EnableREST {
256+
if err := g.createRESTProxy(); err != nil {
257+
return fmt.Errorf("error creating REST proxy: %v", err)
258+
}
259+
}
260+
241261
// Create the instances of our subservers now so we can hook them up to
242262
// lnd once it's fully started.
243-
bufRpcListener := bufconn.Listen(100)
244263
g.faradayServer = frdrpcserver.NewRPCServer(g.cfg.faradayRpcConfig)
245264
g.loopServer = loopd.New(g.cfg.Loop, nil)
246265
g.poolServer = pool.NewServer(g.cfg.Pool)
247-
g.rpcProxy = newRpcProxy(
248-
g.cfg, g, g.validateSuperMacaroon, g.permsMgr,
249-
)
250266
g.accountService, err = accounts.NewService(
251267
filepath.Dir(g.cfg.MacaroonPath), g.errQueue.ChanIn(),
252268
)
@@ -345,12 +361,14 @@ func (g *LightningTerminal) Run() error {
345361

346362
// Call the "real" main in a nested manner so the defers will properly
347363
// be executed in the case of a graceful shutdown.
348-
readyChan := make(chan struct{})
349-
bufReadyChan := make(chan struct{})
350-
unlockChan := make(chan struct{})
351-
lndQuit := make(chan struct{})
352-
macChan := make(chan []byte, 1)
353-
364+
var (
365+
bufRpcListener = bufconn.Listen(100)
366+
readyChan = make(chan struct{})
367+
bufReadyChan = make(chan struct{})
368+
unlockChan = make(chan struct{})
369+
lndQuit = make(chan struct{})
370+
macChan = make(chan []byte, 1)
371+
)
354372
if g.cfg.LndMode == ModeIntegrated {
355373
lisCfg := lnd.ListenerCfg{
356374
RPCListeners: []*lnd.ListenerWithSignal{{
@@ -399,14 +417,6 @@ func (g *LightningTerminal) Run() error {
399417
_ = g.RegisterGrpcSubserver(g.rpcProxy.grpcServer)
400418
}
401419

402-
// We'll also create a REST proxy that'll convert any REST calls to gRPC
403-
// calls and forward them to the internal listener.
404-
if g.cfg.EnableREST {
405-
if err := g.createRESTProxy(); err != nil {
406-
return fmt.Errorf("error creating REST proxy: %v", err)
407-
}
408-
}
409-
410420
// Wait for lnd to be started up so we know we have a TLS cert.
411421
select {
412422
// If lnd needs to be unlocked we get the signal that it's ready to do
@@ -444,16 +454,11 @@ func (g *LightningTerminal) Run() error {
444454
}
445455

446456
// Now start the RPC proxy that will handle all incoming gRPC, grpc-web
447-
// and REST requests. We also start the main web server that dispatches
448-
// requests either to the static UI file server or the RPC proxy. This
449-
// makes it possible to unlock lnd through the UI.
457+
// and REST requests.
450458
if err := g.rpcProxy.Start(g.lndConn); err != nil {
451459
return fmt.Errorf("error starting lnd gRPC proxy server: %v",
452460
err)
453461
}
454-
if err := g.startMainWebServer(); err != nil {
455-
return fmt.Errorf("error starting UI HTTP server: %v", err)
456-
}
457462

458463
// Now that we have started the main UI web server, show some useful
459464
// information to the user so they can access the web UI easily.

0 commit comments

Comments
 (0)