Skip to content

Commit 16bad21

Browse files
authored
Merge pull request #189 from lightninglabs/lnd-grpc-server-fix
Fix main lnd port usage for daemons in lnd-mode=integrated
2 parents 2481028 + a09e56f commit 16bad21

File tree

3 files changed

+139
-54
lines changed

3 files changed

+139
-54
lines changed

doc/testing.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Test scenarios
2+
3+
The possible number of combinations of local/remote configurations has become
4+
quite large over time.
5+
6+
The following tests should be run whenever something in the local/remote config
7+
or proxying changes:
8+
9+
## `lnd` integrated
10+
11+
### All daemons integrated
12+
13+
```shell
14+
--httpslisten=[::]:8443
15+
--uipassword=testnet3
16+
--network=regtest
17+
--lnd-mode=integrated
18+
...
19+
```
20+
21+
1. Open UI, make sure Loop and Pool calls are served correctly
22+
2. Use `lncli` against LiT
23+
`lncli --network regtest getinfo`
24+
3. Use `pool` and `loop` CLI against `lnd` main gRPC server (port `10009`)
25+
- `loop --rpcserver=localhost:10009 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.loop/regtest/loop.macaroon terms`
26+
- `pool --rpcserver=localhost:10009 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.pool/regtest/pool.macaroon getinfo`
27+
4. Use `pool` and `loop` CLI against LiT proxy server (port `8443`)
28+
- `loop --rpcserver=localhost:8443 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.loop/regtest/loop.macaroon terms`
29+
- `pool --rpcserver=localhost:8443 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.pool/regtest/pool.macaroon getinfo`
30+
31+
### Loop daemon remote
32+
33+
```shell
34+
--httpslisten=[::]:8443
35+
--uipassword=testnet3
36+
--network=regtest
37+
--lnd-mode=integrated
38+
--loop-mode=remote
39+
...
40+
```
41+
42+
1. Open UI, make sure Loop and Pool calls are served correctly
43+
2. Use `lncli` against LiT
44+
`lncli --network regtest getinfo`
45+
3. Use `pool` and `loop` CLI against `lnd` main gRPC server (port `10009`)
46+
- `loop --rpcserver=localhost:10009 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.loop/regtest/loop.macaroon terms`
47+
**Expect to get an `unknown service` error!**
48+
- `pool --rpcserver=localhost:10009 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.pool/regtest/pool.macaroon getinfo`
49+
**Expect to get an `unknown service` error!**
50+
4. Use `pool` and `loop` CLI against LiT proxy server (port `8443`)
51+
- `loop --rpcserver=localhost:8443 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.loop/regtest/loop.macaroon terms`
52+
- `pool --rpcserver=localhost:8443 --tlscertpath=~/.lnd/tls.cert --macaroonpath=~/.pool/regtest/pool.macaroon getinfo`
53+
54+
## `lnd` remote
55+
56+
### All daemons integrated
57+
58+
```shell
59+
--httpslisten=[::]:8443
60+
--uipassword=testnet3
61+
--network=regtest
62+
--remote.lnd.rpcserver=localhost:10009
63+
...
64+
```
65+
66+
1. Open UI, make sure Loop and Pool calls are served correctly
67+
2. Use `lncli` against LiT
68+
`lncli --network regtest --rpcserver=localhost:8443 --tlscertpath=~/.lit/tls.cert --macaroonpath=~/.lnd/data/chain/bitcoin/regtest/admin.macaroon getinfo`
69+
3. Use `pool` and `loop` CLI against LiT proxy server (port `8443`)
70+
- `loop --rpcserver=localhost:8443 --tlscertpath=~/.lit/tls.cert --macaroonpath=~/.loop/regtest/loop.macaroon terms`
71+
- `pool --rpcserver=localhost:8443 --tlscertpath=~/.lit/tls.cert --macaroonpath=~/.pool/regtest/pool.macaroon getinfo`
72+
73+
### Loop daemon remote
74+
75+
```shell
76+
--httpslisten=[::]:8443
77+
--uipassword=testnet3
78+
--network=regtest
79+
--remote.lnd.rpcserver=localhost:10009
80+
--loop-mode=remote
81+
...
82+
```
83+
84+
1. Open UI, make sure Loop and Pool calls are served correctly
85+
2. Use `lncli` against LiT
86+
`lncli --network regtest --rpcserver=localhost:8443 --tlscertpath=~/.lit/tls.cert --macaroonpath=~/.lnd/data/chain/bitcoin/regtest/admin.macaroon getinfo`
87+
3. Use `pool` and `loop` CLI against LiT proxy server (port `8443`)
88+
- `loop --rpcserver=localhost:8443 --tlscertpath=~/.lit/tls.cert --macaroonpath=~/.loop/regtest/loop.macaroon terms`
89+
- `pool --rpcserver=localhost:8443 --tlscertpath=~/.lit/tls.cert --macaroonpath=~/.pool/regtest/pool.macaroon getinfo`

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)