Skip to content

Commit 738253f

Browse files
committed
routing: assume TLV onion during path finding
1 parent fb416c2 commit 738253f

File tree

7 files changed

+30
-232
lines changed

7 files changed

+30
-232
lines changed

routing/additional_edge.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ type AdditionalEdge interface {
2525
// additional edge when being an intermediate hop in a route NOT the
2626
// final hop.
2727
IntermediatePayloadSize(amount lnwire.MilliSatoshi, expiry uint32,
28-
legacy bool, channelID uint64) uint64
28+
channelID uint64) uint64
2929

3030
// EdgePolicy returns the policy of the additional edge.
3131
EdgePolicy() *models.CachedEdgePolicy
3232
}
3333

3434
// PayloadSizeFunc defines the interface for the payload size function.
3535
type PayloadSizeFunc func(amount lnwire.MilliSatoshi, expiry uint32,
36-
legacy bool, channelID uint64) uint64
36+
channelID uint64) uint64
3737

3838
// PrivateEdge implements the AdditionalEdge interface. As the name implies it
3939
// is used for private route hints that the receiver adds for example to an
@@ -50,12 +50,11 @@ func (p *PrivateEdge) EdgePolicy() *models.CachedEdgePolicy {
5050
// IntermediatePayloadSize returns the sphinx payload size defined in BOLT04 if
5151
// this edge were to be included in a route.
5252
func (p *PrivateEdge) IntermediatePayloadSize(amount lnwire.MilliSatoshi,
53-
expiry uint32, legacy bool, channelID uint64) uint64 {
53+
expiry uint32, channelID uint64) uint64 {
5454

5555
hop := route.Hop{
5656
AmtToForward: amount,
5757
OutgoingTimeLock: expiry,
58-
LegacyPayload: legacy,
5958
}
6059

6160
return hop.PayloadSize(channelID)
@@ -77,11 +76,10 @@ func (b *BlindedEdge) EdgePolicy() *models.CachedEdgePolicy {
7776
// IntermediatePayloadSize returns the sphinx payload size defined in BOLT04 if
7877
// this edge were to be included in a route.
7978
func (b *BlindedEdge) IntermediatePayloadSize(_ lnwire.MilliSatoshi, _ uint32,
80-
_ bool, _ uint64) uint64 {
79+
_ uint64) uint64 {
8180

8281
hop := route.Hop{
8382
BlindingPoint: b.blindingPoint,
84-
LegacyPayload: false,
8583
EncryptedData: b.cipherText,
8684
}
8785

@@ -97,11 +95,11 @@ var _ AdditionalEdge = (*BlindedEdge)(nil)
9795
// defaultHopPayloadSize is the default payload size of a normal (not-blinded)
9896
// hop in the route.
9997
func defaultHopPayloadSize(amount lnwire.MilliSatoshi, expiry uint32,
100-
legacy bool, channelID uint64) uint64 {
98+
channelID uint64) uint64 {
10199

102100
// The payload size of a cleartext intermediate hop is equal to the
103101
// payload size of a private edge therefore we reuse its size function.
104102
edge := PrivateEdge{}
105103

106-
return edge.IntermediatePayloadSize(amount, expiry, legacy, channelID)
104+
return edge.IntermediatePayloadSize(amount, expiry, channelID)
107105
}

routing/additional_edge_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,12 @@ func TestIntermediatePayloadSize(t *testing.T) {
2727
nextHop uint64
2828
edge AdditionalEdge
2929
}{
30-
{
31-
name: "Legacy payload private edge",
32-
hop: route.Hop{
33-
AmtToForward: 1000,
34-
OutgoingTimeLock: 600000,
35-
ChannelID: 3432483437438,
36-
LegacyPayload: true,
37-
},
38-
nextHop: 1,
39-
edge: &PrivateEdge{},
40-
},
4130
{
4231
name: "Tlv payload private edge",
4332
hop: route.Hop{
4433
AmtToForward: 1000,
4534
OutgoingTimeLock: 600000,
4635
ChannelID: 3432483437438,
47-
LegacyPayload: false,
4836
},
4937
nextHop: 1,
5038
edge: &PrivateEdge{},
@@ -86,7 +74,6 @@ func TestIntermediatePayloadSize(t *testing.T) {
8674
IntermediatePayloadSize(
8775
testCase.hop.AmtToForward,
8876
testCase.hop.OutgoingTimeLock,
89-
testCase.hop.LegacyPayload,
9077
testCase.nextHop,
9178
)
9279

routing/blinding_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,10 @@ func TestBlindedPaymentToHints(t *testing.T) {
202202
// The arguments we use for the payload do not matter as long as
203203
// both functions return the same payload.
204204
expectedPayloadSize := expectedHint[0].IntermediatePayloadSize(
205-
0, 0, false, 0,
205+
0, 0, 0,
206206
)
207207
actualPayloadSize := actualHint[0].IntermediatePayloadSize(
208-
0, 0, false, 0,
208+
0, 0, 0,
209209
)
210210

211211
require.Equal(t, expectedPayloadSize, actualPayloadSize)

routing/mocks.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

routing/pathfind.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -659,8 +659,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
659659

660660
// The payload size of the final hop differ from intermediate hops
661661
// and depends on whether the destination is blinded or not.
662-
lastHopPayloadSize := lastHopPayloadSize(r, finalHtlcExpiry, amt,
663-
!features.HasFeature(lnwire.TLVOnionPayloadOptional))
662+
lastHopPayloadSize := lastHopPayloadSize(r, finalHtlcExpiry, amt)
664663

665664
// We can't always assume that the end destination is publicly
666665
// advertised to the network so we'll manually include the target node.
@@ -882,14 +881,10 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
882881
return
883882
}
884883

885-
supportsTlv := fromFeatures.HasFeature(
886-
lnwire.TLVOnionPayloadOptional,
887-
)
888-
889884
payloadSize = edge.hopPayloadSizeFn(
890885
amountToSend,
891886
uint32(toNodeDist.incomingCltv),
892-
!supportsTlv, edge.policy.ChannelID,
887+
edge.policy.ChannelID,
893888
)
894889
}
895890

@@ -1176,7 +1171,7 @@ func getProbabilityBasedDist(weight int64, probability float64,
11761171
// It depends on the tlv types which are present and also whether the hop is
11771172
// part of a blinded route or not.
11781173
func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
1179-
amount lnwire.MilliSatoshi, legacy bool) uint64 {
1174+
amount lnwire.MilliSatoshi) uint64 {
11801175

11811176
if r.BlindedPayment != nil {
11821177
blindedPath := r.BlindedPayment.BlindedPath.BlindedHops
@@ -1186,7 +1181,6 @@ func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
11861181
finalHop := route.Hop{
11871182
AmtToForward: amount,
11881183
OutgoingTimeLock: uint32(finalHtlcExpiry),
1189-
LegacyPayload: false,
11901184
EncryptedData: encryptedData,
11911185
}
11921186
if len(blindedPath) == 1 {
@@ -1214,7 +1208,6 @@ func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
12141208
AmtToForward: amount,
12151209
OutgoingTimeLock: uint32(finalHtlcExpiry),
12161210
CustomRecords: r.DestCustomRecords,
1217-
LegacyPayload: legacy,
12181211
MPP: mpp,
12191212
AMP: amp,
12201213
Metadata: r.Metadata,

0 commit comments

Comments
 (0)