|
65 | 65 | // start an lnd node then start and register external subservers to it.
|
66 | 66 | type LightningTerminal struct {
|
67 | 67 | cfg *Config
|
68 |
| - lndAddr string |
69 | 68 | listenerCfg lnd.ListenerCfg
|
70 | 69 |
|
71 | 70 | wg sync.WaitGroup
|
@@ -148,33 +147,6 @@ func (g *LightningTerminal) Run() error {
|
148 | 147 | },
|
149 | 148 | }
|
150 | 149 |
|
151 |
| - // With TLS enabled by default, we cannot call 0.0.0.0 internally when |
152 |
| - // dialing lnd as that IP address isn't in the cert. We need to rewrite |
153 |
| - // it to the loopback address. |
154 |
| - lndDialAddr := rpcAddr.String() |
155 |
| - switch { |
156 |
| - case strings.Contains(lndDialAddr, "0.0.0.0"): |
157 |
| - lndDialAddr = strings.Replace( |
158 |
| - lndDialAddr, "0.0.0.0", "127.0.0.1", 1, |
159 |
| - ) |
160 |
| - |
161 |
| - case strings.Contains(lndDialAddr, "[::]"): |
162 |
| - lndDialAddr = strings.Replace( |
163 |
| - lndDialAddr, "[::]", "[::1]", 1, |
164 |
| - ) |
165 |
| - } |
166 |
| - g.lndAddr = lndDialAddr |
167 |
| - |
168 |
| - // Some of the subservers' configuration options won't have any effect |
169 |
| - // (like the log or lnd options) as they will be taken from lnd's config |
170 |
| - // struct. Others we want to force to be the same as lnd so the user |
171 |
| - // doesn't have to set them manually, like the network for example. |
172 |
| - network, err := getNetwork(g.cfg.Lnd.Bitcoin) |
173 |
| - if err != nil { |
174 |
| - return err |
175 |
| - } |
176 |
| - g.cfg.Loop.Network = network |
177 |
| - |
178 | 150 | // Create the instances of our subservers now so we can hook them up to
|
179 | 151 | // lnd once it's fully started.
|
180 | 152 | g.faradayServer = frdrpc.NewRPCServer(&frdrpc.Config{})
|
@@ -216,7 +188,7 @@ func (g *LightningTerminal) Run() error {
|
216 | 188 | case <-signal.ShutdownChannel():
|
217 | 189 | return errors.New("shutting down")
|
218 | 190 | }
|
219 |
| - err = g.startSubservers(network) |
| 191 | + err = g.startSubservers() |
220 | 192 | if err != nil {
|
221 | 193 | log.Errorf("Could not start subservers: %v", err)
|
222 | 194 | return err
|
@@ -253,25 +225,36 @@ func (g *LightningTerminal) Run() error {
|
253 | 225 | // startSubservers creates an internal connection to lnd and then starts all
|
254 | 226 | // embedded daemons as external subservers that hook into the same gRPC and REST
|
255 | 227 | // servers that lnd started.
|
256 |
| -func (g *LightningTerminal) startSubservers(network string) error { |
| 228 | +func (g *LightningTerminal) startSubservers() error { |
257 | 229 | var basicClient lnrpc.LightningClient
|
258 | 230 |
|
| 231 | + host, network, tlsPath, macPath, err := g.cfg.lndConnectParams() |
| 232 | + if err != nil { |
| 233 | + return err |
| 234 | + } |
| 235 | + |
| 236 | + // Some of the subservers' configuration options won't have any effect |
| 237 | + // (like the log or lnd options) as they will be taken from lnd's config |
| 238 | + // struct. Others we want to force to be the same as lnd so the user |
| 239 | + // doesn't have to set them manually, like the network for example. |
| 240 | + g.cfg.Loop.Network = string(network) |
| 241 | + if err := loopd.Validate(g.cfg.Loop); err != nil { |
| 242 | + return err |
| 243 | + } |
| 244 | + |
259 | 245 | // The main RPC listener of lnd might need some time to start, it could
|
260 | 246 | // be that we run into a connection refused a few times. We use the
|
261 | 247 | // basic client connection to find out if the RPC server is started yet
|
262 | 248 | // because that doesn't do anything else than just connect. We'll check
|
263 | 249 | // if lnd is also ready to be used in the next step.
|
264 |
| - err := wait.NoError(func() error { |
| 250 | + err = wait.NoError(func() error { |
265 | 251 | // Create an lnd client now that we have the full configuration.
|
266 | 252 | // We'll need a basic client and a full client because not all
|
267 | 253 | // subservers have the same requirements.
|
268 | 254 | var err error
|
269 | 255 | basicClient, err = lndclient.NewBasicClient(
|
270 |
| - g.lndAddr, g.cfg.Lnd.TLSCertPath, |
271 |
| - filepath.Dir(g.cfg.Lnd.AdminMacPath), network, |
272 |
| - lndclient.MacFilename(filepath.Base( |
273 |
| - g.cfg.Lnd.AdminMacPath, |
274 |
| - )), |
| 256 | + host, tlsPath, filepath.Dir(macPath), string(network), |
| 257 | + lndclient.MacFilename(filepath.Base(macPath)), |
275 | 258 | )
|
276 | 259 | return err
|
277 | 260 | }, defaultStartupTimeout)
|
@@ -304,12 +287,10 @@ func (g *LightningTerminal) startSubservers(network string) error {
|
304 | 287 | }()
|
305 | 288 | g.lndClient, err = lndclient.NewLndServices(
|
306 | 289 | &lndclient.LndServicesConfig{
|
307 |
| - LndAddress: g.lndAddr, |
308 |
| - Network: lndclient.Network(network), |
309 |
| - MacaroonDir: filepath.Dir( |
310 |
| - g.cfg.Lnd.AdminMacPath, |
311 |
| - ), |
312 |
| - TLSPath: g.cfg.Lnd.TLSCertPath, |
| 290 | + LndAddress: host, |
| 291 | + Network: network, |
| 292 | + MacaroonDir: filepath.Dir(macPath), |
| 293 | + TLSPath: tlsPath, |
313 | 294 | BlockUntilChainSynced: true,
|
314 | 295 | ChainSyncCtx: ctxc,
|
315 | 296 | },
|
@@ -429,7 +410,7 @@ func (g *LightningTerminal) startGrpcWebProxy() error {
|
429 | 410 | // admin macaroon and converts the browser's gRPC web calls into native
|
430 | 411 | // gRPC.
|
431 | 412 | lndGrpcServer, grpcServer, err := buildGrpcWebProxyServer(
|
432 |
| - g.lndAddr, g.cfg.UIPassword, g.cfg.Lnd, |
| 413 | + g.cfg.Lnd.RPCListeners[0].String(), g.cfg.UIPassword, g.cfg.Lnd, |
433 | 414 | )
|
434 | 415 | if err != nil {
|
435 | 416 | return fmt.Errorf("could not create gRPC web proxy: %v", err)
|
|
0 commit comments