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

Function route_score

plugins/libplugin-pay.c:758–792  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

756
757/* Prioritize costs over distance, but bias to larger channels. */
758static u64 route_score(struct amount_msat fee,
759 struct amount_msat risk,
760 struct amount_msat total,
761 int dir,
762 const struct gossmap_chan *c)
763{
764 double score;
765 struct amount_msat msat;
766
767 /* These two are comparable, so simply sum them. */
768 if (!amount_msat_add(&msat, fee, risk))
769 msat = AMOUNT_MSAT(-1ULL);
770
771 /* Slight tiebreaker bias: 1 msat per distance */
772 if (!amount_msat_accumulate(&msat, AMOUNT_MSAT(1)))
773 msat = AMOUNT_MSAT(-1ULL);
774
775 /* Percent penalty at different channel capacities:
776 * 1%: 1%
777 * 10%: 11%
778 * 25%: 29%
779 * 50%: 69%
780 * 75%: 138%
781 * 90%: 230%
782 * 95%: 300%
783 * 99%: 461%
784 */
785 score = (capacity_bias(global_gossmap, c, dir, total) + 1)
786 * msat.millisatoshis; /* Raw: Weird math */
787 if (score != score || score > 0xFFFFFFFF)
788 return 0xFFFFFFFF;
789
790 /* Cast unnecessary, but be explicit! */
791 return (u64)score;
792}
793
794static struct route_hop *route(const tal_t *ctx,
795 struct gossmap *gossmap,

Callers 1

mainFunction · 0.50

Calls 3

amount_msat_addFunction · 0.85
amount_msat_accumulateFunction · 0.85
capacity_biasFunction · 0.70

Tested by 1

mainFunction · 0.40