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

Function route_score

common/test/run-route-infloop.c:71–105  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

69
70/* Prioritize costs over distance, but bias to larger channels. */
71static u64 route_score(struct amount_msat fee,
72 struct amount_msat risk,
73 struct amount_msat total,
74 int dir,
75 const struct gossmap_chan *c)
76{
77 double score;
78 struct amount_msat msat;
79
80 /* These two are comparable, so simply sum them. */
81 if (!amount_msat_add(&msat, fee, risk))
82 msat = AMOUNT_MSAT(-1ULL);
83
84 /* Slight tiebreaker bias: 1 msat per distance */
85 if (!amount_msat_accumulate(&msat, AMOUNT_MSAT(1)))
86 msat = AMOUNT_MSAT(-1ULL);
87
88 /* Percent penalty at different channel capacities:
89 * 1%: 1%
90 * 10%: 11%
91 * 25%: 29%
92 * 50%: 69%
93 * 75%: 138%
94 * 90%: 230%
95 * 95%: 300%
96 * 99%: 461%
97 */
98 score = (capacity_bias(gossmap, c, dir, total) + 1)
99 * msat.millisatoshis; /* Raw: Weird math */
100 if (score > 0xFFFFFFFF)
101 return 0xFFFFFFFF;
102
103 /* Cast unnecessary, but be explicit! */
104 return (u64)score;
105}
106
107int main(int argc, char *argv[])
108{

Callers

nothing calls this directly

Calls 3

amount_msat_addFunction · 0.85
amount_msat_accumulateFunction · 0.85
capacity_biasFunction · 0.70

Tested by

no test coverage detected