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

Function payment_compute_onion_payloads

plugins/libplugin-pay.c:1669–1728  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1667}
1668
1669static void payment_compute_onion_payloads(struct payment *p)
1670{
1671 struct createonion_request *cr;
1672 size_t hopcount;
1673 struct payment *root = payment_root(p);
1674 char *routetxt = tal_strdup(tmpctx, "");
1675
1676 p->step = PAYMENT_STEP_ONION_PAYLOAD;
1677 hopcount = tal_count(p->route);
1678
1679 /* Now that we are about to fix the route parameters by
1680 * encoding them in an onion is the right time to update the
1681 * channel hints. */
1682 if (!payment_chanhints_apply_route(p, false)) {
1683 /* We can still end up with a failed channel_hints
1684 * update, either because a plugin changed the route,
1685 * or because a modifier was not synchronous, allowing
1686 * for multiple concurrent routes being built. If that
1687 * is the case, discard this route and retry. */
1688 payment_set_step(p, PAYMENT_STEP_RETRY_GETROUTE);
1689 return payment_continue(p);
1690 }
1691
1692 /* Now compute the payload we're about to pass to `createonion` */
1693 cr = p->createonion_request = tal(p, struct createonion_request);
1694 cr->assocdata = tal_arr(cr, u8, 0);
1695 towire_sha256(&cr->assocdata, p->payment_hash);
1696 cr->session_key = NULL;
1697 cr->hops = tal_arr(cr, struct createonion_hop, tal_count(p->route));
1698
1699 /* Non-final hops */
1700 for (size_t i = 0; i < hopcount - 1; i++) {
1701 /* The message is destined for hop i, but contains fields for
1702 * i+1 */
1703 payment_add_hop_onion_payload(p, &cr->hops[i], &p->route[i],
1704 &p->route[i + 1], false,
1705 NULL, NULL);
1706 tal_append_fmt(&routetxt, "%s -> ",
1707 type_to_string(tmpctx, struct short_channel_id,
1708 &p->route[i].scid));
1709 }
1710
1711 /* Final hop */
1712 payment_add_hop_onion_payload(
1713 p, &cr->hops[hopcount - 1], &p->route[hopcount - 1],
1714 &p->route[hopcount - 1], true,
1715 root->payment_secret, root->payment_metadata);
1716 tal_append_fmt(&routetxt, "%s",
1717 type_to_string(tmpctx, struct short_channel_id,
1718 &p->route[hopcount - 1].scid));
1719
1720 paymod_log(p, LOG_DBG,
1721 "Created outgoing onion for route: %s", routetxt);
1722
1723 p->routetxt = tal_steal(p, routetxt);
1724
1725 /* Now allow all the modifiers to mess with the payloads, before we
1726 * serialize via a call to createonion in the next step. */

Callers 1

payment_continueFunction · 0.85

Calls 9

payment_rootFunction · 0.85
payment_set_stepFunction · 0.85
payment_continueFunction · 0.85
tal_append_fmtFunction · 0.85
paymod_logFunction · 0.85
towire_sha256Function · 0.50
type_to_stringClass · 0.50

Tested by

no test coverage detected