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

Function decode_onion

tests/plugins/channeld_fakenet.c:305–361  ·  view source on GitHub ↗

Sets current_node, *next_onion_packet, *shared_secret and *me, and decodes */

Source from the content-addressed store, hash-verified

303
304/* Sets current_node, *next_onion_packet, *shared_secret and *me, and decodes */
305static struct onion_payload *decode_onion(const tal_t *ctx,
306 struct info *info,
307 const u8 onion_routing_packet[],
308 const struct pubkey *path_key,
309 const struct sha256 *payment_hash,
310 struct amount_msat amount,
311 u32 cltv,
312 u8 **next_onion_packet,
313 struct secret *shared_secret,
314 struct gossmap_node **me)
315{
316 struct onionpacket *op;
317 enum onion_wire failcode;
318 struct route_step *rs = NULL;
319 struct onion_payload *payload;
320 u64 failtlvtype;
321 size_t failtlvpos;
322 const char *explanation;
323
324 op = parse_onionpacket(tmpctx, onion_routing_packet,
325 TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE),
326 &failcode);
327 if (!op)
328 status_failed(STATUS_FAIL_INTERNAL_ERROR,
329 "Could not parse onion (failcode %u)", failcode);
330
331 if (!ecdh_maybe_blinding(&op->ephemeralkey, path_key, shared_secret))
332 abort();
333 rs = process_onionpacket(tmpctx, op, shared_secret,
334 payment_hash->u.u8, sizeof(*payment_hash));
335 if (!rs)
336 status_failed(STATUS_FAIL_INTERNAL_ERROR,
337 "Could not decode onion for %s", current_node->name);
338 *next_onion_packet = get_next_onion(ctx, rs);
339
340 payload = onion_decode(tmpctx,
341 rs, path_key,
342 NULL,
343 amount,
344 cltv, &failtlvtype, &failtlvpos, &explanation);
345 if (!payload) {
346 status_failed(STATUS_FAIL_INTERNAL_ERROR,
347 "Failed tlvtype %"PRIu64" at %zu: %s",
348 failtlvtype, failtlvpos, explanation);
349 }
350
351 /* Find ourselves in the gossmap, so we know our channels */
352 *me = gossmap_find_node(info->gossmap, &current_node->id);
353 if (!*me)
354 status_failed(STATUS_FAIL_INTERNAL_ERROR,
355 "Cannot find %s (%s) in gossmap",
356 current_node->name,
357 fmt_node_id(tmpctx, &current_node->id));
358
359 status_debug("Unpacked onion for %s", current_node->name);
360 return payload;
361}
362

Callers 1

forward_htlcFunction · 0.85

Calls 9

parse_onionpacketFunction · 0.85
abortFunction · 0.85
process_onionpacketFunction · 0.85
get_next_onionFunction · 0.85
onion_decodeFunction · 0.85
gossmap_find_nodeFunction · 0.85
fmt_node_idFunction · 0.85
ecdh_maybe_blindingFunction · 0.70
status_failedFunction · 0.50

Tested by

no test coverage detected