mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
routing/validation_barrier: adds ErrVBarrierShuttingDown
Adds a new error ErrVBarrierShuttingDown that is returned from WaitForDependants if the validation barrier's quit chan is closed. This allows any blocked goroutines to distinguish whether the dependent task has been completed, or if validation should be aborted entirely.
This commit is contained in:
parent
eaa8cdf916
commit
995e3fa85f
@ -1,12 +1,18 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// ErrVBarrierShuttingDown signals that the barrier has been requested to
|
||||
// shutdown, and that the caller should not treat the wait condition as
|
||||
// fulfilled.
|
||||
var ErrVBarrierShuttingDown = errors.New("validation barrier shutting down")
|
||||
|
||||
// ValidationBarrier is a barrier used to ensure proper validation order while
|
||||
// concurrently validating new announcements for channel edges, and the
|
||||
// attributes of channel edges. It uses this set of maps (protected by this
|
||||
@ -152,7 +158,7 @@ func (v *ValidationBarrier) CompleteJob() {
|
||||
// finished executing. This allows us a graceful way to schedule goroutines
|
||||
// based on any pending uncompleted dependent jobs. If this job doesn't have an
|
||||
// active dependent, then this function will return immediately.
|
||||
func (v *ValidationBarrier) WaitForDependants(job interface{}) {
|
||||
func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
||||
|
||||
var (
|
||||
signal chan struct{}
|
||||
@ -181,13 +187,13 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) {
|
||||
case *lnwire.AnnounceSignatures:
|
||||
// TODO(roasbeef): need to wait on chan ann?
|
||||
v.Unlock()
|
||||
return
|
||||
return nil
|
||||
case *channeldb.ChannelEdgeInfo:
|
||||
v.Unlock()
|
||||
return
|
||||
return nil
|
||||
case *lnwire.ChannelAnnouncement:
|
||||
v.Unlock()
|
||||
return
|
||||
return nil
|
||||
}
|
||||
v.Unlock()
|
||||
|
||||
@ -196,10 +202,13 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) {
|
||||
if ok {
|
||||
select {
|
||||
case <-v.quit:
|
||||
return
|
||||
return ErrVBarrierShuttingDown
|
||||
case <-signal:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SignalDependants will signal any jobs that are dependent on this job that
|
||||
|
Loading…
Reference in New Issue
Block a user