Skip to content

Commit

Permalink
multi: allow LNC reconnects without restarting the proxy
Browse files Browse the repository at this point in the history
LNC will automatically try to reconnect to the LND node whenever there
is an error.

Until now, losing the connection with the LND node made the proxy shut
down. When using LNC, we can simply log that we received an error and
let the library handle the reconnection.

Because we do not want to overheat the server when the backend lnd node is
down, we need to make sure that we add a timeout to the client calls.
  • Loading branch information
positiveblue committed Oct 19, 2023
1 parent aa9ca46 commit 281cbd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion aperture.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,18 @@ func (a *Aperture) Start(errChan chan error) error {
"session: %w", err)
}

// An LNC session will automatically try to reconnect to
// the node whenever an error occurs. Instead of
// shutting the proxy down we will just log the error.
lncErrChan := make(chan error)
go func() {
for err := range lncErrChan {
log.Errorf("lnc session error: %v", err)
}
}()

a.challenger, err = challenger.NewLNCChallenger(
session, lncStore, genInvoiceReq, errChan,
session, lncStore, genInvoiceReq, lncErrChan,
)
if err != nil {
return fmt.Errorf("unable to start lnc "+
Expand Down
11 changes: 10 additions & 1 deletion challenger/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import (
"github.com/lightningnetwork/lnd/lntypes"
)

const (
// defaultLNDCallTimeout is the default timeout used for calls to the
// LND client.
defaultLNDCallTimeout = time.Second * 10
)

// LndChallenger is a challenger that uses an lnd backend to create new LSAT
// payment challenges.
type LndChallenger struct {
Expand Down Expand Up @@ -251,7 +257,10 @@ func (l *LndChallenger) NewChallenge(price int64) (string, lntypes.Hash,
}

ctx := l.clientCtx()
response, err := l.client.AddInvoice(ctx, invoice)
ctxt, cancel := context.WithTimeout(ctx, defaultLNDCallTimeout)
defer cancel()

response, err := l.client.AddInvoice(ctxt, invoice)
if err != nil {
log.Errorf("Error adding invoice: %v", err)
return "", lntypes.ZeroHash, err
Expand Down

0 comments on commit 281cbd0

Please sign in to comment.