| 1454 | } |
| 1455 | |
| 1456 | static struct command_result *do_inject(struct command *aux_cmd, |
| 1457 | struct attempt *attempt) |
| 1458 | { |
| 1459 | struct out_req *req; |
| 1460 | const struct xpay_onion *xpay_onion; |
| 1461 | struct xpay *xpay = xpay_of(attempt->payment->plugin); |
| 1462 | /* In case a block comes in, we give CLTVs an extra 1. */ |
| 1463 | u32 effective_bheight = xpay->blockheight + 1; |
| 1464 | |
| 1465 | xpay_onion = create_onion(tmpctx, attempt, effective_bheight); |
| 1466 | if (!xpay_onion->raw_onion) { |
| 1467 | char *error; |
| 1468 | size_t total = |
| 1469 | xpay_onion->forward_bytes + xpay_onion->tail_bytes; |
| 1470 | if (total > ROUTING_INFO_SIZE) |
| 1471 | error = tal_fmt( |
| 1472 | tmpctx, |
| 1473 | "%zu bytes needed (%" PRIu32 |
| 1474 | " hops using %zu bytes, plus %zu bytes for the " |
| 1475 | "final payload or blinded path)", |
| 1476 | total, xpay_onion->num_forwards, |
| 1477 | xpay_onion->forward_bytes, xpay_onion->tail_bytes); |
| 1478 | else |
| 1479 | error = tal_fmt(tmpctx, "failed to derive shared secrets"); |
| 1480 | |
| 1481 | payment_log(attempt->payment, LOG_BROKEN, |
| 1482 | "create_onion failed: %s", error); |
| 1483 | payment_give_up(aux_cmd, attempt->payment, |
| 1484 | PAY_UNSPECIFIED_ERROR, |
| 1485 | "Could not create payment onion: %s", error); |
| 1486 | return command_still_pending(aux_cmd); |
| 1487 | } |
| 1488 | |
| 1489 | outgoing_notify_start(attempt); |
| 1490 | attempt->start_time = time_mono(); |
| 1491 | |
| 1492 | req = jsonrpc_request_start(aux_cmd, |
| 1493 | "injectpaymentonion", |
| 1494 | injectpaymentonion_succeeded, |
| 1495 | injectpaymentonion_failed, |
| 1496 | attempt); |
| 1497 | json_add_hex_talarr(req->js, "onion", xpay_onion->raw_onion); |
| 1498 | json_add_sha256(req->js, "payment_hash", &attempt->payment->payment_hash); |
| 1499 | /* If no route, its the same as delivery (self-pay) */ |
| 1500 | json_add_amount_msat(req->js, "amount_msat", inject_amount(attempt)); |
| 1501 | json_add_u32(req->js, "cltv_expiry", initial_cltv_delta(attempt) + effective_bheight); |
| 1502 | json_add_u64(req->js, "partid", attempt->partid); |
| 1503 | json_add_u64(req->js, "groupid", attempt->payment->group_id); |
| 1504 | /* Use invstring for payments, destination directly for keysend */ |
| 1505 | if (attempt->payment->invstring) |
| 1506 | json_add_string(req->js, "invstring", attempt->payment->invstring); |
| 1507 | else |
| 1508 | json_add_pubkey(req->js, "destination", &attempt->payment->destination); |
| 1509 | json_add_amount_msat(req->js, "destination_msat", attempt_deliver(attempt)); |
| 1510 | if (attempt->payment->localinvreqid) |
| 1511 | json_add_sha256(req->js, "localinvreqid", attempt->payment->localinvreqid); |
| 1512 | if (attempt->payment->label) |
| 1513 | json_add_escaped_string(req->js, "label", attempt->payment->label); |
no test coverage detected