routing+discovery: uniform error codes in routing

This commit is contained in:
yyforyongyu 2021-12-13 08:25:34 +08:00
parent c15c8a1f0b
commit dd74486b59
No known key found for this signature in database
GPG Key ID: 9BCD95C4FF296868
5 changed files with 45 additions and 32 deletions

View File

@ -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(),

View File

@ -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,

View File

@ -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 "+

View File

@ -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
}

View File

@ -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)
}