mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-11 14:48:14 +01:00
routing: assume TLV onion during route construction
This commit is contained in:
@@ -161,7 +161,6 @@ func newRoute(sourceVertex route.Vertex,
|
|||||||
fee int64
|
fee int64
|
||||||
totalAmtMsatBlinded lnwire.MilliSatoshi
|
totalAmtMsatBlinded lnwire.MilliSatoshi
|
||||||
outgoingTimeLock uint32
|
outgoingTimeLock uint32
|
||||||
tlvPayload bool
|
|
||||||
customRecords record.CustomSet
|
customRecords record.CustomSet
|
||||||
mpp *record.MPP
|
mpp *record.MPP
|
||||||
metadata []byte
|
metadata []byte
|
||||||
@@ -180,13 +179,6 @@ func newRoute(sourceVertex route.Vertex,
|
|||||||
return edge.ToNodeFeatures.HasFeature(feature)
|
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 i == len(pathEdges)-1 {
|
||||||
// If this is the last hop, then the hop payload will
|
// If this is the last hop, then the hop payload will
|
||||||
// contain the exact amount. In BOLT #4: Onion Routing
|
// contain the exact amount. In BOLT #4: Onion Routing
|
||||||
@@ -204,12 +196,7 @@ func newRoute(sourceVertex route.Vertex,
|
|||||||
totalTimeLock += uint32(finalHop.cltvDelta)
|
totalTimeLock += uint32(finalHop.cltvDelta)
|
||||||
outgoingTimeLock = totalTimeLock
|
outgoingTimeLock = totalTimeLock
|
||||||
|
|
||||||
// Attach any custom records to the final hop if the
|
// Attach any custom records to the final hop.
|
||||||
// receiver supports TLV.
|
|
||||||
if !tlvPayload && finalHop.records != nil {
|
|
||||||
return nil, errors.New("cannot attach " +
|
|
||||||
"custom records")
|
|
||||||
}
|
|
||||||
customRecords = finalHop.records
|
customRecords = finalHop.records
|
||||||
|
|
||||||
// If we're attaching a payment addr but the receiver
|
// If we're attaching a payment addr but the receiver
|
||||||
@@ -275,7 +262,6 @@ func newRoute(sourceVertex route.Vertex,
|
|||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
AmtToForward: amtToForward,
|
AmtToForward: amtToForward,
|
||||||
OutgoingTimeLock: outgoingTimeLock,
|
OutgoingTimeLock: outgoingTimeLock,
|
||||||
LegacyPayload: !tlvPayload,
|
|
||||||
CustomRecords: customRecords,
|
CustomRecords: customRecords,
|
||||||
MPP: mpp,
|
MPP: mpp,
|
||||||
Metadata: metadata,
|
Metadata: metadata,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/binary"
|
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
@@ -25,6 +24,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
"github.com/lightningnetwork/lnd/channeldb/models"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
|
switchhop "github.com/lightningnetwork/lnd/htlcswitch/hop"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/record"
|
"github.com/lightningnetwork/lnd/record"
|
||||||
@@ -1030,7 +1030,8 @@ var basicGraphPathFindingTests = []basicGraphPathFindingTestCase{
|
|||||||
// Basic route with fee limit.
|
// Basic route with fee limit.
|
||||||
{target: "sophon", paymentAmt: 100, feeLimit: 50,
|
{target: "sophon", paymentAmt: 100, feeLimit: 50,
|
||||||
expectFailureNoPath: true,
|
expectFailureNoPath: true,
|
||||||
}}
|
},
|
||||||
|
}
|
||||||
|
|
||||||
func runBasicGraphPathFinding(t *testing.T, useCache bool) {
|
func runBasicGraphPathFinding(t *testing.T, useCache bool) {
|
||||||
testGraphInstance, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
testGraphInstance, err := parseTestGraph(t, useCache, basicGraphFilePath)
|
||||||
@@ -1123,32 +1124,27 @@ func testBasicGraphPathFindingCase(t *testing.T, graphInstance *testGraphInstanc
|
|||||||
|
|
||||||
// Hops should point to the next hop
|
// Hops should point to the next hop
|
||||||
for i := 0; i < len(expectedHops)-1; i++ {
|
for i := 0; i < len(expectedHops)-1; i++ {
|
||||||
var expectedHop [8]byte
|
payload, _, err := switchhop.ParseTLVPayload(
|
||||||
binary.BigEndian.PutUint64(expectedHop[:], route.Hops[i+1].ChannelID)
|
bytes.NewReader(sphinxPath[i].HopPayload.Payload),
|
||||||
|
)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
hopData, err := sphinxPath[i].HopPayload.HopData()
|
require.Equal(
|
||||||
if err != nil {
|
t, route.Hops[i+1].ChannelID,
|
||||||
t.Fatalf("unable to make hop data: %v", err)
|
payload.FwdInfo.NextHop.ToUint64(),
|
||||||
}
|
)
|
||||||
|
|
||||||
if !bytes.Equal(hopData.NextAddress[:], expectedHop[:]) {
|
|
||||||
t.Fatalf("first hop has incorrect next hop: expected %x, got %x",
|
|
||||||
expectedHop[:], hopData.NextAddress[:])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
// The final hop should have a next hop value of all zeroes in order
|
||||||
// to indicate it's the exit hop.
|
// to indicate it's the exit hop.
|
||||||
var exitHop [8]byte
|
require.Zero(t, payload.FwdInfo.NextHop.ToUint64())
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
var expectedTotalFee lnwire.MilliSatoshi
|
var expectedTotalFee lnwire.MilliSatoshi
|
||||||
for i := 0; i < expectedHopCount; i++ {
|
for i := 0; i < expectedHopCount; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user