Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lnrpc: deprecate QueryRoutes with more than one route #2497

Merged
merged 10 commits into from
Mar 13, 2019
9 changes: 1 addition & 8 deletions routing/pathfind.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func (r *Route) ToHopPayloads() []sphinx.HopData {
//
// NOTE: The passed slice of ChannelHops MUST be sorted in forward order: from
// the source to the target node of the path finding attempt.
func newRoute(amtToSend, feeLimit lnwire.MilliSatoshi, sourceVertex Vertex,
func newRoute(amtToSend lnwire.MilliSatoshi, sourceVertex Vertex,
pathEdges []*channeldb.ChannelEdgePolicy, currentHeight uint32,
finalCLTVDelta uint16) (*Route, error) {

Expand Down Expand Up @@ -310,13 +310,6 @@ func newRoute(amtToSend, feeLimit lnwire.MilliSatoshi, sourceVertex Vertex,
return nil, err
}

// Invalidate this route if its total fees exceed our fee limit.
Roasbeef marked this conversation as resolved.
Show resolved Hide resolved
if newRoute.TotalFees > feeLimit {
err := fmt.Sprintf("total route fees exceeded fee "+
"limit of %v", feeLimit)
return nil, newErrf(ErrFeeLimitExceeded, err)
}

return newRoute, nil
}

Expand Down
60 changes: 3 additions & 57 deletions routing/pathfind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ func TestFindLowestFeePath(t *testing.T) {
t.Fatalf("unable to find path: %v", err)
}
route, err := newRoute(
paymentAmt, infinity, sourceVertex, path, startingHeight,
paymentAmt, sourceVertex, path, startingHeight,
finalHopCLTV)
if err != nil {
t.Fatalf("unable to create path: %v", err)
Expand Down Expand Up @@ -776,7 +776,7 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
}

route, err := newRoute(
paymentAmt, test.feeLimit, sourceVertex, path, startingHeight,
paymentAmt, sourceVertex, path, startingHeight,
finalHopCLTV,
)
if err != nil {
Expand Down Expand Up @@ -1056,8 +1056,6 @@ func TestNewRoute(t *testing.T) {
// expectedErrorCode indicates the expected error code when
// expectError is true.
expectedErrorCode errorCode

feeLimit lnwire.MilliSatoshi
}{
{
// For a single hop payment, no fees are expected to be paid.
Expand All @@ -1070,7 +1068,6 @@ func TestNewRoute(t *testing.T) {
expectedTimeLocks: []uint32{1},
expectedTotalAmount: 100000,
expectedTotalTimeLock: 1,
feeLimit: noFeeLimit,
}, {
// For a two hop payment, only the fee for the first hop
// needs to be paid. The destination hop does not require
Expand All @@ -1085,7 +1082,6 @@ func TestNewRoute(t *testing.T) {
expectedTimeLocks: []uint32{1, 1},
expectedTotalAmount: 100130,
expectedTotalTimeLock: 6,
feeLimit: noFeeLimit,
}, {
// A three hop payment where the first and second hop
// will both charge 1 msat. The fee for the first hop
Expand All @@ -1103,7 +1099,6 @@ func TestNewRoute(t *testing.T) {
expectedTotalAmount: 100002,
expectedTimeLocks: []uint32{4, 1, 1},
expectedTotalTimeLock: 9,
feeLimit: noFeeLimit,
}, {
// A three hop payment where the fee of the first hop
// is slightly higher (11) than the fee at the second hop,
Expand All @@ -1119,7 +1114,6 @@ func TestNewRoute(t *testing.T) {
expectedTotalAmount: 102010,
expectedTimeLocks: []uint32{4, 1, 1},
expectedTotalTimeLock: 9,
feeLimit: noFeeLimit,
}, {
// A three hop payment where the fee policies of the first and
// second hop are just high enough to show the fee carry over
Expand All @@ -1141,53 +1135,6 @@ func TestNewRoute(t *testing.T) {
expectedTotalAmount: 101101,
expectedTimeLocks: []uint32{4, 1, 1},
expectedTotalTimeLock: 9,
feeLimit: noFeeLimit,
},
// Check fee limit behaviour
{
name: "two hop success with fee limit (greater)",
paymentAmount: 100000,
hops: []*channeldb.ChannelEdgePolicy{
createHop(0, 1000, 1000000, 144),
createHop(0, 1000, 1000000, 144),
},
expectedTotalAmount: 100100,
expectedFees: []lnwire.MilliSatoshi{100, 0},
expectedTimeLocks: []uint32{1, 1},
expectedTotalTimeLock: 145,
feeLimit: 150,
}, {
name: "two hop success with fee limit (equal)",
paymentAmount: 100000,
hops: []*channeldb.ChannelEdgePolicy{
createHop(0, 1000, 1000000, 144),
createHop(0, 1000, 1000000, 144),
},
expectedTotalAmount: 100100,
expectedFees: []lnwire.MilliSatoshi{100, 0},
expectedTimeLocks: []uint32{1, 1},
expectedTotalTimeLock: 145,
feeLimit: 100,
}, {
name: "two hop failure with fee limit (smaller)",
paymentAmount: 100000,
hops: []*channeldb.ChannelEdgePolicy{
createHop(0, 1000, 1000000, 144),
createHop(0, 1000, 1000000, 144),
},
feeLimit: 50,
expectError: true,
expectedErrorCode: ErrFeeLimitExceeded,
}, {
name: "two hop failure with fee limit (zero)",
paymentAmount: 100000,
hops: []*channeldb.ChannelEdgePolicy{
createHop(0, 1000, 1000000, 144),
createHop(0, 1000, 1000000, 144),
},
feeLimit: 0,
expectError: true,
expectedErrorCode: ErrFeeLimitExceeded,
}}

for _, testCase := range testCases {
Expand Down Expand Up @@ -1238,7 +1185,6 @@ func TestNewRoute(t *testing.T) {

t.Run(testCase.name, func(t *testing.T) {
route, err := newRoute(testCase.paymentAmount,
testCase.feeLimit,
sourceVertex, testCase.hops, startingHeight,
finalHopCLTV)

Expand Down Expand Up @@ -2106,7 +2052,7 @@ func TestRestrictOutgoingChannel(t *testing.T) {
t.Fatalf("unable to find path: %v", err)
}
route, err := newRoute(
paymentAmt, infinity, sourceVertex, path, startingHeight,
paymentAmt, sourceVertex, path, startingHeight,
finalHopCLTV,
)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions routing/payment_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func (p *paymentSession) RequestRoute(payment *LightningPayment,
// a route by applying the time-lock and fee requirements.
sourceVertex := Vertex(p.mc.selfNode.PubKeyBytes)
route, err := newRoute(
payment.Amount, payment.FeeLimit, sourceVertex, path, height,
finalCltvDelta,
payment.Amount, sourceVertex, path, height, finalCltvDelta,
)
if err != nil {
// TODO(roasbeef): return which edge/vertex didn't work
Expand Down
7 changes: 3 additions & 4 deletions routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ type routingMsg struct {
// initial set of paths as it's possible we drop a route if it can't handle the
// total payment flow after fees are calculated.
func pathsToFeeSortedRoutes(source Vertex, paths [][]*channeldb.ChannelEdgePolicy,
finalCLTVDelta uint16, amt, feeLimit lnwire.MilliSatoshi,
finalCLTVDelta uint16, amt lnwire.MilliSatoshi,
currentHeight uint32) ([]*Route, error) {

validRoutes := make([]*Route, 0, len(paths))
Expand All @@ -1275,8 +1275,7 @@ func pathsToFeeSortedRoutes(source Vertex, paths [][]*channeldb.ChannelEdgePolic
// hop in the path as it contains a "self-hop" that is inserted
// by our KSP algorithm.
route, err := newRoute(
amt, feeLimit, source, path[1:], currentHeight,
finalCLTVDelta,
amt, source, path[1:], currentHeight, finalCLTVDelta,
)
if err != nil {
// TODO(roasbeef): report straw breaking edge?
Expand Down Expand Up @@ -1412,7 +1411,7 @@ func (r *ChannelRouter) FindRoutes(target *btcec.PublicKey,
// factored in.
sourceVertex := Vertex(r.selfNode.PubKeyBytes)
validRoutes, err := pathsToFeeSortedRoutes(
sourceVertex, shortestPaths, finalCLTVDelta, amt, feeLimit,
sourceVertex, shortestPaths, finalCLTVDelta, amt,
uint32(currentHeight),
)
if err != nil {
Expand Down