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