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

Function routehint_excluded

plugins/libplugin-pay.c:2518–2575  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2516 const struct route_info *route, size_t num_route);
2517
2518static bool routehint_excluded(struct payment *p,
2519 const struct route_info *routehint)
2520{
2521 const struct node_id *nodes = payment_get_excluded_nodes(tmpctx, p);
2522 const struct short_channel_id_dir *chans =
2523 payment_get_excluded_channels(tmpctx, p);
2524 const struct channel_hint *hints = payment_root(p)->channel_hints;
2525
2526 /* Note that we ignore direction here: in theory, we could have
2527 * found that one direction of a channel is unavailable, but they
2528 * are suggesting we use it the other way. Very unlikely though! */
2529 for (size_t i = 0; i < tal_count(routehint); i++) {
2530 const struct route_info *r = &routehint[i];
2531 for (size_t j = 0; j < tal_count(nodes); j++)
2532 if (node_id_eq(&r->pubkey, &nodes[j]))
2533 return true;
2534
2535 for (size_t j = 0; j < tal_count(chans); j++)
2536 if (short_channel_id_eq(&chans[j].scid, &r->short_channel_id))
2537 return true;
2538
2539 /* Skip the capacity check if this is the last hop
2540 * in the routehint.
2541 * The last hop in the routehint delivers the exact
2542 * final amount to the destination, which
2543 * payment_get_excluded_channels uses for excluding
2544 * already.
2545 * Thus, the capacity check below only really matters
2546 * for multi-hop routehints.
2547 */
2548 if (i == tal_count(routehint) - 1)
2549 continue;
2550
2551 /* Check our capacity fits. */
2552 struct amount_msat needed_capacity;
2553 if (!route_msatoshi(&needed_capacity, p->amount,
2554 r + 1, tal_count(routehint) - i - 1))
2555 return true;
2556 /* Why do we scan the hints again if
2557 * payment_get_excluded_channels already does?
2558 * Because payment_get_excluded_channels checks the
2559 * amount at destination, but we know that we are
2560 * a specific distance from the destination and we
2561 * know the exact capacity we need to send via this
2562 * channel, which is greater than the destination.
2563 */
2564 for (size_t j = 0; j < tal_count(hints); j++) {
2565 if (!short_channel_id_eq(&hints[j].scid.scid, &r->short_channel_id))
2566 continue;
2567 /* We exclude on equality because we set the estimate
2568 * to the smallest failed attempt. */
2569 if (amount_msat_greater_eq(needed_capacity,
2570 hints[j].estimated_capacity))
2571 return true;
2572 }
2573 }
2574 return false;
2575}

Callers 1

next_routehintFunction · 0.85

Calls 6

payment_rootFunction · 0.85
node_id_eqFunction · 0.85
route_msatoshiFunction · 0.85
amount_msat_greater_eqFunction · 0.85

Tested by

no test coverage detected