Make route path selection optimize strictly for `cost / amount`
authorMatt Corallo <git@bluematt.me>
Tue, 12 Jul 2022 20:35:36 +0000 (20:35 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 19 Jul 2022 15:16:35 +0000 (15:16 +0000)
commit985153e1284c9314f417d614a6a5de7e796c6ef7
tree8dde9c579ca49d7d3e8e2d0bd50851928774713d
parent0c3a47c0162c80062005e8187c16ee624498fdfd
Make route path selection optimize strictly for `cost / amount`

Currently, after we've selected a number of candidate paths, we
construct a route from a random set of paths repeatedly, and then
select the route with the lowest total cost. In the vast majority
of cases this ends up doing a bunch of additional work in order to
select the path(s) with the total lowest cost, with some vague
attempt at randomization that doesn't actually work.

Instead, here, we simply sort available paths by `cost / amount`
and select the top paths. This ends up in practice having the same
end result with substantially less complexity. In some rare cases
it gets a better result, which also would have been achieved
through more random trials. This implies there may in such cases be
a potential privacy loss, but not a substantial one, given our path
selection is ultimately mostly deterministic in many cases (or, if
it is not, then privacy is achieved through randomization at the
scorer level).
lightning/src/routing/router.rs