| 302 | } |
| 303 | |
| 304 | static const u8 *create_onion( |
| 305 | const tal_t *ctx, const unsigned int blockheight, |
| 306 | const struct route_hop *route, const struct sha256 *payment_hash, |
| 307 | const u32 final_cltv_delta, const struct blinded_path *blinded_path, |
| 308 | const struct secret *payment_secret, const struct amount_msat total_amount, |
| 309 | const struct amount_msat deliver_amount, const u8 *metadata, |
| 310 | const struct node_id first_node, const size_t first_index, |
| 311 | struct secret **shared_secrets) |
| 312 | { |
| 313 | bool ret; |
| 314 | const tal_t *this_ctx = tal(ctx, tal_t); |
| 315 | struct node_id current_node = first_node; |
| 316 | struct pubkey node; |
| 317 | const u8 *payload; |
| 318 | const size_t pathlen = tal_count(route); |
| 319 | |
| 320 | struct sphinx_path *sp = sphinx_path_new(this_ctx, payment_hash->u.u8, |
| 321 | sizeof(payment_hash->u.u8)); |
| 322 | |
| 323 | for (size_t i = first_index; i < pathlen; i++) { |
| 324 | /* Encrypted message is for node[i] but the data is hop[i+1], |
| 325 | * therein lays the problem with sendpay's API. */ |
| 326 | ret = pubkey_from_node_id(&node, ¤t_node); |
| 327 | assert(ret); |
| 328 | |
| 329 | const struct route_hop *hop = &route[i]; |
| 330 | payload = onion_nonfinal_hop(this_ctx, &hop->scid, hop->amount, |
| 331 | hop->delay + blockheight); |
| 332 | // FIXME: better handle error here |
| 333 | ret = sphinx_add_hop_has_length(sp, &node, take(payload)); |
| 334 | assert(ret); |
| 335 | current_node = route[i].node_id; |
| 336 | } |
| 337 | |
| 338 | const u32 final_cltv = final_cltv_delta + blockheight; |
| 339 | if (blinded_path) { |
| 340 | sphinx_append_blinded_path(this_ctx, sp, blinded_path, |
| 341 | deliver_amount, total_amount, |
| 342 | final_cltv); |
| 343 | } else { |
| 344 | sphinx_append_final_hop(this_ctx, sp, payment_secret, |
| 345 | ¤t_node, deliver_amount, |
| 346 | total_amount, final_cltv, metadata); |
| 347 | } |
| 348 | |
| 349 | struct onionpacket *packet = |
| 350 | create_onionpacket(this_ctx, sp, ROUTING_INFO_SIZE, shared_secrets); |
| 351 | *shared_secrets = tal_steal(ctx, *shared_secrets); |
| 352 | |
| 353 | const u8 *onion = serialize_onionpacket(ctx, packet); |
| 354 | tal_free(this_ctx); |
| 355 | return onion; |
| 356 | } |
| 357 | |
| 358 | static u32 initial_cltv_delta(const struct route *route, |
| 359 | const struct payment_info *pinfo) |
no test coverage detected