mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-26 18:36:33 +02:00
invoices: remove potential cyclic pointer references
This commit removes the pointer reference to InvoiceRegistry when creating an InvoiceSubscriptionKit and mounts the channels needed for communication.
This commit is contained in:
@@ -1404,8 +1404,15 @@ func (i *InvoiceRegistry) notifyClients(hash lntypes.Hash,
|
|||||||
// invoiceSubscriptionKit defines that are common to both all invoice
|
// invoiceSubscriptionKit defines that are common to both all invoice
|
||||||
// subscribers and single invoice subscribers.
|
// subscribers and single invoice subscribers.
|
||||||
type invoiceSubscriptionKit struct {
|
type invoiceSubscriptionKit struct {
|
||||||
id uint32
|
id uint32 // nolint:structcheck
|
||||||
inv *InvoiceRegistry
|
|
||||||
|
// subscriptionCancels is a chan mounted to InvoiceRegistry that
|
||||||
|
// signals the current subscription has been cancled.
|
||||||
|
subscriptionCancels chan uint32
|
||||||
|
|
||||||
|
// quit is a chan mouted to InvoiceRegistry that signals a shutdown.
|
||||||
|
quit chan struct{}
|
||||||
|
|
||||||
ntfnQueue *queue.ConcurrentQueue
|
ntfnQueue *queue.ConcurrentQueue
|
||||||
|
|
||||||
canceled uint32 // To be used atomically.
|
canceled uint32 // To be used atomically.
|
||||||
@@ -1465,8 +1472,8 @@ func (i *invoiceSubscriptionKit) Cancel() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case i.inv.subscriptionCancels <- i.id:
|
case i.subscriptionCancels <- i.id:
|
||||||
case <-i.inv.quit:
|
case <-i.quit:
|
||||||
}
|
}
|
||||||
|
|
||||||
i.ntfnQueue.Stop()
|
i.ntfnQueue.Stop()
|
||||||
@@ -1478,7 +1485,7 @@ func (i *invoiceSubscriptionKit) Cancel() {
|
|||||||
func (i *invoiceSubscriptionKit) notify(event *invoiceEvent) error {
|
func (i *invoiceSubscriptionKit) notify(event *invoiceEvent) error {
|
||||||
select {
|
select {
|
||||||
case i.ntfnQueue.ChanIn() <- event:
|
case i.ntfnQueue.ChanIn() <- event:
|
||||||
case <-i.inv.quit:
|
case <-i.quit:
|
||||||
return ErrShuttingDown
|
return ErrShuttingDown
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1499,7 +1506,8 @@ func (i *InvoiceRegistry) SubscribeNotifications(
|
|||||||
addIndex: addIndex,
|
addIndex: addIndex,
|
||||||
settleIndex: settleIndex,
|
settleIndex: settleIndex,
|
||||||
invoiceSubscriptionKit: invoiceSubscriptionKit{
|
invoiceSubscriptionKit: invoiceSubscriptionKit{
|
||||||
inv: i,
|
subscriptionCancels: i.subscriptionCancels,
|
||||||
|
quit: i.quit,
|
||||||
ntfnQueue: queue.NewConcurrentQueue(20),
|
ntfnQueue: queue.NewConcurrentQueue(20),
|
||||||
cancelChan: make(chan struct{}),
|
cancelChan: make(chan struct{}),
|
||||||
},
|
},
|
||||||
@@ -1596,7 +1604,8 @@ func (i *InvoiceRegistry) SubscribeSingleInvoice(
|
|||||||
client := &SingleInvoiceSubscription{
|
client := &SingleInvoiceSubscription{
|
||||||
Updates: make(chan *channeldb.Invoice),
|
Updates: make(chan *channeldb.Invoice),
|
||||||
invoiceSubscriptionKit: invoiceSubscriptionKit{
|
invoiceSubscriptionKit: invoiceSubscriptionKit{
|
||||||
inv: i,
|
subscriptionCancels: i.subscriptionCancels,
|
||||||
|
quit: i.quit,
|
||||||
ntfnQueue: queue.NewConcurrentQueue(20),
|
ntfnQueue: queue.NewConcurrentQueue(20),
|
||||||
cancelChan: make(chan struct{}),
|
cancelChan: make(chan struct{}),
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user