Skip to content

Commit 8237e54

Browse files
committed
routing: enforce tlv payloads during path finding
We would always pack our onion payloads in the new tlv format. We also now make sure we drop any routes which do not support the tlv format in the first place because the route will fail anyways when reaching those nodes because they cannot decode it.
1 parent 32c60c1 commit 8237e54

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

routing/integrated_routing_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ func TestBadFirstHopHint(t *testing.T) {
270270
// TestMppSend tests that a payment can be completed using multiple shards.
271271
func TestMppSend(t *testing.T) {
272272
for _, testCase := range mppTestCases {
273-
testCase := testCase
274273

275274
t.Run(testCase.name, func(t *testing.T) {
276275
testMppSend(t, &testCase)

routing/mock_graph_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func (m *mockGraph) ForEachNodeDirectedChannel(nodePub route.Vertex,
199199
ToNodePubKey: func() route.Vertex {
200200
return nodePub
201201
},
202-
ToNodeFeatures: lnwire.EmptyFeatureVector(),
202+
ToNodeFeatures: testFeatures,
203203
FeeBaseMSat: peerNode.baseFee,
204204
},
205205
},
@@ -224,7 +224,7 @@ func (m *mockGraph) sourceNode() route.Vertex {
224224
func (m *mockGraph) FetchNodeFeatures(nodePub route.Vertex) (
225225
*lnwire.FeatureVector, error) {
226226

227-
return lnwire.EmptyFeatureVector(), nil
227+
return testFeatures, nil
228228
}
229229

230230
// GraphSession will provide the call-back with access to a

routing/pathfind.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ func newRoute(sourceVertex route.Vertex,
226226
return edge.ToNodeFeatures.HasFeature(feature)
227227
}
228228

229+
// We pack payloads always in TLV format, therefore it will fail
230+
// anyways at the forwarding/receiving node in case it doesn't
231+
// support it.
232+
tlvPayloadSupport := supports(lnwire.TLVOnionPayloadOptional)
233+
if !tlvPayloadSupport {
234+
return nil, fmt.Errorf("cannot use a route with hops " +
235+
"that don't support TLV payloads")
236+
}
237+
229238
if i == len(pathEdges)-1 {
230239
// If this is the last hop, then the hop payload will
231240
// contain the exact amount. In BOLT #4: Onion Routing
@@ -253,7 +262,7 @@ func newRoute(sourceVertex route.Vertex,
253262
// doesn't support both TLV and payment addrs, fail.
254263
payAddr := supports(lnwire.PaymentAddrOptional)
255264
if !payAddr && finalHop.paymentAddr.IsSome() {
256-
return nil, errors.New("cannot attach " +
265+
return nil, fmt.Errorf("cannot attach " +
257266
"payment addr")
258267
}
259268

routing/pathfind_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
348348
ChannelID: edge.ChannelID,
349349
AuthProof: &testAuthProof,
350350
ChannelPoint: fundingPoint,
351-
Features: lnwire.EmptyFeatureVector(),
351+
Features: testFeatures,
352352
Capacity: btcutil.Amount(edge.Capacity),
353353
}
354354

@@ -528,6 +528,12 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
528528

529529
ctx := t.Context()
530530

531+
// We enforce TLV payloads for all nodes when blinding paths.
532+
testFeatures := lnwire.NewFeatureVector(
533+
lnwire.NewRawFeatureVector(lnwire.TLVOnionPayloadRequired),
534+
lnwire.Features,
535+
)
536+
531537
// We'll use this fake address for the IP address of all the nodes in
532538
// our tests. This value isn't needed for path finding so it doesn't
533539
// need to be unique.
@@ -562,7 +568,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
562568
privKey, pubKey := btcec.PrivKeyFromBytes(keyBytes)
563569

564570
if features == nil {
565-
features = lnwire.EmptyFeatureVector()
571+
features = testFeatures
566572
}
567573

568574
dbNode := &models.Node{
@@ -1490,7 +1496,7 @@ func TestNewRoute(t *testing.T) {
14901496
ToNodePubKey: func() route.Vertex {
14911497
return route.Vertex{}
14921498
},
1493-
ToNodeFeatures: lnwire.NewFeatureVector(nil, nil),
1499+
ToNodeFeatures: testFeatures,
14941500
FeeProportionalMillionths: feeRate,
14951501
FeeBaseMSat: baseFee,
14961502
TimeLockDelta: timeLockDelta,

routing/payment_session_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,7 @@ func TestRequestRoute(t *testing.T) {
223223
ToNodePubKey: func() route.Vertex {
224224
return route.Vertex{}
225225
},
226-
ToNodeFeatures: lnwire.NewFeatureVector(
227-
nil, nil,
228-
),
226+
ToNodeFeatures: testFeatures,
229227
},
230228
},
231229
}

routing/router_test.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ var (
4646
Port: 9000}
4747
testAddrs = []net.Addr{testAddr}
4848

49-
testFeatures = lnwire.NewFeatureVector(nil, lnwire.Features)
49+
// We enforce TLV payloads for all nodes when blinding paths.
50+
testFeatures = lnwire.NewFeatureVector(
51+
lnwire.NewRawFeatureVector(lnwire.TLVOnionPayloadRequired),
52+
lnwire.Features,
53+
)
5054

5155
testTime = time.Date(2018, time.January, 9, 14, 00, 00, 0, time.UTC)
5256

@@ -1512,7 +1516,10 @@ func TestBuildRoute(t *testing.T) {
15121516
// Setup a three node network.
15131517
chanCapSat := btcutil.Amount(100000)
15141518
paymentAddrFeatures := lnwire.NewFeatureVector(
1515-
lnwire.NewRawFeatureVector(lnwire.PaymentAddrOptional),
1519+
lnwire.NewRawFeatureVector(
1520+
lnwire.PaymentAddrOptional,
1521+
lnwire.TLVOnionPayloadRequired,
1522+
),
15161523
lnwire.Features,
15171524
)
15181525
testChannels := []*testChannel{
@@ -2735,13 +2742,26 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
27352742
)
27362743
require.NoError(t, err, "unable to create channel edge")
27372744

2745+
// Before we add the edge, we need to add the nodes to the graph.
2746+
// Although inserting just an edge will also add a node shell in case
2747+
// the nodes don't exist yet, we want to make sure that the nodes also
2748+
// have the proper features set because we now require TLV payloads.
2749+
require.NoError(t, ctx.graph.AddNode(ctxb, &models.Node{
2750+
PubKeyBytes: pub1,
2751+
Features: testFeatures,
2752+
}))
2753+
require.NoError(t, ctx.graph.AddNode(ctxb, &models.Node{
2754+
PubKeyBytes: pub2,
2755+
Features: testFeatures,
2756+
}))
2757+
27382758
edge := &models.ChannelEdgeInfo{
27392759
ChannelID: chanID.ToUint64(),
27402760
NodeKey1Bytes: pub1,
27412761
NodeKey2Bytes: pub2,
27422762
BitcoinKey1Bytes: pub1,
27432763
BitcoinKey2Bytes: pub2,
2744-
Features: lnwire.EmptyFeatureVector(),
2764+
Features: testFeatures,
27452765
AuthProof: nil,
27462766
}
27472767
require.NoError(t, ctx.graph.AddChannelEdge(ctxb, edge))
@@ -2817,7 +2837,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
28172837

28182838
edge = &models.ChannelEdgeInfo{
28192839
ChannelID: chanID.ToUint64(),
2820-
Features: lnwire.EmptyFeatureVector(),
2840+
Features: testFeatures,
28212841
AuthProof: nil,
28222842
}
28232843
copy(edge.NodeKey1Bytes[:], node1Bytes)

0 commit comments

Comments
 (0)