mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-02-23 14:40:30 +01:00
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:
parent
d2c745e610
commit
575d699917
2 changed files with 16 additions and 0 deletions
|
@ -66,6 +66,9 @@ func (s *safeCallback) Exec(req HtlcModifyRequest) (*HtlcModifyResponse,
|
|||
// settle an invoice, enabling a subscribed client to modify certain aspects of
|
||||
// those HTLCs.
|
||||
type HtlcModificationInterceptor struct {
|
||||
started atomic.Bool
|
||||
stopped atomic.Bool
|
||||
|
||||
// callback is the wrapped client callback function that is called when
|
||||
// an invoice is intercepted. This function gives the client the ability
|
||||
// to determine how the invoice should be settled.
|
||||
|
@ -79,6 +82,7 @@ type HtlcModificationInterceptor struct {
|
|||
func NewHtlcModificationInterceptor() *HtlcModificationInterceptor {
|
||||
return &HtlcModificationInterceptor{
|
||||
callback: &safeCallback{},
|
||||
quit: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -163,11 +167,19 @@ func (s *HtlcModificationInterceptor) RegisterInterceptor(
|
|||
|
||||
// Start starts the service.
|
||||
func (s *HtlcModificationInterceptor) Start() error {
|
||||
if !s.started.CompareAndSwap(false, true) {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop stops the service.
|
||||
func (s *HtlcModificationInterceptor) Stop() error {
|
||||
if !s.stopped.CompareAndSwap(false, true) {
|
||||
return nil
|
||||
}
|
||||
|
||||
close(s.quit)
|
||||
|
||||
return nil
|
||||
|
|
|
@ -2380,6 +2380,10 @@ func (s *server) Stop() error {
|
|||
if err := s.invoices.Stop(); err != nil {
|
||||
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 {
|
||||
srvrLog.Warnf("failed to stop chanRouter: %v", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue