Skip to content

Commit 6310eed

Browse files
committed
multi: init status manager
Initialise an instance of the status manager in LightningTerminal. Register its gRPC and REST endpoints and also add its method to the set of LiT whitelisted permissions.
1 parent 21525a5 commit 6310eed

File tree

5 files changed

+40
-12
lines changed

5 files changed

+40
-12
lines changed

litclient/jsoncallbacks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ var Registrations = []StubPackageRegistration{
5050
litrpc.RegisterAccountsJSONCallbacks,
5151
litrpc.RegisterAutopilotJSONCallbacks,
5252
litrpc.RegisterFirewallJSONCallbacks,
53+
litrpc.RegisterStatusJSONCallbacks,
5354
taprpc.RegisterTaprootAssetsJSONCallbacks,
5455
assetwalletrpc.RegisterAssetWalletJSONCallbacks,
5556
universerpc.RegisterUniverseJSONCallbacks,

log.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
1212
"github.com/lightninglabs/lightning-terminal/rules"
1313
"github.com/lightninglabs/lightning-terminal/session"
14+
"github.com/lightninglabs/lightning-terminal/status"
1415
"github.com/lightninglabs/lightning-terminal/subservers"
1516
"github.com/lightninglabs/loop/loopd"
1617
"github.com/lightninglabs/pool"
@@ -82,7 +83,7 @@ func SetupLoggers(root *build.RotatingLogWriter, intercept signal.Interceptor) {
8283
root, autopilotserver.Subsystem, intercept,
8384
autopilotserver.UseLogger,
8485
)
85-
86+
lnd.AddSubLogger(root, status.Subsystem, intercept, status.UseLogger)
8687
lnd.AddSubLogger(
8788
root, subservers.Subsystem, intercept, subservers.UseLogger,
8889
)

perms/permissions.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ var (
9494

9595
// whiteListedLitMethods is a map of all LiT's RPC methods that don't
9696
// require any macaroon authentication.
97-
whiteListedLitMethods = map[string]struct{}{}
97+
whiteListedLitMethods = map[string][]bakery.Op{
98+
// The Status service must be available at all times, even
99+
// before we can check macaroons, so we whitelist it.
100+
"/litrpc.Status/SubServerStatus": {},
101+
}
98102

99103
// lndSubServerNameToTag is a map from the name of an LND subserver to
100104
// the name of the LND tag that corresponds to the subserver. This map

rpc_proxy.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ func (p *rpcProxy) UnaryServerInterceptor(ctx context.Context, req interface{},
375375
info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{},
376376
error) {
377377

378-
if !p.hasStarted() {
378+
if !p.hasStarted() && !isStatusReq(info.FullMethod) {
379379
return nil, ErrWaitingToStart
380380
}
381381

@@ -419,7 +419,7 @@ func (p *rpcProxy) StreamServerInterceptor(srv interface{},
419419
ss grpc.ServerStream, info *grpc.StreamServerInfo,
420420
handler grpc.StreamHandler) error {
421421

422-
if !p.hasStarted() {
422+
if !p.hasStarted() && !isStatusReq(info.FullMethod) {
423423
return ErrWaitingToStart
424424
}
425425

@@ -630,3 +630,11 @@ func isGrpcRequest(req *http.Request) bool {
630630
return req.ProtoMajor == 2 &&
631631
strings.HasPrefix(contentType, contentTypeGrpc)
632632
}
633+
634+
// isStatusReq returns true if the given request is intended for the
635+
// litrpc.Status service.
636+
func isStatusReq(uri string) bool {
637+
return strings.HasPrefix(
638+
uri, fmt.Sprintf("/%s", litrpc.Status_ServiceDesc.ServiceName),
639+
)
640+
}

terminal.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
mid "github.com/lightninglabs/lightning-terminal/rpcmiddleware"
3131
"github.com/lightninglabs/lightning-terminal/rules"
3232
"github.com/lightninglabs/lightning-terminal/session"
33+
"github.com/lightninglabs/lightning-terminal/status"
3334
"github.com/lightninglabs/lightning-terminal/subservers"
3435
"github.com/lightninglabs/lndclient"
3536
"github.com/lightningnetwork/lnd"
@@ -161,6 +162,7 @@ type LightningTerminal struct {
161162
basicClient lnrpc.LightningClient
162163

163164
subServerMgr *subservers.Manager
165+
statusMgr *status.Manager
164166

165167
autopilotClient autopilotserver.Autopilot
166168

@@ -193,7 +195,9 @@ type LightningTerminal struct {
193195

194196
// New creates a new instance of the lightning-terminal daemon.
195197
func New() *LightningTerminal {
196-
return &LightningTerminal{}
198+
return &LightningTerminal{
199+
statusMgr: status.NewStatusManager(),
200+
}
197201
}
198202

199203
// Run starts everything and then blocks until either the application is shut
@@ -245,6 +249,7 @@ func (g *LightningTerminal) Run() error {
245249
// Register any gRPC services that should be served using LiT's
246250
// gRPC server regardless of the LND mode being used.
247251
litrpc.RegisterProxyServer(g.rpcProxy.grpcServer, g.rpcProxy)
252+
litrpc.RegisterStatusServer(g.rpcProxy.grpcServer, g.statusMgr)
248253

249254
// Start the main web server that dispatches requests either to the
250255
// static UI file server or the RPC proxy. This makes it possible to
@@ -385,7 +390,7 @@ func (g *LightningTerminal) start() error {
385390
),
386391
},
387392
registerGrpcServers: func(server *grpc.Server) {
388-
g.registerSubDaemonGrpcServers(server, false)
393+
g.registerSubDaemonGrpcServers(server, true)
389394
},
390395
superMacBaker: superMacBaker,
391396
firstConnectionDeadline: g.cfg.FirstLNCConnDeadline,
@@ -901,22 +906,24 @@ func (g *LightningTerminal) RegisterGrpcSubserver(server *grpc.Server) error {
901906

902907
// Register all other daemon RPC servers that are running in-process.
903908
// The LiT session server should be enabled on the main interface.
904-
g.registerSubDaemonGrpcServers(server, true)
909+
g.registerSubDaemonGrpcServers(server, false)
905910

906911
return nil
907912
}
908913

909914
// registerSubDaemonGrpcServers registers the sub daemon (Faraday, Loop, Pool
910915
// and LiT session) servers to a given gRPC server, given they are running in
911-
// the local process. The lit session server is gated by its own boolean because
912-
// we don't necessarily want to expose it on all listeners, given its security
913-
// implications.
916+
// the local process. Some of LiT's own sub-servers should be registered with
917+
// LNC sessions and some should not - the forLNCSession boolean can be used to
918+
// control this.
914919
func (g *LightningTerminal) registerSubDaemonGrpcServers(server *grpc.Server,
915-
withLitRPC bool) {
920+
forLNCSession bool) {
916921

917922
g.subServerMgr.RegisterRPCServices(server)
918923

919-
if withLitRPC {
924+
if forLNCSession {
925+
litrpc.RegisterStatusServer(server, g.statusMgr)
926+
} else {
920927
litrpc.RegisterSessionsServer(server, g.sessionRpcServer)
921928
litrpc.RegisterAccountsServer(server, g.accountRpcServer)
922929
}
@@ -980,6 +987,13 @@ func (g *LightningTerminal) RegisterRestSubserver(ctx context.Context,
980987
return err
981988
}
982989

990+
err = litrpc.RegisterStatusHandlerFromEndpoint(
991+
ctx, mux, endpoint, dialOpts,
992+
)
993+
if err != nil {
994+
return err
995+
}
996+
983997
return g.subServerMgr.RegisterRestServices(ctx, mux, endpoint, dialOpts)
984998
}
985999

0 commit comments

Comments
 (0)