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

Function create_onion

plugins/xpay/xpay.c:1404–1464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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_nonfinal_hopFunction · 0.85
onion_final_hopFunction · 0.85
attempt_deliverFunction · 0.85
hop_appendFunction · 0.85
create_onionpacketFunction · 0.85
serialize_onionpacketFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected