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

Function payment_chanhints_apply_route

plugins/libplugin-pay.c:509–584  ·  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

507 * through, since the balances really changed in that case.
508 */
509static bool payment_chanhints_apply_route(struct payment *p)
510{
511 bool apply;
512 struct route_hop *curhop;
513 struct channel_hint *curhint;
514 struct payment *root = payment_root(p);
515 assert(p->route != NULL);
516
517 /* First round: make sure we can cleanly apply the update. */
518 for (size_t i = 0; i < tal_count(p->route); i++) {
519 curhop = &p->route[i];
520 curhint = payment_chanhints_get(root, curhop);
521
522 /* If we don't have a hint we can't fail updating it. */
523 if (!curhint)
524 continue;
525
526 /* For local channels we check that we don't overwhelm
527 * them with too many HTLCs. */
528 apply = (!curhint->local) ||
529 (curhint->local->htlc_budget > 0);
530
531 /* For all channels we check that they have a
532 * sufficiently large estimated capacity to have some
533 * chance of succeeding. */
534 apply &= amount_msat_greater_eq(curhint->estimated_capacity,
535 curhop->amount);
536
537 if (!apply) {
538 /* This can happen in case of multiple
539 * concurrent getroute calls using the
540 * same channel_hints, no biggy, it's
541 * an estimation anyway. */
542 paymod_log(p, LOG_DBG,
543 "Could not update the channel hint "
544 "for %s. Could be a concurrent "
545 "`getroute` call.",
546 fmt_short_channel_id_dir(tmpctx,
547 &curhint->scid));
548 paymod_log(
549 p, LOG_DBG,
550 "Capacity: estimated_capacity=%s, hop_amount=%s. "
551 "local=%s%s",
552 fmt_amount_msat(tmpctx, curhint->estimated_capacity),
553 fmt_amount_msat(tmpctx, curhop->amount),
554 curhint->local ? "Y" : "N",
555 curhint->local ?
556 tal_fmt(tmpctx, " HTLC Budget: htlc_budget=%d",
557 curhint->local->htlc_budget) : "");
558 return false;
559 }
560 }
561
562 /* Second round: apply the changes, now that we know they'll succeed. */
563 for (size_t i = 0; i < tal_count(p->route); i++) {
564 curhop = &p->route[i];
565 curhint = payment_chanhints_get(root, curhop);
566 if (!curhint)

Callers 1

Calls 8

payment_rootFunction · 0.85
payment_chanhints_getFunction · 0.85
amount_msat_greater_eqFunction · 0.85
paymod_logFunction · 0.85
fmt_short_channel_id_dirFunction · 0.85
amount_msat_deductFunction · 0.85
abortFunction · 0.85
fmt_amount_msatFunction · 0.50

Tested by

no test coverage detected