Prioritize costs over distance, but bias to larger channels. */
| 69 | |
| 70 | /* Prioritize costs over distance, but bias to larger channels. */ |
| 71 | static 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 | |
| 107 | int main(int argc, char *argv[]) |
| 108 | { |
nothing calls this directly
no test coverage detected