MCPcopy Create free account
hub / github.com/ElementsProject/lightning / route_score

Function route_score

plugins/libplugin-pay.c:733–749  ·  view source on GitHub ↗

Prioritize costs over distance, but bias to larger channels. */

Source from the content-addressed store, hash-verified

731
732/* Prioritize costs over distance, but bias to larger channels. */
733static u64 route_score(u32 distance,
734 struct amount_msat cost,
735 struct amount_msat risk,
736 int dir,
737 const struct gossmap_chan *c)
738{
739 u64 cmsat = cost.millisatoshis; /* Raw: lengthy math */
740 u64 rmsat = risk.millisatoshis; /* Raw: lengthy math */
741 u64 bias = capacity_bias(global_gossmap, c, dir, cost);
742
743 /* Smoothed harmonic mean to avoid division by 0 */
744 u64 costs = (cmsat * rmsat * bias) / (cmsat + rmsat + bias + 1);
745
746 if (costs > 0xFFFFFFFF)
747 costs = 0xFFFFFFFF;
748 return costs;
749}
750
751static struct route_hop *route(const tal_t *ctx,
752 struct gossmap *gossmap,

Callers

nothing calls this directly

Calls 1

capacity_biasFunction · 0.85

Tested by

no test coverage detected