routing+discovery: uniform error codes in routing

This commit is contained in:
yyforyongyu committed 2022-01-05 04:27:33 +08:00
1 parent c15c8a1f0b
commit dd74486b59
5 files changed
+45 -32

No files matched your search

+9
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,
+9 -3
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 "+
+4 -14
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
}
+6 -2
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)
}