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

Function add_blindedpath

plugins/xpay/xpay.c:2078–2140  ·  view source on GitHub ↗

If it fails, returns error, otherwise NULL */

Source from the content-addressed store, hash-verified

2076
2077/* If it fails, returns error, otherwise NULL */
2078static char *add_blindedpath(const tal_t *ctx,
2079 struct request_batch *batch,
2080 struct command *aux_cmd,
2081 struct payment *payment,
2082 size_t blindedpath_num,
2083 const struct blinded_path *path,
2084 const struct blinded_payinfo *payinfo)
2085{
2086 struct xpay *xpay = xpay_of(payment->plugin);
2087 struct amount_msat big_cap, per_route_reduction;
2088 int badf;
2089 struct short_channel_id scid;
2090 struct node_id src, dst;
2091
2092 /* BOLT #12:
2093 * - SHOULD prefer to use earlier `invoice_paths` over later ones if
2094 * it has no other reason for preference.
2095 */
2096 /* We do this by telling askrene that the first one is the largest
2097 * capacity channel. */
2098
2099 /* We add these channels to our private layer. We start with assuming
2100 * they have 100x the capacity we need (including fees!): we'll figure
2101 * it out quickly if we're wrong, but this gives a success probability
2102 * of 99%. */
2103 if (!amount_msat_add(&per_route_reduction,
2104 payment->amount, payment->maxfee)
2105 || !amount_msat_mul(&big_cap,
2106 per_route_reduction,
2107 100 + (tal_count(payment->paths) - blindedpath_num))) {
2108 /* Going to fail route anyway! */
2109 per_route_reduction = AMOUNT_MSAT(0);
2110 big_cap = payment->amount;
2111 }
2112
2113 assert(path->first_node_id.is_pubkey);
2114
2115 /* BOLT #12:
2116 * - For each `invoice_blindedpay`.`payinfo`:
2117 * - MUST NOT use the corresponding `invoice_paths`.`path`
2118 * if `payinfo`.`features` has any unknown even bits set.
2119 * - MUST reject the invoice if this leaves no usable paths.
2120 */
2121 badf = features_unsupported(plugin_feature_set(payment->plugin),
2122 payinfo->features,
2123 BOLT12_INVOICE_FEATURE);
2124 if (badf != -1)
2125 return tal_fmt(ctx, "unknown feature %i", badf);
2126
2127 node_id_from_pubkey(&src, &path->first_node_id.pubkey);
2128 node_id_from_pubkey(&dst, &xpay->fakenode);
2129 /* We make the "scid" for the blinded path block 0, which is impossible */
2130 scid.u64 = blindedpath_num;
2131
2132 add_fake_channel(aux_cmd, batch, payment,
2133 &src, &dst, scid, big_cap,
2134 payinfo->htlc_minimum_msat,
2135 payinfo->htlc_maximum_msat,

Callers 1

populate_private_layerFunction · 0.85

Calls 8

xpay_ofFunction · 0.85
amount_msat_addFunction · 0.85
amount_msat_mulFunction · 0.85
node_id_from_pubkeyFunction · 0.85
add_fake_channelFunction · 0.85
amount_msatClass · 0.70
features_unsupportedFunction · 0.50
plugin_feature_setFunction · 0.50

Tested by

no test coverage detected