Figures out how to fwd, allocating return off hp */
| 1172 | |
| 1173 | /* Figures out how to fwd, allocating return off hp */ |
| 1174 | static struct channel_id *calc_forwarding_channel(struct lightningd *ld, |
| 1175 | struct htlc_accepted_hook_payload *hp, |
| 1176 | const struct route_step *rs) |
| 1177 | { |
| 1178 | const struct onion_payload *p = hp->payload; |
| 1179 | struct channel *c, *best; |
| 1180 | |
| 1181 | if (rs->nextcase != ONION_FORWARD) |
| 1182 | return NULL; |
| 1183 | |
| 1184 | if (!p || !p->forward_channel) |
| 1185 | return NULL; |
| 1186 | |
| 1187 | c = any_channel_by_scid(ld, p->forward_channel, false); |
| 1188 | if (!c) |
| 1189 | return NULL; |
| 1190 | |
| 1191 | best = best_channel(ld, c->peer, p->amt_to_forward, c); |
| 1192 | if (best != c) { |
| 1193 | log_debug(hp->channel->log, |
| 1194 | "Chose a better channel than %s: %s", |
| 1195 | type_to_string(tmpctx, struct short_channel_id, |
| 1196 | p->forward_channel), |
| 1197 | type_to_string(tmpctx, struct short_channel_id, |
| 1198 | channel_scid_or_local_alias(best))); |
| 1199 | } |
| 1200 | |
| 1201 | return tal_dup(hp, struct channel_id, &best->cid); |
| 1202 | } |
| 1203 | |
| 1204 | /** |
| 1205 | * Everyone is committed to this htlc of theirs |
no test coverage detected