Figures out how to fwd, allocating return off hp */
| 1352 | |
| 1353 | /* Figures out how to fwd, allocating return off hp */ |
| 1354 | static struct channel_id *calc_forwarding_channel(struct lightningd *ld, |
| 1355 | struct htlc_accepted_hook_payload *hp) |
| 1356 | { |
| 1357 | const struct onion_payload *p = hp->payload; |
| 1358 | struct peer *peer; |
| 1359 | struct channel *c, *best; |
| 1360 | |
| 1361 | if (!p) |
| 1362 | return NULL; |
| 1363 | |
| 1364 | if (p->final) |
| 1365 | return NULL; |
| 1366 | |
| 1367 | if (p->forward_channel) { |
| 1368 | log_debug(hp->channel->log, |
| 1369 | "Looking up channel by scid=%s to forward htlc_id=%" PRIu64, |
| 1370 | fmt_short_channel_id(tmpctx, *p->forward_channel), |
| 1371 | hp->hin->key.id); |
| 1372 | |
| 1373 | c = any_channel_by_scid(ld, *p->forward_channel, false); |
| 1374 | |
| 1375 | if (!c) { |
| 1376 | log_unusual(hp->channel->log, "No peer channel with scid=%s", |
| 1377 | fmt_short_channel_id(tmpctx, *p->forward_channel)); |
| 1378 | return NULL; |
| 1379 | } |
| 1380 | |
| 1381 | peer = c->peer; |
| 1382 | } else { |
| 1383 | struct node_id id; |
| 1384 | if (!p->forward_node_id) { |
| 1385 | log_unusual(hp->channel->log, |
| 1386 | "Neither forward_channel nor " |
| 1387 | "forward_node_id was set in payload"); |
| 1388 | return NULL; |
| 1389 | } |
| 1390 | node_id_from_pubkey(&id, p->forward_node_id); |
| 1391 | peer = peer_by_id(ld, &id); |
| 1392 | |
| 1393 | log_debug(hp->channel->log, "Looking up peer by node_id=%s", |
| 1394 | fmt_node_id(tmpctx, &id)); |
| 1395 | |
| 1396 | if (!peer) { |
| 1397 | log_unusual( |
| 1398 | hp->channel->log, "No peer with node_id=%s", |
| 1399 | fmt_node_id(tmpctx, &id)); |
| 1400 | return NULL; |
| 1401 | } |
| 1402 | c = NULL; |
| 1403 | } |
| 1404 | |
| 1405 | if (!ld->dev_strict_forwarding) |
| 1406 | best = best_channel(ld, peer, p->amt_to_forward, c); |
| 1407 | else |
| 1408 | best = c; |
| 1409 | |
| 1410 | if (!c) { |
| 1411 | if (!best) |
no test coverage detected