FIXME: This is naive: * - Only creates if we have no public channels. * - Always creates a path from direct neighbor. * - Doesn't append dummy hops. * - Doesn't pad to length. */
| 264 | * - Doesn't pad to length. |
| 265 | */ |
| 266 | static struct command_result *found_best_peer(struct command *cmd, |
| 267 | const struct chaninfo *best, |
| 268 | struct invreq *ir) |
| 269 | { |
| 270 | struct offers_data *od = get_offers_data(cmd->plugin); |
| 271 | |
| 272 | /* BOLT #12: |
| 273 | * - MUST include `invoice_paths` containing one or more paths to the node. |
| 274 | * - MUST specify `invoice_paths` in order of most-preferred to |
| 275 | * least-preferred if it has a preference. |
| 276 | * - MUST include `invoice_blindedpay` with exactly one `blinded_payinfo` |
| 277 | * for each `blinded_path` in `paths`, in order. |
| 278 | */ |
| 279 | if (!best) { |
| 280 | /* Don't allow bare invoices if they explicitly told us to front */ |
| 281 | if (ir->fronting_nodes) { |
| 282 | return fail_invreq(cmd, ir, |
| 283 | "Could not find path from %zu nodes (%s%s)", |
| 284 | tal_count(ir->fronting_nodes), |
| 285 | fmt_pubkey(tmpctx, &ir->fronting_nodes[0]), |
| 286 | tal_count(ir->fronting_nodes) > 1 ? ", ..." : ""); |
| 287 | } |
| 288 | |
| 289 | /* Note: since we don't make one, createinvoice adds a dummy. */ |
| 290 | plugin_log(cmd->plugin, LOG_UNUSUAL, |
| 291 | "No incoming channel for %s, so no blinded path", |
| 292 | fmt_amount_msat(tmpctx, |
| 293 | amount_msat(*ir->inv->invoice_amount))); |
| 294 | } else { |
| 295 | struct tlv_encrypted_data_tlv **etlvs; |
| 296 | struct pubkey *ids; |
| 297 | struct short_channel_id **scids; |
| 298 | u32 base; |
| 299 | |
| 300 | /* Make a small 1-hop path to us */ |
| 301 | ids = tal_arr(tmpctx, struct pubkey, 2); |
| 302 | ids[0] = best->id; |
| 303 | ids[1] = od->id; |
| 304 | |
| 305 | /* This does nothing unless dev_invoice_internal_scid is set */ |
| 306 | scids = tal_arrz(tmpctx, struct short_channel_id *, 2); |
| 307 | scids[1] = od->dev_invoice_internal_scid; |
| 308 | |
| 309 | /* Make basic tlvs, add payment restrictions */ |
| 310 | etlvs = new_encdata_tlvs(tmpctx, ids, |
| 311 | cast_const2(const struct short_channel_id **, |
| 312 | scids)); |
| 313 | |
| 314 | /* Tell the first node what restrictions we have on relaying */ |
| 315 | etlvs[0]->payment_relay = tal(etlvs[0], |
| 316 | struct tlv_encrypted_data_tlv_payment_relay); |
| 317 | etlvs[0]->payment_relay->cltv_expiry_delta = best->cltv; |
| 318 | etlvs[0]->payment_relay->fee_base_msat = best->feebase; |
| 319 | etlvs[0]->payment_relay->fee_proportional_millionths = best->feeppm; |
| 320 | |
| 321 | /* BOLT #12: |
| 322 | * - if the expiry for accepting payment is not 7200 seconds |
| 323 | * after `invoice_created_at`: |
nothing calls this directly
no test coverage detected