From 995e3fa85fea307608d2c9f5e35d10751312c770 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Mon, 7 May 2018 16:33:17 -0700 Subject: [PATCH] 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. --- routing/validation_barrier.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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