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

Function best_candidate

plugins/topology.c:465–488  ·  view source on GitHub ↗

For deterministic results with bolt12/11 routes, we only return a * single candidate: choose the one with most capacity */

Source from the content-addressed store, hash-verified

463/* For deterministic results with bolt12/11 routes, we only return a
464 * single candidate: choose the one with most capacity */
465static size_t best_candidate(const struct gossmap *gossmap,
466 const struct gossmap_node *me)
467{
468 struct amount_msat best_cap = AMOUNT_MSAT(0);
469 size_t best_num = 0;
470 for (size_t i = 0; i < me->num_chans; i++) {
471 int dir;
472 struct gossmap_chan *ourchan;
473 struct amount_msat cap;
474 struct gossmap_node *peer;
475
476 ourchan = gossmap_nth_chan(gossmap, me, i, &dir);
477 if (ourchan->cupdate_off[!dir] == 0)
478 continue;
479
480 peer = gossmap_nth_node(gossmap, ourchan, !dir);
481 cap = peer_capacity(gossmap, me, peer, ourchan);
482 if (amount_msat_greater(cap, best_cap)) {
483 best_num = i;
484 best_cap = cap;
485 }
486 }
487 return best_num;
488}
489
490static struct command_result *
491listpeerchannels_listincoming_done(struct command *cmd,

Callers 1

Calls 4

gossmap_nth_chanFunction · 0.85
gossmap_nth_nodeFunction · 0.85
peer_capacityFunction · 0.85
amount_msat_greaterFunction · 0.85

Tested by

no test coverage detected