diff --git a/routing/validation_barrier.go b/routing/validation_barrier.go index b0a0aa854..ce4eb98f6 100644 --- a/routing/validation_barrier.go +++ b/routing/validation_barrier.go @@ -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