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

Function create_onion

plugins/xpay/xpay.c:1385–1454  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

do_injectFunction · 0.70

Calls 12

xpay_ofFunction · 0.85
attempt_mpp_amountFunction · 0.85
sphinx_path_newFunction · 0.85
append_blinded_payloadsFunction · 0.85
onion_forward_payloadFunction · 0.85
onion_final_payloadFunction · 0.85
attempt_deliverFunction · 0.85
create_onionpacketFunction · 0.85
serialize_onionpacketFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected