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

Use correct cost comparison when evaluating candidate channels #1090

Merged
merged 2 commits into from
Jul 26, 2019

Conversation

araspitzu
Copy link
Contributor

@araspitzu araspitzu commented Jul 26, 2019

This PR fixes bug ACINQ/eclair-mobile#207 which was caused by an incorrect channel cost evaluation against its htlcMaximumMsat. The fix is to consider the correct channel cost.

…ng is within th range htlcMinimumMsat/htlcMaximumMsat of the candidate channel
@codecov-io
Copy link

codecov-io commented Jul 26, 2019

Codecov Report

Merging #1090 into master will increase coverage by 0.14%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1090      +/-   ##
==========================================
+ Coverage   82.64%   82.79%   +0.14%     
==========================================
  Files         101      101              
  Lines        7652     7653       +1     
  Branches      312      312              
==========================================
+ Hits         6324     6336      +12     
+ Misses       1328     1317      -11
Impacted Files Coverage Δ
.../src/main/scala/fr/acinq/eclair/router/Graph.scala 97.22% <100%> (+0.01%) ⬆️
...nq/eclair/blockchain/electrum/ElectrumClient.scala 73.23% <0%> (-0.38%) ⬇️
...-core/src/main/scala/fr/acinq/eclair/io/Peer.scala 74.92% <0%> (-0.31%) ⬇️
...c/main/scala/fr/acinq/eclair/channel/Channel.scala 84.47% <0%> (+0.46%) ⬆️
...src/main/scala/fr/acinq/eclair/router/Router.scala 86.76% <0%> (+0.94%) ⬆️
...clair/blockchain/electrum/ElectrumClientPool.scala 78.49% <0%> (+4.3%) ⬆️

@araspitzu araspitzu marked this pull request as ready for review July 26, 2019 13:56
@araspitzu araspitzu requested a review from sstone July 26, 2019 13:58
@@ -230,8 +230,8 @@ object Graph {
val newMinimumKnownWeight = edgeWeight(edge, currentWeight, initialWeight.length == 0 && neighbor == sourceNode, currentBlockHeight, wr)

// test for ignored edges
if (edge.update.htlcMaximumMsat.forall(newMinimumKnownWeight.cost + amountMsat <= _) &&
newMinimumKnownWeight.cost + amountMsat >= edge.update.htlcMinimumMsat &&
if (edge.update.htlcMaximumMsat.forall(newMinimumKnownWeight.cost <= _) &&
Copy link
Member

Choose a reason for hiding this comment

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

If amountMsat is not used here then it's not used at all in dijkstraShortestPath and should be removed from the parameter list. We then need to make sure that

val spurPath = dijkstraShortestPath(graph, spurEdge.desc.a, targetNode, amountMsat, ignoredEdges ++ edgesToIgnore.toSet ++ returningEdges.toSet, extraEdges, rootPathWeight, boundaries, currentBlockHeight, wr)
is correct

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this change dijkstraShortestPath will use only the cost found in the initialWeight parameter which is RichWeight(amountMsat, 0, 0, 0) for the initial step and when calculating the 'spurPath' for an alternative path this is the result of pathWeight so it's the cost to go from the starting node to this intermediate node (from here the algorithm will search for a different path). I will remove amountMsat from the parameter list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

f62f472 removes the unused parameter and also extracts the initialWeight parameter in the first invocation of dijkstraShortestPath, for more readability.

…eight in the first step of 'yenKshortestPaths'
@araspitzu araspitzu merged commit d88d376 into master Jul 26, 2019
@araspitzu araspitzu deleted the path_finding_fix_channel_costs_comparison branch July 26, 2019 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants