routing: remove redundant fee limit check in newRoute

This check was a left over from when the fee limit wasn't checked yet in
the path finding algorithm.
This commit is contained in:
Joost Jager 2019-03-05 10:37:14 +01:00
parent f4cc2e235a
commit 4937304732
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
4 changed files with 8 additions and 71 deletions

View File

@ -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) {
@ -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.
if newRoute.TotalFees > feeLimit {
err := fmt.Sprintf("total route fees exceeded fee "+
"limit of %v", feeLimit)
return nil, newErrf(ErrFeeLimitExceeded, err)
}
return newRoute, nil
}

View File

@ -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)
@ -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 {
@ -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.
@ -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
@ -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
@ -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,
@ -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
@ -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 {
@ -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)
@ -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 {

View File

@ -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

View File

@ -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))
@ -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?
@ -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 {