routing: export RestrictParams and EdgeLocator
This commit is contained in:
parent
4937304732
commit
b2b28b49b1
@ -46,7 +46,7 @@ type missionControl struct {
|
|||||||
// it was added to the prune view. Edges are added to this map if a
|
// it was added to the prune view. Edges are added to this map if a
|
||||||
// caller reports to missionControl a failure localized to that edge
|
// caller reports to missionControl a failure localized to that edge
|
||||||
// when sending a payment.
|
// when sending a payment.
|
||||||
failedEdges map[edgeLocator]time.Time
|
failedEdges map[EdgeLocator]time.Time
|
||||||
|
|
||||||
// failedVertexes maps a node's public key that should be pruned, to
|
// failedVertexes maps a node's public key that should be pruned, to
|
||||||
// the time that it was added to the prune view. Vertexes are added to
|
// the time that it was added to the prune view. Vertexes are added to
|
||||||
@ -75,7 +75,7 @@ func newMissionControl(g *channeldb.ChannelGraph, selfNode *channeldb.LightningN
|
|||||||
qb func(*channeldb.ChannelEdgeInfo) lnwire.MilliSatoshi) *missionControl {
|
qb func(*channeldb.ChannelEdgeInfo) lnwire.MilliSatoshi) *missionControl {
|
||||||
|
|
||||||
return &missionControl{
|
return &missionControl{
|
||||||
failedEdges: make(map[edgeLocator]time.Time),
|
failedEdges: make(map[EdgeLocator]time.Time),
|
||||||
failedVertexes: make(map[Vertex]time.Time),
|
failedVertexes: make(map[Vertex]time.Time),
|
||||||
selfNode: selfNode,
|
selfNode: selfNode,
|
||||||
queryBandwidth: qb,
|
queryBandwidth: qb,
|
||||||
@ -89,7 +89,7 @@ func newMissionControl(g *channeldb.ChannelGraph, selfNode *channeldb.LightningN
|
|||||||
// state of the wider network from the PoV of mission control compiled via HTLC
|
// state of the wider network from the PoV of mission control compiled via HTLC
|
||||||
// routing attempts in the past.
|
// routing attempts in the past.
|
||||||
type graphPruneView struct {
|
type graphPruneView struct {
|
||||||
edges map[edgeLocator]struct{}
|
edges map[EdgeLocator]struct{}
|
||||||
|
|
||||||
vertexes map[Vertex]struct{}
|
vertexes map[Vertex]struct{}
|
||||||
}
|
}
|
||||||
@ -124,7 +124,7 @@ func (m *missionControl) GraphPruneView() graphPruneView {
|
|||||||
|
|
||||||
// We'll also do the same for edges, but use the edgeDecay this time
|
// We'll also do the same for edges, but use the edgeDecay this time
|
||||||
// rather than the decay for vertexes.
|
// rather than the decay for vertexes.
|
||||||
edges := make(map[edgeLocator]struct{})
|
edges := make(map[EdgeLocator]struct{})
|
||||||
for edge, pruneTime := range m.failedEdges {
|
for edge, pruneTime := range m.failedEdges {
|
||||||
if now.Sub(pruneTime) >= edgeDecay {
|
if now.Sub(pruneTime) >= edgeDecay {
|
||||||
log.Tracef("Pruning decayed failure report for edge %v "+
|
log.Tracef("Pruning decayed failure report for edge %v "+
|
||||||
@ -217,7 +217,7 @@ func (m *missionControl) NewPaymentSession(routeHints [][]HopHint,
|
|||||||
pruneViewSnapshot: viewSnapshot,
|
pruneViewSnapshot: viewSnapshot,
|
||||||
additionalEdges: edges,
|
additionalEdges: edges,
|
||||||
bandwidthHints: bandwidthHints,
|
bandwidthHints: bandwidthHints,
|
||||||
errFailedPolicyChans: make(map[edgeLocator]struct{}),
|
errFailedPolicyChans: make(map[EdgeLocator]struct{}),
|
||||||
mc: m,
|
mc: m,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
@ -231,7 +231,7 @@ func (m *missionControl) NewPaymentSessionFromRoutes(routes []*Route) *paymentSe
|
|||||||
pruneViewSnapshot: m.GraphPruneView(),
|
pruneViewSnapshot: m.GraphPruneView(),
|
||||||
haveRoutes: true,
|
haveRoutes: true,
|
||||||
preBuiltRoutes: routes,
|
preBuiltRoutes: routes,
|
||||||
errFailedPolicyChans: make(map[edgeLocator]struct{}),
|
errFailedPolicyChans: make(map[EdgeLocator]struct{}),
|
||||||
mc: m,
|
mc: m,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,7 +275,7 @@ func generateBandwidthHints(sourceNode *channeldb.LightningNode,
|
|||||||
// if no payment attempts have been made.
|
// if no payment attempts have been made.
|
||||||
func (m *missionControl) ResetHistory() {
|
func (m *missionControl) ResetHistory() {
|
||||||
m.Lock()
|
m.Lock()
|
||||||
m.failedEdges = make(map[edgeLocator]time.Time)
|
m.failedEdges = make(map[EdgeLocator]time.Time)
|
||||||
m.failedVertexes = make(map[Vertex]time.Time)
|
m.failedVertexes = make(map[Vertex]time.Time)
|
||||||
m.Unlock()
|
m.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -398,24 +398,24 @@ type graphParams struct {
|
|||||||
bandwidthHints map[uint64]lnwire.MilliSatoshi
|
bandwidthHints map[uint64]lnwire.MilliSatoshi
|
||||||
}
|
}
|
||||||
|
|
||||||
// restrictParams wraps the set of restrictions passed to findPath that the
|
// RestrictParams wraps the set of restrictions passed to findPath that the
|
||||||
// found path must adhere to.
|
// found path must adhere to.
|
||||||
type restrictParams struct {
|
type RestrictParams struct {
|
||||||
// ignoredNodes is an optional set of nodes that should be ignored if
|
// IgnoredNodes is an optional set of nodes that should be ignored if
|
||||||
// encountered during path finding.
|
// encountered during path finding.
|
||||||
ignoredNodes map[Vertex]struct{}
|
IgnoredNodes map[Vertex]struct{}
|
||||||
|
|
||||||
// ignoredEdges is an optional set of edges that should be ignored if
|
// IgnoredEdges is an optional set of edges that should be ignored if
|
||||||
// encountered during path finding.
|
// encountered during path finding.
|
||||||
ignoredEdges map[edgeLocator]struct{}
|
IgnoredEdges map[EdgeLocator]struct{}
|
||||||
|
|
||||||
// feeLimit is a maximum fee amount allowed to be used on the path from
|
// FeeLimit is a maximum fee amount allowed to be used on the path from
|
||||||
// the source to the target.
|
// the source to the target.
|
||||||
feeLimit lnwire.MilliSatoshi
|
FeeLimit lnwire.MilliSatoshi
|
||||||
|
|
||||||
// outgoingChannelID is the channel that needs to be taken to the first
|
// OutgoingChannelID is the channel that needs to be taken to the first
|
||||||
// hop. If nil, any channel may be used.
|
// hop. If nil, any channel may be used.
|
||||||
outgoingChannelID *uint64
|
OutgoingChannelID *uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// findPath attempts to find a path from the source node within the
|
// findPath attempts to find a path from the source node within the
|
||||||
@ -429,7 +429,7 @@ type restrictParams struct {
|
|||||||
// destination node back to source. This is to properly accumulate fees
|
// destination node back to source. This is to properly accumulate fees
|
||||||
// that need to be paid along the path and accurately check the amount
|
// that need to be paid along the path and accurately check the amount
|
||||||
// to forward at every node against the available bandwidth.
|
// to forward at every node against the available bandwidth.
|
||||||
func findPath(g *graphParams, r *restrictParams,
|
func findPath(g *graphParams, r *RestrictParams,
|
||||||
sourceNode *channeldb.LightningNode, target *btcec.PublicKey,
|
sourceNode *channeldb.LightningNode, target *btcec.PublicKey,
|
||||||
amt lnwire.MilliSatoshi) ([]*channeldb.ChannelEdgePolicy, error) {
|
amt lnwire.MilliSatoshi) ([]*channeldb.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
@ -536,20 +536,20 @@ func findPath(g *graphParams, r *restrictParams,
|
|||||||
|
|
||||||
// If we have an outgoing channel restriction and this is not
|
// If we have an outgoing channel restriction and this is not
|
||||||
// the specified channel, skip it.
|
// the specified channel, skip it.
|
||||||
if isSourceChan && r.outgoingChannelID != nil &&
|
if isSourceChan && r.OutgoingChannelID != nil &&
|
||||||
*r.outgoingChannelID != edge.ChannelID {
|
*r.OutgoingChannelID != edge.ChannelID {
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this vertex or edge has been black listed, then we'll
|
// If this vertex or edge has been black listed, then we'll
|
||||||
// skip exploring this edge.
|
// skip exploring this edge.
|
||||||
if _, ok := r.ignoredNodes[fromVertex]; ok {
|
if _, ok := r.IgnoredNodes[fromVertex]; ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
locator := newEdgeLocator(edge)
|
locator := newEdgeLocator(edge)
|
||||||
if _, ok := r.ignoredEdges[*locator]; ok {
|
if _, ok := r.IgnoredEdges[*locator]; ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,7 +603,7 @@ func findPath(g *graphParams, r *restrictParams,
|
|||||||
// Check if accumulated fees would exceed fee limit when this
|
// Check if accumulated fees would exceed fee limit when this
|
||||||
// node would be added to the path.
|
// node would be added to the path.
|
||||||
totalFee := amountToReceive - amt
|
totalFee := amountToReceive - amt
|
||||||
if totalFee > r.feeLimit {
|
if totalFee > r.FeeLimit {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -784,7 +784,7 @@ func findPaths(tx *bbolt.Tx, graph *channeldb.ChannelGraph,
|
|||||||
amt lnwire.MilliSatoshi, feeLimit lnwire.MilliSatoshi, numPaths uint32,
|
amt lnwire.MilliSatoshi, feeLimit lnwire.MilliSatoshi, numPaths uint32,
|
||||||
bandwidthHints map[uint64]lnwire.MilliSatoshi) ([][]*channeldb.ChannelEdgePolicy, error) {
|
bandwidthHints map[uint64]lnwire.MilliSatoshi) ([][]*channeldb.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
// TODO(roasbeef): modifying ordering within heap to eliminate final
|
// TODO(roasbeef): modifying ordering within heap to eliminate final
|
||||||
@ -803,10 +803,10 @@ func findPaths(tx *bbolt.Tx, graph *channeldb.ChannelGraph,
|
|||||||
graph: graph,
|
graph: graph,
|
||||||
bandwidthHints: bandwidthHints,
|
bandwidthHints: bandwidthHints,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: feeLimit,
|
FeeLimit: feeLimit,
|
||||||
},
|
},
|
||||||
source, target, amt,
|
source, target, amt,
|
||||||
)
|
)
|
||||||
@ -839,7 +839,7 @@ func findPaths(tx *bbolt.Tx, graph *channeldb.ChannelGraph,
|
|||||||
// we'll exclude from the next path finding attempt.
|
// we'll exclude from the next path finding attempt.
|
||||||
// These are required to ensure the paths are unique
|
// These are required to ensure the paths are unique
|
||||||
// and loopless.
|
// and loopless.
|
||||||
ignoredEdges = make(map[edgeLocator]struct{})
|
ignoredEdges = make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes = make(map[Vertex]struct{})
|
ignoredVertexes = make(map[Vertex]struct{})
|
||||||
|
|
||||||
// Our spur node is the i-th node in the prior shortest
|
// Our spur node is the i-th node in the prior shortest
|
||||||
@ -891,10 +891,10 @@ func findPaths(tx *bbolt.Tx, graph *channeldb.ChannelGraph,
|
|||||||
graph: graph,
|
graph: graph,
|
||||||
bandwidthHints: bandwidthHints,
|
bandwidthHints: bandwidthHints,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: feeLimit,
|
FeeLimit: feeLimit,
|
||||||
}, spurNode, target, amt,
|
}, spurNode, target, amt,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -598,7 +598,7 @@ func TestFindLowestFeePath(t *testing.T) {
|
|||||||
}
|
}
|
||||||
sourceVertex := Vertex(sourceNode.PubKeyBytes)
|
sourceVertex := Vertex(sourceNode.PubKeyBytes)
|
||||||
|
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -612,10 +612,10 @@ func TestFindLowestFeePath(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: testGraphInstance.graph,
|
graph: testGraphInstance.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, paymentAmt,
|
sourceNode, target, paymentAmt,
|
||||||
)
|
)
|
||||||
@ -744,7 +744,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
|
|||||||
}
|
}
|
||||||
sourceVertex := Vertex(sourceNode.PubKeyBytes)
|
sourceVertex := Vertex(sourceNode.PubKeyBytes)
|
||||||
|
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -758,10 +758,10 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graphInstance.graph,
|
graph: graphInstance.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: test.feeLimit,
|
FeeLimit: test.feeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, paymentAmt,
|
sourceNode, target, paymentAmt,
|
||||||
)
|
)
|
||||||
@ -925,8 +925,8 @@ func TestPathFindingWithAdditionalEdges(t *testing.T) {
|
|||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
additionalEdges: additionalEdges,
|
additionalEdges: additionalEdges,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, dogePubKey, paymentAmt,
|
sourceNode, dogePubKey, paymentAmt,
|
||||||
)
|
)
|
||||||
@ -1224,7 +1224,7 @@ func TestNewRoutePathTooLong(t *testing.T) {
|
|||||||
t.Fatalf("unable to fetch source node: %v", err)
|
t.Fatalf("unable to fetch source node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
paymentAmt := lnwire.NewMSatFromSatoshis(100)
|
paymentAmt := lnwire.NewMSatFromSatoshis(100)
|
||||||
@ -1236,10 +1236,10 @@ func TestNewRoutePathTooLong(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, paymentAmt,
|
sourceNode, target, paymentAmt,
|
||||||
)
|
)
|
||||||
@ -1254,10 +1254,10 @@ func TestNewRoutePathTooLong(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, paymentAmt,
|
sourceNode, target, paymentAmt,
|
||||||
)
|
)
|
||||||
@ -1283,7 +1283,7 @@ func TestPathNotAvailable(t *testing.T) {
|
|||||||
t.Fatalf("unable to fetch source node: %v", err)
|
t.Fatalf("unable to fetch source node: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
// With the test graph loaded, we'll test that queries for target that
|
// With the test graph loaded, we'll test that queries for target that
|
||||||
@ -1303,10 +1303,10 @@ func TestPathNotAvailable(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, unknownNode, 100,
|
sourceNode, unknownNode, 100,
|
||||||
)
|
)
|
||||||
@ -1328,7 +1328,7 @@ func TestPathInsufficientCapacity(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch source node: %v", err)
|
t.Fatalf("unable to fetch source node: %v", err)
|
||||||
}
|
}
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
// Next, test that attempting to find a path in which the current
|
// Next, test that attempting to find a path in which the current
|
||||||
@ -1346,10 +1346,10 @@ func TestPathInsufficientCapacity(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1373,7 +1373,7 @@ func TestRouteFailMinHTLC(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch source node: %v", err)
|
t.Fatalf("unable to fetch source node: %v", err)
|
||||||
}
|
}
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
// We'll not attempt to route an HTLC of 10 SAT from roasbeef to Son
|
// We'll not attempt to route an HTLC of 10 SAT from roasbeef to Son
|
||||||
@ -1385,10 +1385,10 @@ func TestRouteFailMinHTLC(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1438,7 +1438,7 @@ func TestRouteFailMaxHTLC(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch source node: %v", err)
|
t.Fatalf("unable to fetch source node: %v", err)
|
||||||
}
|
}
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
// First, attempt to send a payment greater than the max HTLC we are
|
// First, attempt to send a payment greater than the max HTLC we are
|
||||||
@ -1449,10 +1449,10 @@ func TestRouteFailMaxHTLC(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1475,10 +1475,10 @@ func TestRouteFailMaxHTLC(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1505,7 +1505,7 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch source node: %v", err)
|
t.Fatalf("unable to fetch source node: %v", err)
|
||||||
}
|
}
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
// First, we'll try to route from roasbeef -> sophon. This should
|
// First, we'll try to route from roasbeef -> sophon. This should
|
||||||
@ -1516,10 +1516,10 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1548,10 +1548,10 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1577,10 +1577,10 @@ func TestRouteFailDisabledEdge(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1605,7 +1605,7 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to fetch source node: %v", err)
|
t.Fatalf("unable to fetch source node: %v", err)
|
||||||
}
|
}
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
// First, we'll try to route from roasbeef -> sophon. This should
|
// First, we'll try to route from roasbeef -> sophon. This should
|
||||||
@ -1617,10 +1617,10 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1645,10 +1645,10 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
|||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
bandwidthHints: bandwidths,
|
bandwidthHints: bandwidths,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1667,10 +1667,10 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
|||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
bandwidthHints: bandwidths,
|
bandwidthHints: bandwidths,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -1702,10 +1702,10 @@ func TestPathSourceEdgesBandwidth(t *testing.T) {
|
|||||||
graph: graph.graph,
|
graph: graph.graph,
|
||||||
bandwidthHints: bandwidths,
|
bandwidthHints: bandwidths,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, payAmt,
|
sourceNode, target, payAmt,
|
||||||
)
|
)
|
||||||
@ -2022,7 +2022,7 @@ func TestRestrictOutgoingChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
sourceVertex := Vertex(sourceNode.PubKeyBytes)
|
sourceVertex := Vertex(sourceNode.PubKeyBytes)
|
||||||
|
|
||||||
ignoredEdges := make(map[edgeLocator]struct{})
|
ignoredEdges := make(map[EdgeLocator]struct{})
|
||||||
ignoredVertexes := make(map[Vertex]struct{})
|
ignoredVertexes := make(map[Vertex]struct{})
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -2040,11 +2040,11 @@ func TestRestrictOutgoingChannel(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: testGraphInstance.graph,
|
graph: testGraphInstance.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoredVertexes,
|
IgnoredNodes: ignoredVertexes,
|
||||||
ignoredEdges: ignoredEdges,
|
IgnoredEdges: ignoredEdges,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
outgoingChannelID: &outgoingChannelID,
|
OutgoingChannelID: &outgoingChannelID,
|
||||||
},
|
},
|
||||||
sourceNode, target, paymentAmt,
|
sourceNode, target, paymentAmt,
|
||||||
)
|
)
|
||||||
|
@ -27,7 +27,7 @@ type paymentSession struct {
|
|||||||
// source of policy related routing failures during this payment attempt.
|
// source of policy related routing failures during this payment attempt.
|
||||||
// We'll use this map to prune out channels when the first error may not
|
// We'll use this map to prune out channels when the first error may not
|
||||||
// require pruning, but any subsequent ones do.
|
// require pruning, but any subsequent ones do.
|
||||||
errFailedPolicyChans map[edgeLocator]struct{}
|
errFailedPolicyChans map[EdgeLocator]struct{}
|
||||||
|
|
||||||
mc *missionControl
|
mc *missionControl
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ func (p *paymentSession) ReportVertexFailure(v Vertex) {
|
|||||||
// retrying an edge after its pruning has expired.
|
// retrying an edge after its pruning has expired.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): also add value attempted to send and capacity of channel
|
// TODO(roasbeef): also add value attempted to send and capacity of channel
|
||||||
func (p *paymentSession) ReportEdgeFailure(e *edgeLocator) {
|
func (p *paymentSession) ReportEdgeFailure(e *EdgeLocator) {
|
||||||
log.Debugf("Reporting edge %v failure to Mission Control", e)
|
log.Debugf("Reporting edge %v failure to Mission Control", e)
|
||||||
|
|
||||||
// First, we'll add the failed edge to our local prune view snapshot.
|
// First, we'll add the failed edge to our local prune view snapshot.
|
||||||
@ -82,7 +82,7 @@ func (p *paymentSession) ReportEdgeFailure(e *edgeLocator) {
|
|||||||
// pruned. This is to prevent nodes from keeping us busy by continuously sending
|
// pruned. This is to prevent nodes from keeping us busy by continuously sending
|
||||||
// new channel updates.
|
// new channel updates.
|
||||||
func (p *paymentSession) ReportEdgePolicyFailure(
|
func (p *paymentSession) ReportEdgePolicyFailure(
|
||||||
errSource Vertex, failedEdge *edgeLocator) {
|
errSource Vertex, failedEdge *EdgeLocator) {
|
||||||
|
|
||||||
// Check to see if we've already reported a policy related failure for
|
// Check to see if we've already reported a policy related failure for
|
||||||
// this channel. If so, then we'll prune out the vertex.
|
// this channel. If so, then we'll prune out the vertex.
|
||||||
@ -147,11 +147,11 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment,
|
|||||||
additionalEdges: p.additionalEdges,
|
additionalEdges: p.additionalEdges,
|
||||||
bandwidthHints: p.bandwidthHints,
|
bandwidthHints: p.bandwidthHints,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: pruneView.vertexes,
|
IgnoredNodes: pruneView.vertexes,
|
||||||
ignoredEdges: pruneView.edges,
|
IgnoredEdges: pruneView.edges,
|
||||||
feeLimit: payment.FeeLimit,
|
FeeLimit: payment.FeeLimit,
|
||||||
outgoingChannelID: payment.OutgoingChannelID,
|
OutgoingChannelID: payment.OutgoingChannelID,
|
||||||
},
|
},
|
||||||
p.mc.selfNode, payment.Target, payment.Amount,
|
p.mc.selfNode, payment.Target, payment.Amount,
|
||||||
)
|
)
|
||||||
|
@ -215,18 +215,20 @@ func newRouteTuple(amt lnwire.MilliSatoshi, dest []byte) routeTuple {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
// edgeLocator is a struct used to identify a specific edge. The direction
|
// EdgeLocator is a struct used to identify a specific edge.
|
||||||
// fields takes the value of 0 or 1 and is identical in definition to the
|
type EdgeLocator struct {
|
||||||
// channel direction flag. A value of 0 means the direction from the lower node
|
// ChannelID is the channel of this edge.
|
||||||
// pubkey to the higher.
|
ChannelID uint64
|
||||||
type edgeLocator struct {
|
|
||||||
channelID uint64
|
// Direction takes the value of 0 or 1 and is identical in definition to
|
||||||
direction uint8
|
// the channel direction flag. A value of 0 means the direction from the
|
||||||
|
// lower node pubkey to the higher.
|
||||||
|
Direction uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
// newEdgeLocatorByPubkeys returns an edgeLocator based on its end point
|
// newEdgeLocatorByPubkeys returns an edgeLocator based on its end point
|
||||||
// pubkeys.
|
// pubkeys.
|
||||||
func newEdgeLocatorByPubkeys(channelID uint64, fromNode, toNode *Vertex) *edgeLocator {
|
func newEdgeLocatorByPubkeys(channelID uint64, fromNode, toNode *Vertex) *EdgeLocator {
|
||||||
// Determine direction based on lexicographical ordering of both
|
// Determine direction based on lexicographical ordering of both
|
||||||
// pubkeys.
|
// pubkeys.
|
||||||
var direction uint8
|
var direction uint8
|
||||||
@ -234,24 +236,24 @@ func newEdgeLocatorByPubkeys(channelID uint64, fromNode, toNode *Vertex) *edgeLo
|
|||||||
direction = 1
|
direction = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
return &edgeLocator{
|
return &EdgeLocator{
|
||||||
channelID: channelID,
|
ChannelID: channelID,
|
||||||
direction: direction,
|
Direction: direction,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// newEdgeLocator extracts an edgeLocator based for a full edge policy
|
// newEdgeLocator extracts an edgeLocator based for a full edge policy
|
||||||
// structure.
|
// structure.
|
||||||
func newEdgeLocator(edge *channeldb.ChannelEdgePolicy) *edgeLocator {
|
func newEdgeLocator(edge *channeldb.ChannelEdgePolicy) *EdgeLocator {
|
||||||
return &edgeLocator{
|
return &EdgeLocator{
|
||||||
channelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
direction: uint8(edge.ChannelFlags & lnwire.ChanUpdateDirection),
|
Direction: uint8(edge.ChannelFlags & lnwire.ChanUpdateDirection),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a human readable version of the edgeLocator values.
|
// String returns a human readable version of the edgeLocator values.
|
||||||
func (e *edgeLocator) String() string {
|
func (e *EdgeLocator) String() string {
|
||||||
return fmt.Sprintf("%v:%v", e.channelID, e.direction)
|
return fmt.Sprintf("%v:%v", e.ChannelID, e.Direction)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelRouter is the layer 3 router within the Lightning stack. Below the
|
// ChannelRouter is the layer 3 router within the Lightning stack. Below the
|
||||||
@ -1275,7 +1277,7 @@ func pathsToFeeSortedRoutes(source Vertex, paths [][]*channeldb.ChannelEdgePolic
|
|||||||
// hop in the path as it contains a "self-hop" that is inserted
|
// hop in the path as it contains a "self-hop" that is inserted
|
||||||
// by our KSP algorithm.
|
// by our KSP algorithm.
|
||||||
route, err := newRoute(
|
route, err := newRoute(
|
||||||
amt, source, path[1:], currentHeight, finalCLTVDelta,
|
amt, source, path[1:], currentHeight, finalCLTVDelta,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO(roasbeef): report straw breaking edge?
|
// TODO(roasbeef): report straw breaking edge?
|
||||||
@ -1972,13 +1974,13 @@ func (r *ChannelRouter) processSendError(paySession *paymentSession,
|
|||||||
// we'll prune the channel in both directions and
|
// we'll prune the channel in both directions and
|
||||||
// continue with the rest of the routes.
|
// continue with the rest of the routes.
|
||||||
case *lnwire.FailPermanentChannelFailure:
|
case *lnwire.FailPermanentChannelFailure:
|
||||||
paySession.ReportEdgeFailure(&edgeLocator{
|
paySession.ReportEdgeFailure(&EdgeLocator{
|
||||||
channelID: failedEdge.channelID,
|
ChannelID: failedEdge.ChannelID,
|
||||||
direction: 0,
|
Direction: 0,
|
||||||
})
|
})
|
||||||
paySession.ReportEdgeFailure(&edgeLocator{
|
paySession.ReportEdgeFailure(&EdgeLocator{
|
||||||
channelID: failedEdge.channelID,
|
ChannelID: failedEdge.ChannelID,
|
||||||
direction: 1,
|
Direction: 1,
|
||||||
})
|
})
|
||||||
return false
|
return false
|
||||||
|
|
||||||
@ -1991,7 +1993,7 @@ func (r *ChannelRouter) processSendError(paySession *paymentSession,
|
|||||||
// pubkey of the node that sent the error. It will assume that the error is
|
// pubkey of the node that sent the error. It will assume that the error is
|
||||||
// associated with the outgoing channel of the error node.
|
// associated with the outgoing channel of the error node.
|
||||||
func getFailedEdge(route *Route, errSource Vertex) (
|
func getFailedEdge(route *Route, errSource Vertex) (
|
||||||
*edgeLocator, error) {
|
*EdgeLocator, error) {
|
||||||
|
|
||||||
hopCount := len(route.Hops)
|
hopCount := len(route.Hops)
|
||||||
fromNode := route.SourcePubKey
|
fromNode := route.SourcePubKey
|
||||||
|
@ -1950,7 +1950,7 @@ func TestFindPathFeeWeighting(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ignoreVertex := make(map[Vertex]struct{})
|
ignoreVertex := make(map[Vertex]struct{})
|
||||||
ignoreEdge := make(map[edgeLocator]struct{})
|
ignoreEdge := make(map[EdgeLocator]struct{})
|
||||||
|
|
||||||
amt := lnwire.MilliSatoshi(100)
|
amt := lnwire.MilliSatoshi(100)
|
||||||
|
|
||||||
@ -1966,10 +1966,10 @@ func TestFindPathFeeWeighting(t *testing.T) {
|
|||||||
&graphParams{
|
&graphParams{
|
||||||
graph: ctx.graph,
|
graph: ctx.graph,
|
||||||
},
|
},
|
||||||
&restrictParams{
|
&RestrictParams{
|
||||||
ignoredNodes: ignoreVertex,
|
IgnoredNodes: ignoreVertex,
|
||||||
ignoredEdges: ignoreEdge,
|
IgnoredEdges: ignoreEdge,
|
||||||
feeLimit: noFeeLimit,
|
FeeLimit: noFeeLimit,
|
||||||
},
|
},
|
||||||
sourceNode, target, amt,
|
sourceNode, target, amt,
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user