Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion aperture.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,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
22 changes: 20 additions & 2 deletions 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 @@ -199,12 +205,20 @@ func (l *LndChallenger) readInvoiceStream(
log.Errorf("Received error from invoice subscription: "+
"%v", err)

// If the challenger was shutting down, we will receive the
// "client connection is closing" error for LNC connections
// but there is no need to signal the error to the main goroutine.
select {
case <-l.quit:
return
default:
}

// The connection is faulty, we can't continue to
// function properly. Signal the error to the main
// goroutine to force a shutdown/restart.
select {
case l.errChan <- err:
case <-l.quit:
default:
}

Expand Down Expand Up @@ -244,6 +258,7 @@ func (l *LndChallenger) readInvoiceStream(
func (l *LndChallenger) Stop() {
l.invoicesCancel()
close(l.quit)
close(l.errChan)
l.wg.Wait()
}

Expand All @@ -263,7 +278,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