Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Routing hints balance #1443

Merged
merged 4 commits into from
Jun 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ object RouteCalculation {

// we convert extra routing info provided in the payment request to fake channel_update
// it takes precedence over all other channel_updates we know
val assistedChannels: Map[ShortChannelId, AssistedChannel] = r.assistedRoutes.flatMap(toAssistedChannels(_, r.target, r.amount)).toMap
val assistedChannels: Map[ShortChannelId, AssistedChannel] = r.assistedRoutes.flatMap(toAssistedChannels(_, r.target, r.amount))
.filterNot { case (_, ac) => ac.extraHop.nodeId == r.source } // we ignore routing hints for our own channels, we have more accurate information
.toMap
val extraEdges = assistedChannels.values.map(ac =>
GraphEdge(ChannelDesc(ac.extraHop.shortChannelId, ac.extraHop.nodeId, ac.nextNodeId), toFakeUpdate(ac.extraHop, ac.htlcMaximum), htlcMaxToCapacity(ac.htlcMaximum), Some(ac.htlcMaximum))
).toSet
Expand Down Expand Up @@ -107,7 +109,7 @@ object RouteCalculation {
// should be able to route the payment, so we'll compute an htlcMaximumMsat accordingly.
// We could also get the channel capacity from the blockchain (since we have the shortChannelId) but that's more expensive.
// We also need to make sure the channel isn't excluded by our heuristics.
val lastChannelCapacity = amount.max(RoutingHeuristics.CAPACITY_CHANNEL_LOW)
val lastChannelCapacity = (amount * 2).max(RoutingHeuristics.CAPACITY_CHANNEL_LOW)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this, except if we have a real reason behind this change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indeed shouldn't be necessary, I reverted it in aaf17b6

val nextNodeIds = extraRoute.map(_.nodeId).drop(1) :+ targetNodeId
extraRoute.zip(nextNodeIds).reverse.foldLeft((lastChannelCapacity, Map.empty[ShortChannelId, AssistedChannel])) {
case ((amount, acs), (extraHop: ExtraHop, nextNodeId)) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@ class RouteCalculationSpec extends AnyFunSuite with ParallelTestExecution {
val amount = 90000 sat // below RoutingHeuristics.CAPACITY_CHANNEL_LOW
val assistedChannels = toAssistedChannels(extraHops, e, amount.toMilliSatoshi)

assert(assistedChannels(extraHop4.shortChannelId) === AssistedChannel(extraHop4, e, 100050.sat.toMilliSatoshi))
assert(assistedChannels(extraHop3.shortChannelId) === AssistedChannel(extraHop3, d, 100200.sat.toMilliSatoshi))
assert(assistedChannels(extraHop2.shortChannelId) === AssistedChannel(extraHop2, c, 100400.sat.toMilliSatoshi))
assert(assistedChannels(extraHop1.shortChannelId) === AssistedChannel(extraHop1, b, 101416.sat.toMilliSatoshi))
assert(assistedChannels(extraHop4.shortChannelId) === AssistedChannel(extraHop4, e, 180050.sat.toMilliSatoshi))
assert(assistedChannels(extraHop3.shortChannelId) === AssistedChannel(extraHop3, d, 180200.sat.toMilliSatoshi))
assert(assistedChannels(extraHop2.shortChannelId) === AssistedChannel(extraHop2, c, 180400.sat.toMilliSatoshi))
assert(assistedChannels(extraHop1.shortChannelId) === AssistedChannel(extraHop1, b, 182216.sat.toMilliSatoshi))
}

test("blacklist routes") {
Expand Down