Prioritize costs over distance, but bias to larger channels. */
| 756 | |
| 757 | /* Prioritize costs over distance, but bias to larger channels. */ |
| 758 | static 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 | |
| 794 | static struct route_hop *route(const tal_t *ctx, |
| 795 | struct gossmap *gossmap, |