routing/pathfind: consolidate population of custom records

This commit is contained in:
Conner Fromknecht 2019-12-18 23:56:23 -08:00
parent cddb71ee53
commit 7965cb08db
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7

@ -151,6 +151,7 @@ func newRoute(sourceVertex route.Vertex,
fee lnwire.MilliSatoshi
outgoingTimeLock uint32
tlvPayload bool
customRecords record.CustomSet
)
// Define a helper function that checks this edge's feature
@ -182,6 +183,14 @@ func newRoute(sourceVertex route.Vertex,
// last link in the route.
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")
}
customRecords = finalHop.records
} else {
// The amount that the current hop needs to forward is
// equal to the incoming amount of the next hop.
@ -210,12 +219,7 @@ func newRoute(sourceVertex route.Vertex,
AmtToForward: amtToForward,
OutgoingTimeLock: outgoingTimeLock,
LegacyPayload: !tlvPayload,
}
// If this is the last hop, then we'll populate any TLV records
// destined for it.
if i == len(pathEdges)-1 && len(finalHop.records) != 0 {
currentHop.CustomRecords = finalHop.records
CustomRecords: customRecords,
}
hops = append([]*route.Hop{currentHop}, hops...)