diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 690b5a564..5efafde33 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1113,8 +1113,11 @@ func (d *AuthenticatedGossiper) networkHandler() { announcement.msg, ) if err != nil { - if err != routing.ErrVBarrierShuttingDown && - err != routing.ErrParentValidationFailed { + if !routing.IsError( + err, + routing.ErrVBarrierShuttingDown, + routing.ErrParentValidationFailed, + ) { log.Warnf("unexpected error "+ "during validation "+ "barrier shutdown: %v", @@ -1658,15 +1661,13 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement( log.Debugf("Adding node: %x got error: %v", msg.NodeID, err) - switch { - case routing.IsError(err, routing.ErrOutdated, - routing.ErrIgnored): - - case err == routing.ErrVBarrierShuttingDown: - - default: + if !routing.IsError( + err, + routing.ErrOutdated, + routing.ErrIgnored, + routing.ErrVBarrierShuttingDown, + ) { log.Error(err) - } nMsg.err <- err @@ -2188,11 +2189,14 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement( } if err := d.cfg.Router.UpdateEdge(update, schedulerOp...); err != nil { - if routing.IsError(err, routing.ErrOutdated, - routing.ErrIgnored) { + if routing.IsError( + err, routing.ErrOutdated, + routing.ErrIgnored, + routing.ErrVBarrierShuttingDown, + ) { log.Debug(err) - } else if err != routing.ErrVBarrierShuttingDown { + } else { key := newRejectCacheKey( msg.ShortChannelID.ToUint64(), nMsg.peer.PubKey(), diff --git a/routing/errors.go b/routing/errors.go index a5c7fd3ca..2511757bc 100644 --- a/routing/errors.go +++ b/routing/errors.go @@ -28,6 +28,15 @@ const ( // ErrInvalidFundingOutput is returned if the channle funding output // fails validation. ErrInvalidFundingOutput + + // ErrVBarrierShuttingDown signals that the barrier has been requested + // to shutdown, and that the caller should not treat the wait condition + // as fulfilled. + ErrVBarrierShuttingDown + + // ErrParentValidationFailed signals that the validation of a + // dependent's parent failed, so the dependent must not be processed. + ErrParentValidationFailed ) // routerError is a structure that represent the error inside the routing package, diff --git a/routing/router.go b/routing/router.go index 5baf6eccc..36d098fc4 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1062,13 +1062,19 @@ func (r *ChannelRouter) networkHandler() { update.msg, ) if err != nil { - switch err { - case ErrVBarrierShuttingDown: + switch { + case IsError( + err, ErrVBarrierShuttingDown, + ): update.err <- err - case ErrParentValidationFailed: + + case IsError( + err, ErrParentValidationFailed, + ): update.err <- newErrf( ErrIgnored, err.Error(), ) + default: log.Warnf("unexpected error "+ "during validation "+ diff --git a/routing/validation_barrier.go b/routing/validation_barrier.go index c8c5e7b34..17d378826 100644 --- a/routing/validation_barrier.go +++ b/routing/validation_barrier.go @@ -1,7 +1,6 @@ package routing import ( - "errors" "sync" "github.com/lightningnetwork/lnd/channeldb" @@ -9,17 +8,6 @@ import ( "github.com/lightningnetwork/lnd/routing/route" ) -var ( - // ErrVBarrierShuttingDown signals that the barrier has been requested - // to shutdown, and that the caller should not treat the wait condition - // as fulfilled. - ErrVBarrierShuttingDown = errors.New("validation barrier shutting down") - - // ErrParentValidationFailed signals that the validation of a - // dependent's parent failed, so the dependent must not be processed. - ErrParentValidationFailed = errors.New("parent validation failed") -) - // validationSignals contains two signals which allows the ValidationBarrier to // communicate back to the caller whether a dependent should be processed or not // based on whether its parent was successfully validated. Only one of these @@ -228,9 +216,11 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error { if ok { select { case <-v.quit: - return ErrVBarrierShuttingDown + return newErrf(ErrVBarrierShuttingDown, + "validation barrier shutting down") case <-signals.deny: - return ErrParentValidationFailed + return newErrf(ErrParentValidationFailed, + "parent validation failed") case <-signals.allow: return nil } diff --git a/routing/validation_barrier_test.go b/routing/validation_barrier_test.go index 248c1dc20..2eda0120f 100644 --- a/routing/validation_barrier_test.go +++ b/routing/validation_barrier_test.go @@ -141,14 +141,18 @@ func TestValidationBarrierQuit(t *testing.T) { switch { // First half should return without failure. - case i < numTasks/4 && err != routing.ErrParentValidationFailed: + case i < numTasks/4 && !routing.IsError( + err, routing.ErrParentValidationFailed, + ): t.Fatalf("unexpected failure while waiting: %v", err) case i >= numTasks/4 && i < numTasks/2 && err != nil: t.Fatalf("unexpected failure while waiting: %v", err) // Last half should return the shutdown error. - case i >= numTasks/2 && err != routing.ErrVBarrierShuttingDown: + case i >= numTasks/2 && !routing.IsError( + err, routing.ErrVBarrierShuttingDown, + ): t.Fatalf("expected failure after quitting: want %v, "+ "got %v", routing.ErrVBarrierShuttingDown, err) }