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