Skip to content

Commit 32b2a58

Browse files
terminal: don't stop litd on account system error
1 parent 4696c47 commit 32b2a58

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

accounts/service.go

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,18 @@ type InterceptorService struct {
6060
invoiceToAccount map[lntypes.Hash]AccountID
6161
pendingPayments map[lntypes.Hash]*trackedPayment
6262

63-
mainErrChan chan<- error
64-
wg sync.WaitGroup
65-
quit chan struct{}
63+
mainErrCallback func(error)
64+
wg sync.WaitGroup
65+
quit chan struct{}
6666

6767
isEnabled bool
6868
}
6969

7070
// NewService returns a service backed by the macaroon Bolt DB stored in the
7171
// passed-in directory.
72-
func NewService(dir string, errChan chan<- error) (*InterceptorService, error) {
72+
func NewService(dir string,
73+
errCallback func(error)) (*InterceptorService, error) {
74+
7375
accountStore, err := NewBoltStore(dir, DBFilename)
7476
if err != nil {
7577
return nil, err
@@ -83,7 +85,7 @@ func NewService(dir string, errChan chan<- error) (*InterceptorService, error) {
8385
contextCancel: contextCancel,
8486
invoiceToAccount: make(map[lntypes.Hash]AccountID),
8587
pendingPayments: make(map[lntypes.Hash]*trackedPayment),
86-
mainErrChan: errChan,
88+
mainErrCallback: errCallback,
8789
quit: make(chan struct{}),
8890
isEnabled: false,
8991
}, nil
@@ -184,11 +186,7 @@ func (s *InterceptorService) Start(lightningClient lndclient.LightningClient,
184186
log.Errorf("Error processing invoice "+
185187
"update: %v", err)
186188

187-
select {
188-
case s.mainErrChan <- err:
189-
case <-s.mainCtx.Done():
190-
case <-s.quit:
191-
}
189+
s.mainErrCallback(err)
192190
return
193191
}
194192

@@ -199,11 +197,7 @@ func (s *InterceptorService) Start(lightningClient lndclient.LightningClient,
199197
err = s.disableAndErrorf("Error in invoice "+
200198
"subscription: %w", err)
201199

202-
select {
203-
case s.mainErrChan <- err:
204-
case <-s.mainCtx.Done():
205-
case <-s.quit:
206-
}
200+
s.mainErrCallback(err)
207201
return
208202

209203
case <-s.mainCtx.Done():
@@ -581,11 +575,7 @@ func (s *InterceptorService) TrackPayment(id AccountID, hash lntypes.Hash,
581575
hash, paymentUpdate,
582576
)
583577
if err != nil {
584-
select {
585-
case s.mainErrChan <- err:
586-
case <-s.mainCtx.Done():
587-
case <-s.quit:
588-
}
578+
s.mainErrCallback(err)
589579
return
590580
}
591581

@@ -614,11 +604,7 @@ func (s *InterceptorService) TrackPayment(id AccountID, hash lntypes.Hash,
614604
"error from TrackPayment RPC "+
615605
"for payment %v: %w", hash, err)
616606

617-
select {
618-
case s.mainErrChan <- err:
619-
case <-s.mainCtx.Done():
620-
case <-s.quit:
621-
}
607+
s.mainErrCallback(err)
622608
}
623609
return
624610

accounts/service_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func TestAccountService(t *testing.T) {
287287
err := s.store.UpdateAccount(acct)
288288
require.NoError(t, err)
289289

290-
lnd.mainErrChan <- testErr
290+
s.mainErrCallback(testErr)
291291
},
292292
validate: func(t *testing.T, lnd *mockLnd,
293293
s *InterceptorService) {
@@ -672,9 +672,10 @@ func TestAccountService(t *testing.T) {
672672
tt.Parallel()
673673

674674
lndMock := newMockLnd()
675-
service, err := NewService(
676-
t.TempDir(), lndMock.mainErrChan,
677-
)
675+
errFunc := func(err error) {
676+
lndMock.mainErrChan <- err
677+
}
678+
service, err := NewService(t.TempDir(), errFunc)
678679
require.NoError(t, err)
679680

680681
// Is a setup call required to initialize initial

terminal.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,14 @@ func (g *LightningTerminal) Run() error {
305305
func (g *LightningTerminal) start() error {
306306
var err error
307307

308+
accountServiceErrCallback := func(err error) {
309+
log.Errorf("Error thrown in the accounts service, keeping "+
310+
"litd running: %v", err,
311+
)
312+
}
313+
308314
g.accountService, err = accounts.NewService(
309-
filepath.Dir(g.cfg.MacaroonPath), g.errQueue.ChanIn(),
315+
filepath.Dir(g.cfg.MacaroonPath), accountServiceErrCallback,
310316
)
311317
if err != nil {
312318
return fmt.Errorf("error creating account service: %v", err)
@@ -843,9 +849,12 @@ func (g *LightningTerminal) startInternalSubServers(
843849
g.lndClient.ChainParams,
844850
)
845851
if err != nil {
846-
return fmt.Errorf("error starting account service: %v",
847-
err)
852+
log.Errorf("error starting account service: %v, disabling "+
853+
"account service", err)
848854
}
855+
// Even if we error on accountService.Start, we still want to mark the
856+
// service as started so that we can properly shut it down in the
857+
// shutdownSubServers call.
849858
g.accountServiceStarted = true
850859

851860
requestLogger, err := firewall.NewRequestLogger(

0 commit comments

Comments
 (0)