diff --git a/aperture.go b/aperture.go index 95a3193..5acc08b 100644 --- a/aperture.go +++ b/aperture.go @@ -337,8 +337,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 "+ diff --git a/challenger/lnd.go b/challenger/lnd.go index 00bd53e..e790196 100644 --- a/challenger/lnd.go +++ b/challenger/lnd.go @@ -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 { @@ -244,6 +250,7 @@ func (l *LndChallenger) readInvoiceStream( func (l *LndChallenger) Stop() { l.invoicesCancel() close(l.quit) + close(l.errChan) l.wg.Wait() } @@ -263,7 +270,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