routing: use simple errors for path finding
This commit is contained in:
parent
6774b5a007
commit
ac2df9bbf4
@ -7,18 +7,10 @@ import "github.com/go-errors/errors"
|
||||
type errorCode uint8
|
||||
|
||||
const (
|
||||
// ErrNoPathFound is returned when a path to the target destination
|
||||
// does not exist in the graph.
|
||||
ErrNoPathFound errorCode = iota
|
||||
|
||||
// ErrMaxHopsExceeded is returned when a candidate path is found, but
|
||||
// the length of that path exceeds HopLimit.
|
||||
ErrMaxHopsExceeded
|
||||
|
||||
// ErrTargetNotInNetwork is returned when the target of a path-finding
|
||||
// or payment attempt isn't known to be within the current version of
|
||||
// the channel graph.
|
||||
ErrTargetNotInNetwork
|
||||
ErrTargetNotInNetwork errorCode = iota
|
||||
|
||||
// ErrOutdated is returned when the routing update already have
|
||||
// been applied, or a newer update is already known.
|
||||
|
@ -2,13 +2,13 @@ package routing
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/coreos/bbolt"
|
||||
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
@ -63,6 +63,19 @@ var (
|
||||
// DefaultAprioriHopProbability is the default a priori probability for
|
||||
// a hop.
|
||||
DefaultAprioriHopProbability = float64(0.6)
|
||||
|
||||
// errNoTlvPayload is returned when the destination hop does not support
|
||||
// a tlv payload.
|
||||
errNoTlvPayload = errors.New("destination hop doesn't " +
|
||||
"understand new TLV payloads")
|
||||
|
||||
// errNoPathFound is returned when a path to the target destination does
|
||||
// not exist in the graph.
|
||||
errNoPathFound = errors.New("unable to find a path to destination")
|
||||
|
||||
// errMaxHopsExceeded is returned when a candidate path is found, but
|
||||
// the length of that path exceeds HopLimit.
|
||||
errMaxHopsExceeded = errors.New("potential path has too many hops")
|
||||
)
|
||||
|
||||
// edgePolicyWithSource is a helper struct to keep track of the source node
|
||||
@ -347,8 +360,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
||||
lnwire.TLVOnionPayloadOptional,
|
||||
)
|
||||
if !supportsTLV {
|
||||
return nil, fmt.Errorf("destination hop doesn't " +
|
||||
"understand new TLV paylods")
|
||||
return nil, errNoTlvPayload
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -610,8 +622,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
||||
currentNodeWithDist, ok := distance[currentNode]
|
||||
if !ok {
|
||||
// If the node doesnt have a next hop it means we didn't find a path.
|
||||
return nil, newErrf(ErrNoPathFound, "unable to find a "+
|
||||
"path to destination")
|
||||
return nil, errNoPathFound
|
||||
}
|
||||
|
||||
// Add the next hop to the list of path edges.
|
||||
@ -634,8 +645,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
||||
// hops, then it's invalid.
|
||||
numEdges := len(pathEdges)
|
||||
if numEdges > HopLimit {
|
||||
return nil, newErr(ErrMaxHopsExceeded, "potential path has "+
|
||||
"too many hops")
|
||||
return nil, errMaxHopsExceeded
|
||||
}
|
||||
|
||||
log.Debugf("Found route: probability=%v, hops=%v, fee=%v\n",
|
||||
|
@ -1269,7 +1269,7 @@ func TestPathNotAvailable(t *testing.T) {
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, unknownNode, 100,
|
||||
)
|
||||
if !IsError(err, ErrNoPathFound) {
|
||||
if err != errNoPathFound {
|
||||
t.Fatalf("path shouldn't have been found: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1306,7 +1306,7 @@ func TestPathInsufficientCapacity(t *testing.T) {
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt,
|
||||
)
|
||||
if !IsError(err, ErrNoPathFound) {
|
||||
if err != errNoPathFound {
|
||||
t.Fatalf("graph shouldn't be able to support payment: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1339,7 +1339,7 @@ func TestRouteFailMinHTLC(t *testing.T) {
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt,
|
||||
)
|
||||
if !IsError(err, ErrNoPathFound) {
|
||||
if err != errNoPathFound {
|
||||
t.Fatalf("graph shouldn't be able to support payment: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1403,7 +1403,7 @@ func TestRouteFailMaxHTLC(t *testing.T) {
|
||||
// We'll now attempt to route through that edge with a payment above
|
||||
// 100k msat, which should fail.
|
||||
_, err = ctx.findPath(target, payAmt)
|
||||
if !IsError(err, ErrNoPathFound) {
|
||||
if err != errNoPathFound {
|
||||
t.Fatalf("graph shouldn't be able to support payment: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1491,7 +1491,7 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt,
|
||||
)
|
||||
if !IsError(err, ErrNoPathFound) {
|
||||
if err != errNoPathFound {
|
||||
t.Fatalf("graph shouldn't be able to support payment: %v", err)
|
||||
}
|
||||
}
|
||||
@ -1549,7 +1549,7 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
||||
noRestrictions, testPathFindingConfig,
|
||||
sourceNode.PubKeyBytes, target, payAmt,
|
||||
)
|
||||
if !IsError(err, ErrNoPathFound) {
|
||||
if err != errNoPathFound {
|
||||
t.Fatalf("graph shouldn't be able to support payment: %v", err)
|
||||
}
|
||||
|
||||
@ -1971,7 +1971,7 @@ func testCltvLimit(t *testing.T, limit uint32, expectedChannel uint64) {
|
||||
path, err := ctx.findPath(target, paymentAmt)
|
||||
if expectedChannel == 0 {
|
||||
// Finish test if we expect no route.
|
||||
if IsError(err, ErrNoPathFound) {
|
||||
if err == errNoPathFound {
|
||||
return
|
||||
}
|
||||
t.Fatal("expected no path to be found")
|
||||
@ -2137,7 +2137,7 @@ func testProbabilityRouting(t *testing.T, p10, p11, p20, minProbability float64,
|
||||
|
||||
path, err := ctx.findPath(target, paymentAmt)
|
||||
if expectedChan == 0 {
|
||||
if err == nil || !IsError(err, ErrNoPathFound) {
|
||||
if err != errNoPathFound {
|
||||
t.Fatalf("expected no path found, but got %v", err)
|
||||
}
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user