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

View File

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