Skip to content

Commit 945fffe

Browse files
committed
terminal+rpc_proxy: fix gRPC daemon calls in integrated mode
The call flow diagram wasn't accurate what lead to an incorrect assumption in the last PR. In integrated mode, lnd spins up its gRPC server as the main entry point and the other daemons need to hook into it.
1 parent 2481028 commit 945fffe

File tree

2 files changed

+50
-54
lines changed

2 files changed

+50
-54
lines changed

rpc_proxy.go

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -100,22 +100,25 @@ func newRpcProxy(cfg *Config, validator macaroons.MacaroonValidator,
100100
// +---+----------------------+
101101
// |
102102
// v native gRPC call with macaroon
103-
// +---+----------------------+ registered call
104-
// | gRPC server +--------------+
105-
// +---+----------------------+ |
106-
// | |
107-
// v non-registered call |
108-
// +---+----------------------+ +---------v----------+
109-
// | director | | local subserver |
110-
// +---+----------------------+ | - faraday |
111-
// | | - loop |
112-
// v authenticated call | - pool |
113-
// +---+----------------------+ +--------------------+
114-
// | lnd (remote or local) |
115-
// | faraday remote |
116-
// | loop remote |
117-
// | pool remote |
118-
// +--------------------------+
103+
// +---+----------------------+
104+
// | gRPC server |
105+
// +---+----------------------+
106+
// |
107+
// v unknown authenticated call, gRPC server is just a wrapper
108+
// +---+----------------------+
109+
// | director |
110+
// +---+----------------------+
111+
// |
112+
// v authenticated call
113+
// +---+----------------------+ call to lnd or integrated daemon
114+
// | lnd (remote or local) +---------------+
115+
// | faraday remote | |
116+
// | loop remote | +----------v----------+
117+
// | pool remote | | lnd local subserver |
118+
// +--------------------------+ | - faraday |
119+
// | - loop |
120+
// | - pool |
121+
// +---------------------+
119122
//
120123
type rpcProxy struct {
121124
cfg *Config
@@ -263,16 +266,13 @@ func (p *rpcProxy) director(ctx context.Context,
263266

264267
outCtx := metadata.NewOutgoingContext(ctx, mdCopy)
265268

266-
// Direct the call to the correct backend. For lnd we _always_ have a
267-
// client connection, no matter if it's running in integrated or remote
268-
// mode. For all other daemons the request shouldn't get here in
269-
// integrated mode (after all, the director only picks up calls that the
270-
// gRPC server itself would throw a 404 for) so we throw an error
271-
// message for them if they're not in remote mode.
269+
// Direct the call to the correct backend. All gRPC calls end up here
270+
// since our gRPC server instance doesn't have any handlers registered
271+
// itself. So all daemon calls that are remote are forwarded to them
272+
// directly. Everything else will go to lnd since it must either be an
273+
// lnd call or something that'll be handled by the integrated daemons
274+
// that are hooking into lnd's gRPC server.
272275
switch {
273-
case isLndURI(requestURI):
274-
return outCtx, p.lndConn, nil
275-
276276
case isFaradayURI(requestURI) && p.cfg.faradayRemote:
277277
return outCtx, p.faradayConn, nil
278278

@@ -283,8 +283,7 @@ func (p *rpcProxy) director(ctx context.Context,
283283
return outCtx, p.poolConn, nil
284284

285285
default:
286-
return ctx, nil, fmt.Errorf("unknown gRPC web request: %v",
287-
requestURI)
286+
return outCtx, p.lndConn, nil
288287
}
289288
}
290289

terminal.go

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ type LightningTerminal struct {
6060
wg sync.WaitGroup
6161
lndErrChan chan error
6262

63-
lndClient *lndclient.GrpcLndServices
63+
lndClient *lndclient.GrpcLndServices
6464

6565
faradayServer *frdrpc.RPCServer
6666
faradayStarted bool
@@ -342,27 +342,21 @@ func (g *LightningTerminal) startSubservers() error {
342342
// called once lnd has initialized its main gRPC server instance. It gives the
343343
// daemons (or external subservers) the possibility to register themselves to
344344
// the same server instance.
345-
func (g *LightningTerminal) RegisterGrpcSubserver(_ *grpc.Server) error {
345+
func (g *LightningTerminal) RegisterGrpcSubserver(server *grpc.Server) error {
346346
// In remote mode the "director" of the RPC proxy will act as a catch-
347347
// all for any gRPC request that isn't known because we didn't register
348348
// any server for it. The director will then forward the request to the
349349
// remote service.
350350
if !g.cfg.faradayRemote {
351-
frdrpc.RegisterFaradayServerServer(
352-
g.rpcProxy.grpcServer, g.faradayServer,
353-
)
351+
frdrpc.RegisterFaradayServerServer(server, g.faradayServer)
354352
}
355353

356354
if !g.cfg.loopRemote {
357-
looprpc.RegisterSwapClientServer(
358-
g.rpcProxy.grpcServer, g.loopServer,
359-
)
355+
looprpc.RegisterSwapClientServer(server, g.loopServer)
360356
}
361357

362358
if !g.cfg.poolRemote {
363-
poolrpc.RegisterTraderServer(
364-
g.rpcProxy.grpcServer, g.poolServer,
365-
)
359+
poolrpc.RegisterTraderServer(server, g.poolServer)
366360
}
367361

368362
return nil
@@ -550,22 +544,25 @@ func (g *LightningTerminal) shutdown() error {
550544
// +---+----------------------+
551545
// |
552546
// v native gRPC call with macaroon
553-
// +---+----------------------+ registered call
554-
// | gRPC server +--------------+
555-
// +---+----------------------+ |
556-
// | |
557-
// v non-registered call |
558-
// +---+----------------------+ +---------v----------+
559-
// | director | | local subserver |
560-
// +---+----------------------+ | - faraday |
561-
// | | - loop |
562-
// v authenticated call | - pool |
563-
// +---+----------------------+ +--------------------+
564-
// | lnd (remote or local) |
565-
// | faraday remote |
566-
// | loop remote |
567-
// | pool remote |
568-
// +--------------------------+
547+
// +---+----------------------+
548+
// | gRPC server |
549+
// +---+----------------------+
550+
// |
551+
// v unknown authenticated call, gRPC server is just a wrapper
552+
// +---+----------------------+
553+
// | director |
554+
// +---+----------------------+
555+
// |
556+
// v authenticated call
557+
// +---+----------------------+ call to lnd or integrated daemon
558+
// | lnd (remote or local) +---------------+
559+
// | faraday remote | |
560+
// | loop remote | +----------v----------+
561+
// | pool remote | | lnd local subserver |
562+
// +--------------------------+ | - faraday |
563+
// | - loop |
564+
// | - pool |
565+
// +---------------------+
569566
//
570567
func (g *LightningTerminal) startMainWebServer() error {
571568
// Initialize the in-memory file server from the content compiled by

0 commit comments

Comments
 (0)