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

Function add_blindedpath

plugins/xpay/xpay.c:2009–2071  ·  view source on GitHub ↗

If it fails, returns error, otherwise NULL */

Source from the content-addressed store, hash-verified

2007
2008/* If it fails, returns error, otherwise NULL */
2009static char *add_blindedpath(const tal_t *ctx,
2010 struct request_batch *batch,
2011 struct command *aux_cmd,
2012 struct payment *payment,
2013 size_t blindedpath_num,
2014 const struct blinded_path *path,
2015 const struct blinded_payinfo *payinfo)
2016{
2017 struct xpay *xpay = xpay_of(payment->plugin);
2018 struct amount_msat big_cap, per_route_reduction;
2019 int badf;
2020 struct short_channel_id scid;
2021 struct node_id src, dst;
2022
2023 /* BOLT #12:
2024 * - SHOULD prefer to use earlier `invoice_paths` over later ones if
2025 * it has no other reason for preference.
2026 */
2027 /* We do this by telling askrene that the first one is the largest
2028 * capacity channel. */
2029
2030 /* We add these channels to our private layer. We start with assuming
2031 * they have 100x the capacity we need (including fees!): we'll figure
2032 * it out quickly if we're wrong, but this gives a success probability
2033 * of 99%. */
2034 if (!amount_msat_add(&per_route_reduction,
2035 payment->amount, payment->maxfee)
2036 || !amount_msat_mul(&big_cap,
2037 per_route_reduction,
2038 100 + (tal_count(payment->paths) - blindedpath_num))) {
2039 /* Going to fail route anyway! */
2040 per_route_reduction = AMOUNT_MSAT(0);
2041 big_cap = payment->amount;
2042 }
2043
2044 assert(path->first_node_id.is_pubkey);
2045
2046 /* BOLT #12:
2047 * - For each `invoice_blindedpay`.`payinfo`:
2048 * - MUST NOT use the corresponding `invoice_paths`.`path`
2049 * if `payinfo`.`features` has any unknown even bits set.
2050 * - MUST reject the invoice if this leaves no usable paths.
2051 */
2052 badf = features_unsupported(plugin_feature_set(payment->plugin),
2053 payinfo->features,
2054 BOLT12_INVOICE_FEATURE);
2055 if (badf != -1)
2056 return tal_fmt(ctx, "unknown feature %i", badf);
2057
2058 node_id_from_pubkey(&src, &path->first_node_id.pubkey);
2059 node_id_from_pubkey(&dst, &xpay->fakenode);
2060 /* We make the "scid" for the blinded path block 0, which is impossible */
2061 scid.u64 = blindedpath_num;
2062
2063 add_fake_channel(aux_cmd, batch, payment,
2064 &src, &dst, scid, big_cap,
2065 payinfo->htlc_minimum_msat,
2066 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