| 1391 | } |
| 1392 | |
| 1393 | static const u8 *create_onion(const tal_t *ctx, |
| 1394 | struct attempt *attempt, |
| 1395 | u32 effective_bheight) |
| 1396 | { |
| 1397 | struct xpay *xpay = xpay_of(attempt->payment->plugin); |
| 1398 | bool blinded_path = false; |
| 1399 | struct onionpacket *packet; |
| 1400 | struct sphinx_path *sp; |
| 1401 | const u8 *payload, *ret; |
| 1402 | const struct pubkey *node; |
| 1403 | const struct amount_msat mpp_amount = attempt_mpp_amount(attempt); |
| 1404 | |
| 1405 | sp = sphinx_path_new(ctx, attempt->payment->payment_hash.u.u8, |
| 1406 | sizeof(attempt->payment->payment_hash.u.u8)); |
| 1407 | |
| 1408 | /* First hop is to the local node */ |
| 1409 | node = &xpay->local_id; |
| 1410 | |
| 1411 | for (size_t i = 0; i < tal_count(attempt->hops); i++) { |
| 1412 | const struct hop *hop = &attempt->hops[i]; |
| 1413 | |
| 1414 | if (pubkey_eq(&hop->next_node, &xpay->fakenode) |
| 1415 | && hop->scidd.scid.u64 < tal_count(attempt->payment->paths)) { |
| 1416 | blinded_path = true; |
| 1417 | append_blinded_payloads(sp, attempt, effective_bheight, |
| 1418 | hop->scidd.scid.u64); |
| 1419 | /* This must be at the end, unless they put the fake nodeid |
| 1420 | * in a layer, in which case it doesn't matter what we put |
| 1421 | * in the rest of the onion. */ |
| 1422 | break; |
| 1423 | } |
| 1424 | /* We tell it how much to send *out* */ |
| 1425 | payload = onion_nonfinal_hop(NULL, &hop->scidd.scid, hop->amount_out, |
| 1426 | hop->cltv_value_out + effective_bheight); |
| 1427 | sphinx_add_hop_has_length(sp, node, take(payload)); |
| 1428 | node = &hop->next_node; |
| 1429 | } |
| 1430 | |
| 1431 | /* If we use a blinded path, final has to be special, so |
| 1432 | * that's done in append_blinded_payloads. */ |
| 1433 | if (!blinded_path) { |
| 1434 | u8 *final = onion_final_hop(NULL, |
| 1435 | attempt_deliver(attempt), |
| 1436 | attempt->payment->final_cltv + effective_bheight, |
| 1437 | mpp_amount, |
| 1438 | attempt->payment->payment_secret, |
| 1439 | attempt->payment->payment_metadata); |
| 1440 | hop_append(&final, attempt->payment->extra_tlvs); |
| 1441 | sphinx_add_hop_has_length(sp, node, take(final)); |
| 1442 | } |
| 1443 | |
| 1444 | /* Fails if would be too long */ |
| 1445 | packet = create_onionpacket(attempt, sp, ROUTING_INFO_SIZE, |
| 1446 | &attempt->shared_secrets); |
| 1447 | if (!packet) |
| 1448 | return NULL; |
| 1449 | |
| 1450 | ret = serialize_onionpacket(ctx, packet); |
no test coverage detected