diff --git a/routing/pathfind.go b/routing/pathfind.go index 893cef12a..32302b941 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -161,7 +161,6 @@ func newRoute(sourceVertex route.Vertex, fee int64 totalAmtMsatBlinded lnwire.MilliSatoshi outgoingTimeLock uint32 - tlvPayload bool customRecords record.CustomSet mpp *record.MPP metadata []byte @@ -180,13 +179,6 @@ func newRoute(sourceVertex route.Vertex, return edge.ToNodeFeatures.HasFeature(feature) } - // We start by assuming the node doesn't support TLV. We'll now - // inspect the node's feature vector to see if we can promote - // the hop. We assume already that the feature vector's - // transitive dependencies have already been validated by path - // finding or some other means. - tlvPayload = supports(lnwire.TLVOnionPayloadOptional) - if i == len(pathEdges)-1 { // If this is the last hop, then the hop payload will // contain the exact amount. In BOLT #4: Onion Routing @@ -204,12 +196,7 @@ func newRoute(sourceVertex route.Vertex, totalTimeLock += uint32(finalHop.cltvDelta) outgoingTimeLock = totalTimeLock - // Attach any custom records to the final hop if the - // receiver supports TLV. - if !tlvPayload && finalHop.records != nil { - return nil, errors.New("cannot attach " + - "custom records") - } + // Attach any custom records to the final hop. customRecords = finalHop.records // If we're attaching a payment addr but the receiver @@ -275,7 +262,6 @@ func newRoute(sourceVertex route.Vertex, ChannelID: edge.ChannelID, AmtToForward: amtToForward, OutgoingTimeLock: outgoingTimeLock, - LegacyPayload: !tlvPayload, CustomRecords: customRecords, MPP: mpp, Metadata: metadata, diff --git a/routing/pathfind_test.go b/routing/pathfind_test.go index af2e296bd..51859adf6 100644 --- a/routing/pathfind_test.go +++ b/routing/pathfind_test.go @@ -3,7 +3,6 @@ package routing import ( "bytes" "crypto/sha256" - "encoding/binary" "encoding/hex" "encoding/json" "errors" @@ -25,6 +24,7 @@ import ( "github.com/lightningnetwork/lnd/channeldb" "github.com/lightningnetwork/lnd/channeldb/models" "github.com/lightningnetwork/lnd/htlcswitch" + switchhop "github.com/lightningnetwork/lnd/htlcswitch/hop" "github.com/lightningnetwork/lnd/kvdb" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/record" @@ -1030,7 +1030,8 @@ var basicGraphPathFindingTests = []basicGraphPathFindingTestCase{ // Basic route with fee limit. {target: "sophon", paymentAmt: 100, feeLimit: 50, expectFailureNoPath: true, - }} + }, +} func runBasicGraphPathFinding(t *testing.T, useCache bool) { testGraphInstance, err := parseTestGraph(t, useCache, basicGraphFilePath) @@ -1123,32 +1124,27 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc // Hops should point to the next hop for i := 0; i < len(expectedHops)-1; i++ { - var expectedHop [8]byte - binary.BigEndian.PutUint64(expectedHop[:], route.Hops[i+1].ChannelID) + payload, _, err := switchhop.ParseTLVPayload( + bytes.NewReader(sphinxPath[i].HopPayload.Payload), + ) + require.NoError(t, err) - hopData, err := sphinxPath[i].HopPayload.HopData() - if err != nil { - t.Fatalf("unable to make hop data: %v", err) - } - - if !bytes.Equal(hopData.NextAddress[:], expectedHop[:]) { - t.Fatalf("first hop has incorrect next hop: expected %x, got %x", - expectedHop[:], hopData.NextAddress[:]) - } + require.Equal( + t, route.Hops[i+1].ChannelID, + payload.FwdInfo.NextHop.ToUint64(), + ) } + lastHopIndex := len(expectedHops) - 1 + + payload, _, err := switchhop.ParseTLVPayload( + bytes.NewReader(sphinxPath[lastHopIndex].HopPayload.Payload), + ) + require.NoError(t, err) + // The final hop should have a next hop value of all zeroes in order // to indicate it's the exit hop. - var exitHop [8]byte - lastHopIndex := len(expectedHops) - 1 - - hopData, err := sphinxPath[lastHopIndex].HopPayload.HopData() - require.NoError(t, err, "unable to create hop data") - - if !bytes.Equal(hopData.NextAddress[:], exitHop[:]) { - t.Fatalf("first hop has incorrect next hop: expected %x, got %x", - exitHop[:], hopData.NextAddress) - } + require.Zero(t, payload.FwdInfo.NextHop.ToUint64()) var expectedTotalFee lnwire.MilliSatoshi for i := 0; i < expectedHopCount; i++ {