invoices: init quit channel of modifier

Also add atomic start and stop vars to prevent close of a closed
channel.
This commit is contained in:
Elle Mouton 2024-09-24 14:44:09 +09:00
parent 7dc86acb8c
commit 0bd76ffe32
No known key found for this signature in database
GPG Key ID: D7D916376026F177
2 changed files with 16 additions and 0 deletions

View File

@ -66,6 +66,9 @@ func (s *safeCallback) Exec(req HtlcModifyRequest) (*HtlcModifyResponse,
// settle an invoice, enabling a subscribed client to modify certain aspects of // settle an invoice, enabling a subscribed client to modify certain aspects of
// those HTLCs. // those HTLCs.
type HtlcModificationInterceptor struct { type HtlcModificationInterceptor struct {
started atomic.Bool
stopped atomic.Bool
// callback is the wrapped client callback function that is called when // callback is the wrapped client callback function that is called when
// an invoice is intercepted. This function gives the client the ability // an invoice is intercepted. This function gives the client the ability
// to determine how the invoice should be settled. // to determine how the invoice should be settled.
@ -79,6 +82,7 @@ type HtlcModificationInterceptor struct {
func NewHtlcModificationInterceptor() *HtlcModificationInterceptor { func NewHtlcModificationInterceptor() *HtlcModificationInterceptor {
return &HtlcModificationInterceptor{ return &HtlcModificationInterceptor{
callback: &safeCallback{}, callback: &safeCallback{},
quit: make(chan struct{}),
} }
} }
@ -163,11 +167,19 @@ func (s *HtlcModificationInterceptor) RegisterInterceptor(
// Start starts the service. // Start starts the service.
func (s *HtlcModificationInterceptor) Start() error { func (s *HtlcModificationInterceptor) Start() error {
if !s.started.CompareAndSwap(false, true) {
return nil
}
return nil return nil
} }
// Stop stops the service. // Stop stops the service.
func (s *HtlcModificationInterceptor) Stop() error { func (s *HtlcModificationInterceptor) Stop() error {
if !s.stopped.CompareAndSwap(false, true) {
return nil
}
close(s.quit) close(s.quit)
return nil return nil

View File

@ -2411,6 +2411,10 @@ func (s *server) Stop() error {
if err := s.invoices.Stop(); err != nil { if err := s.invoices.Stop(); err != nil {
srvrLog.Warnf("failed to stop invoices: %v", err) srvrLog.Warnf("failed to stop invoices: %v", err)
} }
if err := s.invoiceHtlcModifier.Stop(); err != nil {
srvrLog.Warnf("failed to stop htlc invoices "+
"modifier: %v", err)
}
if err := s.chanRouter.Stop(); err != nil { if err := s.chanRouter.Stop(); err != nil {
srvrLog.Warnf("failed to stop chanRouter: %v", err) srvrLog.Warnf("failed to stop chanRouter: %v", err)
} }