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

Function payment_compute_onion_payloads

plugins/libplugin-pay.c:1876–1963  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1874}
1875
1876static struct command_result *payment_compute_onion_payloads(struct payment *p)
1877{
1878 struct createonion_request *cr;
1879 size_t hopcount;
1880 struct payment *root = payment_root(p);
1881 char *routetxt = tal_strdup(tmpctx, "");
1882
1883 p->step = PAYMENT_STEP_ONION_PAYLOAD;
1884 hopcount = tal_count(p->route);
1885
1886 /* Now that we are about to fix the route parameters by
1887 * encoding them in an onion is the right time to update the
1888 * channel hints. */
1889 if (!payment_chanhints_apply_route(p)) {
1890 /* We can still end up with a failed channel_hints
1891 * update, either because a plugin changed the route,
1892 * or because a modifier was not synchronous, allowing
1893 * for multiple concurrent routes being built. If that
1894 * is the case, discard this route and retry. */
1895 payment_set_step(p, PAYMENT_STEP_RETRY_GETROUTE);
1896 return payment_continue(p);
1897 }
1898
1899 /* Now compute the payload we're about to pass to `createonion` */
1900 cr = p->createonion_request = tal(p, struct createonion_request);
1901 cr->assocdata = tal_arr(cr, u8, 0);
1902 towire_sha256(&cr->assocdata, p->payment_hash);
1903 cr->session_key = NULL;
1904 cr->hops = tal_arr(cr, struct createonion_hop,
1905 tal_count(p->route)
1906 + (root->blindedpath ? tal_count(root->blindedpath->path) - 1: 0));
1907
1908 /* Non-final hops */
1909 for (size_t i = 0; i < hopcount - 1; i++) {
1910 /* The message is destined for hop i, but contains fields for
1911 * i+1 */
1912 payment_add_hop_onion_payload(p, &cr->hops[i], &p->route[i],
1913 &p->route[i + 1], false,
1914 NULL, NULL);
1915 tal_append_fmt(&routetxt, "%s -> ",
1916 fmt_short_channel_id(tmpctx, p->route[i].scid));
1917 }
1918
1919 /* If we're headed to a blinded path, connect that now. */
1920 if (root->blindedpath) {
1921 /* This final_cltv matches our payment heuristic of adding 1 block. */
1922
1923 /* BOLT #4:
1924 * - For every node inside a blinded route:
1925 *...
1926 * - If it is the final node:
1927 *...
1928 * - The value set for `outgoing_cltv_value`:
1929 * - MUST use the current block height as a baseline value.
1930 * - if a [random offset](07-routing-gossip.md#recommendations-for-routing) was added to improve privacy:
1931 * - SHOULD add the offset to the baseline value.
1932 */
1933 u32 final_cltv = p->start_block + 1;

Callers 1

payment_continueFunction · 0.85

Calls 10

payment_rootFunction · 0.85
payment_set_stepFunction · 0.85
tal_append_fmtFunction · 0.85
fmt_short_channel_idFunction · 0.85
payment_add_blindedpathFunction · 0.85
paymod_logFunction · 0.85
payment_continueFunction · 0.70
towire_sha256Function · 0.50

Tested by

no test coverage detected