routing: assume TLV onion during route construction

This commit is contained in:
Elle Mouton 2024-05-29 16:18:12 -04:00 committed by Oliver Gugger
parent 6ab5ed1b7f
commit 8446ecc22e
No known key found for this signature in database
GPG Key ID: 8E4256593F177720
2 changed files with 20 additions and 38 deletions

View File

@ -163,7 +163,6 @@ func newRoute(sourceVertex route.Vertex,
fee int64
totalAmtMsatBlinded lnwire.MilliSatoshi
outgoingTimeLock uint32
tlvPayload bool
customRecords record.CustomSet
mpp *record.MPP
metadata []byte
@ -182,13 +181,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
@ -206,12 +198,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
@ -277,7 +264,6 @@ func newRoute(sourceVertex route.Vertex,
ChannelID: edge.ChannelID,
AmtToForward: amtToForward,
OutgoingTimeLock: outgoingTimeLock,
LegacyPayload: !tlvPayload,
CustomRecords: customRecords,
MPP: mpp,
Metadata: metadata,

View File

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