routing: implement capacity in getEdge
This commit adds the maximal capacity between two nodes to the unified edge data. We use MaxHTLC as a replacement if the channel capacity is not available. In tests we use larger maxHTLC values to be able to convert to a non-zero sat capacity.
This commit is contained in:
2 files changed
+45
-3
No files matched your search
@@ -207,6 +207,7 @@ func (u *edgeUnifier) getEdgeNetwork(amt lnwire.MilliSatoshi) *unifiedEdge {
|
||||
bestPolicy *channeldb.CachedEdgePolicy
|
||||
maxFee lnwire.MilliSatoshi
|
||||
maxTimelock uint16
|
||||
maxCapMsat lnwire.MilliSatoshi
|
||||
)
|
||||
|
||||
for _, edge := range u.edges {
|
||||
@@ -222,6 +223,18 @@ func (u *edgeUnifier) getEdgeNetwork(amt lnwire.MilliSatoshi) *unifiedEdge {
|
||||
continue
|
||||
}
|
||||
|
||||
// Track the maximal capacity for usable channels. If we don't
|
||||
// know the capacity, we fall back to MaxHTLC.
|
||||
capMsat := lnwire.NewMSatFromSatoshis(edge.capacity)
|
||||
if capMsat == 0 && edge.policy.MessageFlags.HasMaxHtlc() {
|
||||
log.Tracef("No capacity available for channel %v, "+
|
||||
"using MaxHtlcMsat (%v) as a fallback.",
|
||||
edge.policy.ChannelID, edge.policy.MaxHTLC)
|
||||
|
||||
capMsat = edge.policy.MaxHTLC
|
||||
}
|
||||
maxCapMsat = lntypes.Max(capMsat, maxCapMsat)
|
||||
|
||||
// Track the maximum time lock of all channels that are
|
||||
// candidate for non-strict forwarding at the routing node.
|
||||
maxTimelock = lntypes.Max(
|
||||
@@ -257,6 +270,7 @@ func (u *edgeUnifier) getEdgeNetwork(amt lnwire.MilliSatoshi) *unifiedEdge {
|
||||
policyCopy := *bestPolicy
|
||||
modifiedEdge := unifiedEdge{policy: &policyCopy}
|
||||
modifiedEdge.policy.TimeLockDelta = maxTimelock
|
||||
modifiedEdge.capacity = maxCapMsat.ToSatoshis()
|
||||
|
||||
return &modifiedEdge
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user