mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-21 14:10:35 +02:00
chainntnfs/btcd+neutrino: sync epoch cancel
This commit is contained in:
committed by
Olaoluwa Osuntokun
parent
a9b1af4c73
commit
9f85eadde1
@@ -257,9 +257,6 @@ out:
|
|||||||
delete(b.spendNotifications[msg.op], msg.spendID)
|
delete(b.spendNotifications[msg.op], msg.spendID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal that it's safe yield from Cancel to application.
|
|
||||||
close(msg.done)
|
|
||||||
|
|
||||||
case *epochCancel:
|
case *epochCancel:
|
||||||
chainntnfs.Log.Infof("Cancelling epoch "+
|
chainntnfs.Log.Infof("Cancelling epoch "+
|
||||||
"notification, epoch_id=%v", msg.epochID)
|
"notification, epoch_id=%v", msg.epochID)
|
||||||
@@ -278,8 +275,6 @@ out:
|
|||||||
close(b.blockEpochClients[msg.epochID].epochChan)
|
close(b.blockEpochClients[msg.epochID].epochChan)
|
||||||
delete(b.blockEpochClients, msg.epochID)
|
delete(b.blockEpochClients, msg.epochID)
|
||||||
|
|
||||||
// Signal that it's safe yield from Cancel to application.
|
|
||||||
close(msg.done)
|
|
||||||
}
|
}
|
||||||
case registerMsg := <-b.notificationRegistry:
|
case registerMsg := <-b.notificationRegistry:
|
||||||
switch msg := registerMsg.(type) {
|
switch msg := registerMsg.(type) {
|
||||||
@@ -625,8 +620,6 @@ type spendCancel struct {
|
|||||||
|
|
||||||
// spendID the ID of the notification to cancel.
|
// spendID the ID of the notification to cancel.
|
||||||
spendID uint64
|
spendID uint64
|
||||||
|
|
||||||
done chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterSpendNtfn registers an intent to be notified once the target
|
// RegisterSpendNtfn registers an intent to be notified once the target
|
||||||
@@ -685,17 +678,21 @@ func (b *BtcdNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
|||||||
cancel := &spendCancel{
|
cancel := &spendCancel{
|
||||||
op: *outpoint,
|
op: *outpoint,
|
||||||
spendID: ntfn.spendID,
|
spendID: ntfn.spendID,
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit spend cancellation to notification dispatcher.
|
// Submit spend cancellation to notification dispatcher.
|
||||||
select {
|
select {
|
||||||
case b.notificationCancels <- cancel:
|
case b.notificationCancels <- cancel:
|
||||||
// Cancellation is being handled, wait for close before yielding to
|
// Cancellation is being handled, drain the spend chan until it is
|
||||||
// caller.
|
// closed before yielding to the caller.
|
||||||
select {
|
for {
|
||||||
case <-cancel.done:
|
select {
|
||||||
case <-b.quit:
|
case _, ok := <-ntfn.spendChan:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-b.quit:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case <-b.quit:
|
case <-b.quit:
|
||||||
}
|
}
|
||||||
@@ -755,8 +752,6 @@ type blockEpochRegistration struct {
|
|||||||
// cancel an outstanding epoch notification that has yet to be dispatched.
|
// cancel an outstanding epoch notification that has yet to be dispatched.
|
||||||
type epochCancel struct {
|
type epochCancel struct {
|
||||||
epochID uint64
|
epochID uint64
|
||||||
|
|
||||||
done chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterBlockEpochNtfn returns a BlockEpochEvent which subscribes the
|
// RegisterBlockEpochNtfn returns a BlockEpochEvent which subscribes the
|
||||||
@@ -779,17 +774,21 @@ func (b *BtcdNotifier) RegisterBlockEpochNtfn() (*chainntnfs.BlockEpochEvent, er
|
|||||||
Cancel: func() {
|
Cancel: func() {
|
||||||
cancel := &epochCancel{
|
cancel := &epochCancel{
|
||||||
epochID: registration.epochID,
|
epochID: registration.epochID,
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit epoch cancellation to notification dispatcher.
|
// Submit epoch cancellation to notification dispatcher.
|
||||||
select {
|
select {
|
||||||
case b.notificationCancels <- cancel:
|
case b.notificationCancels <- cancel:
|
||||||
// Cancellation is being handled, wait for close before yielding to
|
// Cancellation is being handled, drain the epoch channel until it is
|
||||||
// caller.
|
// closed before yielding to caller.
|
||||||
select {
|
for {
|
||||||
case <-cancel.done:
|
select {
|
||||||
case <-b.quit:
|
case _, ok := <-registration.epochChan:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-b.quit:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case <-b.quit:
|
case <-b.quit:
|
||||||
}
|
}
|
||||||
|
@@ -268,9 +268,6 @@ func (n *NeutrinoNotifier) notificationDispatcher() {
|
|||||||
delete(n.spendNotifications[msg.op], msg.spendID)
|
delete(n.spendNotifications[msg.op], msg.spendID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Signal that it's safe yield from Cancel to application.
|
|
||||||
close(msg.done)
|
|
||||||
|
|
||||||
case *epochCancel:
|
case *epochCancel:
|
||||||
chainntnfs.Log.Infof("Cancelling epoch "+
|
chainntnfs.Log.Infof("Cancelling epoch "+
|
||||||
"notification, epoch_id=%v", msg.epochID)
|
"notification, epoch_id=%v", msg.epochID)
|
||||||
@@ -288,9 +285,6 @@ func (n *NeutrinoNotifier) notificationDispatcher() {
|
|||||||
// cancelled.
|
// cancelled.
|
||||||
close(n.blockEpochClients[msg.epochID].epochChan)
|
close(n.blockEpochClients[msg.epochID].epochChan)
|
||||||
delete(n.blockEpochClients, msg.epochID)
|
delete(n.blockEpochClients, msg.epochID)
|
||||||
|
|
||||||
// Signal that it's safe yield from Cancel to application.
|
|
||||||
close(msg.done)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case registerMsg := <-n.notificationRegistry:
|
case registerMsg := <-n.notificationRegistry:
|
||||||
@@ -687,8 +681,6 @@ type spendCancel struct {
|
|||||||
|
|
||||||
// spendID the ID of the notification to cancel.
|
// spendID the ID of the notification to cancel.
|
||||||
spendID uint64
|
spendID uint64
|
||||||
|
|
||||||
done chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterSpendNtfn registers an intent to be notified once the target
|
// RegisterSpendNtfn registers an intent to be notified once the target
|
||||||
@@ -716,17 +708,21 @@ func (n *NeutrinoNotifier) RegisterSpendNtfn(outpoint *wire.OutPoint,
|
|||||||
cancel := &spendCancel{
|
cancel := &spendCancel{
|
||||||
op: *outpoint,
|
op: *outpoint,
|
||||||
spendID: ntfn.spendID,
|
spendID: ntfn.spendID,
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit spend cancellation to notification dispatcher.
|
// Submit spend cancellation to notification dispatcher.
|
||||||
select {
|
select {
|
||||||
case n.notificationCancels <- cancel:
|
case n.notificationCancels <- cancel:
|
||||||
// Cancellation is being handled, wait for close before yielding to
|
// Cancellation is being handled, drain the spend chan until it is
|
||||||
// caller.
|
// closed before yielding to the caller.
|
||||||
select {
|
for {
|
||||||
case <-cancel.done:
|
select {
|
||||||
case <-n.quit:
|
case _, ok := <-ntfn.spendChan:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-n.quit:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case <-n.quit:
|
case <-n.quit:
|
||||||
}
|
}
|
||||||
@@ -860,8 +856,6 @@ type blockEpochRegistration struct {
|
|||||||
// to cancel an outstanding epoch notification that has yet to be dispatched.
|
// to cancel an outstanding epoch notification that has yet to be dispatched.
|
||||||
type epochCancel struct {
|
type epochCancel struct {
|
||||||
epochID uint64
|
epochID uint64
|
||||||
|
|
||||||
done chan struct{}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterBlockEpochNtfn returns a BlockEpochEvent which subscribes the caller
|
// RegisterBlockEpochNtfn returns a BlockEpochEvent which subscribes the caller
|
||||||
@@ -883,17 +877,21 @@ func (n *NeutrinoNotifier) RegisterBlockEpochNtfn() (*chainntnfs.BlockEpochEvent
|
|||||||
Cancel: func() {
|
Cancel: func() {
|
||||||
cancel := &epochCancel{
|
cancel := &epochCancel{
|
||||||
epochID: registration.epochID,
|
epochID: registration.epochID,
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Submit epoch cancellation to notification dispatcher.
|
// Submit epoch cancellation to notification dispatcher.
|
||||||
select {
|
select {
|
||||||
case n.notificationCancels <- cancel:
|
case n.notificationCancels <- cancel:
|
||||||
// Cancellation is being handled, wait for close before yielding to
|
// Cancellation is being handled, drain the epoch channel until it is
|
||||||
// caller.
|
// closed before yielding to caller.
|
||||||
select {
|
for {
|
||||||
case <-cancel.done:
|
select {
|
||||||
case <-n.quit:
|
case _, ok := <-registration.epochChan:
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-n.quit:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case <-n.quit:
|
case <-n.quit:
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user