invoices: add proper startup for the interceptor

During testing of this PR I figured out the the htlc interceptor
was not shutdown and started properly in terms of closing the
quit channel but also in terms of the relevant logs.
This commit is contained in:
ziggie
2024-09-26 10:39:57 +02:00
parent 448193b0fd
commit 027de0a82c

View File

@@ -2,6 +2,7 @@ package invoices
import (
"errors"
"fmt"
"sync/atomic"
"github.com/lightningnetwork/lnd/fn"
@@ -167,21 +168,31 @@ func (s *HtlcModificationInterceptor) RegisterInterceptor(
// Start starts the service.
func (s *HtlcModificationInterceptor) Start() error {
log.Info("HtlcModificationInterceptor starting...")
if !s.started.CompareAndSwap(false, true) {
return nil
return fmt.Errorf("HtlcModificationInterceptor started more" +
"than once")
}
log.Debugf("HtlcModificationInterceptor started")
return nil
}
// Stop stops the service.
func (s *HtlcModificationInterceptor) Stop() error {
log.Info("HtlcModificationInterceptor stopping...")
if !s.stopped.CompareAndSwap(false, true) {
return nil
return fmt.Errorf("HtlcModificationInterceptor stopped more" +
"than once")
}
close(s.quit)
log.Debug("HtlcModificationInterceptor stopped")
return nil
}