mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-20 13:04:28 +02:00
invoices: add client to map before delivering backlog notif
Prior to this change, if SubscribeSingleInvoice or SubscribeNotifications was called, it was possible that a state change would never be delivered to the client. The sequence of events would be: - delivery of backlog events with invoice in the Open state - invoice goes to the Accepted state, no client to notify - client added to map This is fixed by adding the client to the map first. However, with this change alone it then becomes possible for notifications to be delivered out of order. This is addressed in a following commit.
This commit is contained in:
@@ -1543,6 +1543,10 @@ func (i *InvoiceRegistry) SubscribeNotifications(
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
i.Lock()
|
||||||
|
i.notificationClients[client.id] = client
|
||||||
|
i.Unlock()
|
||||||
|
|
||||||
// Query the database to see if based on the provided addIndex and
|
// Query the database to see if based on the provided addIndex and
|
||||||
// settledIndex we need to deliver any backlog notifications.
|
// settledIndex we need to deliver any backlog notifications.
|
||||||
err := i.deliverBacklogEvents(client)
|
err := i.deliverBacklogEvents(client)
|
||||||
@@ -1552,12 +1556,6 @@ func (i *InvoiceRegistry) SubscribeNotifications(
|
|||||||
|
|
||||||
log.Infof("New invoice subscription client: id=%v", client.id)
|
log.Infof("New invoice subscription client: id=%v", client.id)
|
||||||
|
|
||||||
i.Lock()
|
|
||||||
// With the backlog notifications delivered (if any), we'll add this to
|
|
||||||
// our active subscriptions.
|
|
||||||
i.notificationClients[client.id] = client
|
|
||||||
i.Unlock()
|
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1617,6 +1615,10 @@ func (i *InvoiceRegistry) SubscribeSingleInvoice(
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
i.Lock()
|
||||||
|
i.singleNotificationClients[client.id] = client
|
||||||
|
i.Unlock()
|
||||||
|
|
||||||
err := i.deliverSingleBacklogEvents(client)
|
err := i.deliverSingleBacklogEvents(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -1625,10 +1627,6 @@ func (i *InvoiceRegistry) SubscribeSingleInvoice(
|
|||||||
log.Infof("New single invoice subscription client: id=%v, ref=%v",
|
log.Infof("New single invoice subscription client: id=%v, ref=%v",
|
||||||
client.id, client.invoiceRef)
|
client.id, client.invoiceRef)
|
||||||
|
|
||||||
i.Lock()
|
|
||||||
i.singleNotificationClients[client.id] = client
|
|
||||||
i.Unlock()
|
|
||||||
|
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user