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