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

Function payment_chanhints_apply_route

plugins/libplugin-pay.c:489–581  ·  view source on GitHub ↗

Given a route and a couple of channel hints, apply the route to the channel * hints, so we have a better estimation of channel's capacity. We apply a * route to a channel hint before calling `sendonion` so subsequent `route` * calls don't accidentally try to use those out-of-date estimates. We unapply * if the payment failed, i.e., all HTLCs we might have added have been torn * down again. Fi

Source from the content-addressed store, hash-verified

487 * argument indicates whether we want to apply (`remove=false`), or clear a
488 * prior application (`remove=true`). */
489static bool payment_chanhints_apply_route(struct payment *p, bool remove)
490{
491 bool apply;
492 struct route_hop *curhop;
493 struct channel_hint *curhint;
494 struct payment *root = payment_root(p);
495 assert(p->route != NULL);
496
497 /* No need to check for applicability if we increase
498 * capacity and budgets. */
499 if (remove)
500 goto apply_changes;
501
502 /* First round: make sure we can cleanly apply the update. */
503 for (size_t i = 0; i < tal_count(p->route); i++) {
504 curhop = &p->route[i];
505 curhint = payment_chanhints_get(root, curhop);
506
507 /* If we don't have a hint we can't fail updating it. */
508 if (!curhint)
509 continue;
510
511 /* For local channels we check that we don't overwhelm
512 * them with too many HTLCs. */
513 apply = (!curhint->local) || curhint->htlc_budget > 0;
514
515 /* For all channels we check that they have a
516 * sufficiently large estimated capacity to have some
517 * chance of succeeding. */
518 apply &= amount_msat_greater_eq(curhint->estimated_capacity,
519 curhop->amount);
520
521 if (!apply) {
522 /* This can happen in case of multiple
523 * concurrent getroute calls using the
524 * same channel_hints, no biggy, it's
525 * an estimation anyway. */
526 paymod_log(p, LOG_DBG,
527 "Could not update the channel hint "
528 "for %s. Could be a concurrent "
529 "`getroute` call.",
530 type_to_string(tmpctx,
531 struct short_channel_id_dir,
532 &curhint->scid));
533 paymod_log(
534 p, LOG_DBG,
535 "Capacity: estimated_capacity=%s, hop_amount=%s. "
536 "HTLC Budget: htlc_budget=%d, local=%d",
537 type_to_string(tmpctx, struct amount_msat,
538 &curhint->estimated_capacity),
539 type_to_string(tmpctx, struct amount_msat,
540 &curhop->amount),
541 curhint->htlc_budget, curhint->local);
542 return false;
543 }
544 }
545
546apply_changes:

Callers 2

Calls 8

payment_rootFunction · 0.85
payment_chanhints_getFunction · 0.85
amount_msat_greater_eqFunction · 0.85
paymod_logFunction · 0.85
amount_msat_addFunction · 0.85
abortFunction · 0.85
amount_msat_subFunction · 0.85
type_to_stringClass · 0.50

Tested by

no test coverage detected