Skip to content

Commit

Permalink
terminal: retry to create lnd client on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorTigerstrom committed Dec 12, 2023
1 parent 7bc6eb2 commit e73cfb6
Showing 1 changed file with 49 additions and 29 deletions.
78 changes: 49 additions & 29 deletions terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnrpc/watchtowerrpc"
"github.com/lightningnetwork/lnd/lnrpc/wtclientrpc"
"github.com/lightningnetwork/lnd/lntest/wait"
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
"github.com/lightningnetwork/lnd/macaroons"
"github.com/lightningnetwork/lnd/rpcperms"
Expand Down Expand Up @@ -685,6 +684,7 @@ func (g *LightningTerminal) start() error {
// setUpLNDClients sets up the various LND clients required by LiT.
func (g *LightningTerminal) setUpLNDClients() error {
var (
err error
insecure bool
clientOptions []lndclient.BasicClientOption
)
Expand Down Expand Up @@ -712,19 +712,28 @@ func (g *LightningTerminal) setUpLNDClients() error {
// because that doesn't do anything else than just connect. We'll check
// if lnd is also ready to be used in the next step.
log.Infof("Connecting basic lnd client")
err := wait.NoError(func() error {
// Create an lnd client now that we have the full configuration.
// We'll need a basic client and a full client because not all
// subservers have the same requirements.
var err error

for {
// Create an lnd client now that we have the full
// configuration.
// We'll need a basic client and a full client because
// not all subservers have the same requirements.
g.basicClient, err = lndclient.NewBasicClient(
host, tlsPath, filepath.Dir(macPath), string(network),
clientOptions...,
host, tlsPath, filepath.Dir(macPath),
string(network), clientOptions...,
)
return err
}, defaultStartupTimeout)
if err != nil {
return fmt.Errorf("could not create basic LND Client: %v", err)
if err == nil {
log.Infof("Basic lnd client connected")

break
}

g.statusMgr.SetErrored(
subservers.LIT,
"Error when setting up basic LND Client: %v", err,
)

log.Infof("Retrying to connect basic lnd client")
}

// Now we know that the connection itself is ready. But we also need to
Expand Down Expand Up @@ -752,23 +761,34 @@ func (g *LightningTerminal) setUpLNDClients() error {
}()

log.Infof("Connecting full lnd client")
g.lndClient, err = lndclient.NewLndServices(
&lndclient.LndServicesConfig{
LndAddress: host,
Network: network,
TLSPath: tlsPath,
Insecure: insecure,
CustomMacaroonPath: macPath,
CustomMacaroonHex: hex.EncodeToString(macData),
BlockUntilChainSynced: true,
BlockUntilUnlocked: true,
CallerCtx: ctxc,
CheckVersion: minimalCompatibleVersion,
},
)
if err != nil {
return fmt.Errorf("could not create LND Services client: %v",
err)
for {
g.lndClient, err = lndclient.NewLndServices(
&lndclient.LndServicesConfig{
LndAddress: host,
Network: network,
TLSPath: tlsPath,
Insecure: insecure,
CustomMacaroonPath: macPath,
CustomMacaroonHex: hex.EncodeToString(macData),
BlockUntilChainSynced: true,
BlockUntilUnlocked: true,
CallerCtx: ctxc,
CheckVersion: minimalCompatibleVersion,
},
)
if err == nil {
log.Infof("Full lnd client connected")

break
}

g.statusMgr.SetErrored(
subservers.LIT,
"Error when creating LND Services client: %v",
err,
)

log.Infof("Retrying to create LND Services client")
}

// Pass LND's build tags to the permission manager so that it can
Expand Down

0 comments on commit e73cfb6

Please sign in to comment.