Skip to content

Commit 71fb8e5

Browse files
committed
rpc_proxy: prepare dialBackend to be more generic
As a preparation for using the dialBackend function for other daemons/backends as well, we rename it from dialLnd and add a name parameter for more specific logs.
1 parent a8a4da8 commit 71fb8e5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

rpc_proxy.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (p *rpcProxy) Start() error {
130130

131131
// Setup the connection to lnd.
132132
host, _, tlsPath, _ := p.cfg.lndConnectParams()
133-
p.lndConn, err = dialLnd(host, tlsPath)
133+
p.lndConn, err = dialBackend("lnd", host, tlsPath)
134134
if err != nil {
135135
return fmt.Errorf("could not dial lnd: %v", err)
136136
}
@@ -336,21 +336,20 @@ func (p *rpcProxy) basicAuthToMacaroon(ctx context.Context,
336336
return metadata.NewIncomingContext(ctx, md), nil
337337
}
338338

339-
// dialLnd connects to lnd through the given address and uses the given TLS
340-
// certificate to authenticate the connection.
341-
func dialLnd(dialAddr, tlsCertPath string) (*grpc.ClientConn, error) {
342-
339+
// dialBackend connects to a gRPC backend through the given address and uses the
340+
// given TLS certificate to authenticate the connection.
341+
func dialBackend(name, dialAddr, tlsCertPath string) (*grpc.ClientConn, error) {
343342
var opts []grpc.DialOption
344343
tlsConfig, err := credentials.NewClientTLSFromFile(tlsCertPath, "")
345344
if err != nil {
346-
return nil, fmt.Errorf("could not read lnd TLS cert %s: %v",
347-
tlsCertPath, err)
345+
return nil, fmt.Errorf("could not read %s TLS cert %s: %v",
346+
name, tlsCertPath, err)
348347
}
349348

350349
opts = append(
351350
opts,
352351

353-
// From the grpxProxy doc: This codec is *crucial* to the
352+
// From the grpcProxy doc: This codec is *crucial* to the
354353
// functioning of the proxy.
355354
grpc.WithCodec(grpcProxy.Codec()), // nolint
356355
grpc.WithTransportCredentials(tlsConfig),
@@ -361,10 +360,11 @@ func dialLnd(dialAddr, tlsCertPath string) (*grpc.ClientConn, error) {
361360
}),
362361
)
363362

364-
log.Infof("Dialing lnd gRPC server at %s", dialAddr)
363+
log.Infof("Dialing %s gRPC server at %s", name, dialAddr)
365364
cc, err := grpc.Dial(dialAddr, opts...)
366365
if err != nil {
367-
return nil, fmt.Errorf("failed dialing backend: %v", err)
366+
return nil, fmt.Errorf("failed dialing %s backend: %v", name,
367+
err)
368368
}
369369
return cc, nil
370370
}

0 commit comments

Comments
 (0)