Skip to content

Commit 6b64703

Browse files
authored
Merge pull request #8791 from ellemouton/assumeTLV
routing: assume TLV onion feature bit
2 parents fb416c2 + 738206f commit 6b64703

File tree

8 files changed

+55
-269
lines changed

8 files changed

+55
-269
lines changed

docs/release-notes/release-notes-0.18.1.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@
7979

8080
# Technical and Architectural Updates
8181
## BOLT Spec Updates
82+
83+
* Start assuming that all hops used during path-finding and route construction
84+
[support the TLV onion
85+
format](https://github.com/lightningnetwork/lnd/pull/8791).
86+
8287
## Testing
8388
## Database
8489
## Code Health
@@ -88,5 +93,6 @@
8893

8994
* Andras Banki-Horvath
9095
* Bufo
96+
* Elle Mouton
9197
* Matheus Degiovani
9298
* Slyghtning

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: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ func newRoute(sourceVertex route.Vertex,
161161
fee int64
162162
totalAmtMsatBlinded lnwire.MilliSatoshi
163163
outgoingTimeLock uint32
164-
tlvPayload bool
165164
customRecords record.CustomSet
166165
mpp *record.MPP
167166
metadata []byte
@@ -180,13 +179,6 @@ func newRoute(sourceVertex route.Vertex,
180179
return edge.ToNodeFeatures.HasFeature(feature)
181180
}
182181

183-
// We start by assuming the node doesn't support TLV. We'll now
184-
// inspect the node's feature vector to see if we can promote
185-
// the hop. We assume already that the feature vector's
186-
// transitive dependencies have already been validated by path
187-
// finding or some other means.
188-
tlvPayload = supports(lnwire.TLVOnionPayloadOptional)
189-
190182
if i == len(pathEdges)-1 {
191183
// If this is the last hop, then the hop payload will
192184
// contain the exact amount. In BOLT #4: Onion Routing
@@ -204,12 +196,7 @@ func newRoute(sourceVertex route.Vertex,
204196
totalTimeLock += uint32(finalHop.cltvDelta)
205197
outgoingTimeLock = totalTimeLock
206198

207-
// Attach any custom records to the final hop if the
208-
// receiver supports TLV.
209-
if !tlvPayload && finalHop.records != nil {
210-
return nil, errors.New("cannot attach " +
211-
"custom records")
212-
}
199+
// Attach any custom records to the final hop.
213200
customRecords = finalHop.records
214201

215202
// If we're attaching a payment addr but the receiver
@@ -275,7 +262,6 @@ func newRoute(sourceVertex route.Vertex,
275262
ChannelID: edge.ChannelID,
276263
AmtToForward: amtToForward,
277264
OutgoingTimeLock: outgoingTimeLock,
278-
LegacyPayload: !tlvPayload,
279265
CustomRecords: customRecords,
280266
MPP: mpp,
281267
Metadata: metadata,
@@ -659,8 +645,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
659645

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

665650
// We can't always assume that the end destination is publicly
666651
// advertised to the network so we'll manually include the target node.
@@ -882,14 +867,10 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
882867
return
883868
}
884869

885-
supportsTlv := fromFeatures.HasFeature(
886-
lnwire.TLVOnionPayloadOptional,
887-
)
888-
889870
payloadSize = edge.hopPayloadSizeFn(
890871
amountToSend,
891872
uint32(toNodeDist.incomingCltv),
892-
!supportsTlv, edge.policy.ChannelID,
873+
edge.policy.ChannelID,
893874
)
894875
}
895876

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

11811162
if r.BlindedPayment != nil {
11821163
blindedPath := r.BlindedPayment.BlindedPath.BlindedHops
@@ -1186,7 +1167,6 @@ func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
11861167
finalHop := route.Hop{
11871168
AmtToForward: amount,
11881169
OutgoingTimeLock: uint32(finalHtlcExpiry),
1189-
LegacyPayload: false,
11901170
EncryptedData: encryptedData,
11911171
}
11921172
if len(blindedPath) == 1 {
@@ -1214,7 +1194,6 @@ func lastHopPayloadSize(r *RestrictParams, finalHtlcExpiry int32,
12141194
AmtToForward: amount,
12151195
OutgoingTimeLock: uint32(finalHtlcExpiry),
12161196
CustomRecords: r.DestCustomRecords,
1217-
LegacyPayload: legacy,
12181197
MPP: mpp,
12191198
AMP: amp,
12201199
Metadata: r.Metadata,

0 commit comments

Comments
 (0)