@@ -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
@@ -185,28 +187,18 @@ func (s *InterceptorService) Start(lightningClient lndclient.LightningClient,
185187 log .Errorf ("Error processing invoice " +
186188 "update: %v" , err )
187189
188- select {
189- case s .mainErrChan <- err :
190- case <- s .mainCtx .Done ():
191- case <- s .quit :
192- }
190+ s .mainErrCallback (err )
193191 return
194192 }
195193
196194 case err := <- invoiceErrChan :
197- log .Errorf ("Error in invoice subscription: %v" ,
198- err )
199-
200195 // if the invoice subscription errors out, we
201196 // stop the service as we won't be able to
202197 // process invoices.
203- s .disable ()
198+ err = s .disableAndErrorf ("Error in invoice " +
199+ "subscription: %v" , err )
204200
205- select {
206- case s .mainErrChan <- err :
207- case <- s .mainCtx .Done ():
208- case <- s .quit :
209- }
201+ s .mainErrCallback (err )
210202 return
211203
212204 case <- s .mainCtx .Done ():
@@ -587,11 +579,7 @@ func (s *InterceptorService) TrackPayment(id AccountID, hash lntypes.Hash,
587579 hash , paymentUpdate ,
588580 )
589581 if err != nil {
590- select {
591- case s .mainErrChan <- err :
592- case <- s .mainCtx .Done ():
593- case <- s .quit :
594- }
582+ s .mainErrCallback (err )
595583 return
596584 }
597585
@@ -613,18 +601,13 @@ func (s *InterceptorService) TrackPayment(id AccountID, hash lntypes.Hash,
613601 return
614602 }
615603
616- log .Errorf ("Received error from TrackPayment " +
617- "RPC for payment %v: %v" , hash , err )
618-
619604 if err != nil {
620605 // If we error when tracking the
621606 // payment, we stop the service.
622- s .disable ()
623- select {
624- case s .mainErrChan <- err :
625- case <- s .mainCtx .Done ():
626- case <- s .quit :
627- }
607+ err = s .disableAndErrorf ("Received " +
608+ "error from TrackPayment RPC " +
609+ "for payment %v: %v" , hash , err )
610+ s .mainErrCallback (err )
628611 }
629612 return
630613
0 commit comments