| 1180 | } |
| 1181 | |
| 1182 | static struct command_result * |
| 1183 | send_payment(struct lightningd *ld, |
| 1184 | struct command *cmd, |
| 1185 | const struct sha256 *rhash, |
| 1186 | u64 partid, |
| 1187 | u64 group, |
| 1188 | const struct route_hop *route, |
| 1189 | struct amount_msat msat, |
| 1190 | struct amount_msat total_msat, |
| 1191 | const char *label TAKES, |
| 1192 | const char *invstring TAKES, |
| 1193 | const char *description TAKES, |
| 1194 | const struct sha256 *local_invreq_id, |
| 1195 | const struct secret *payment_secret, |
| 1196 | const u8 *payment_metadata, |
| 1197 | bool dev_legacy_hop) |
| 1198 | { |
| 1199 | unsigned int base_expiry; |
| 1200 | struct onionpacket *packet; |
| 1201 | struct secret *path_secrets; |
| 1202 | size_t i, n_hops = tal_count(route); |
| 1203 | struct node_id *ids = tal_arr(tmpctx, struct node_id, n_hops); |
| 1204 | struct short_channel_id *channels; |
| 1205 | struct sphinx_path *path; |
| 1206 | struct pubkey pubkey; |
| 1207 | bool ret; |
| 1208 | u8 *onion; |
| 1209 | |
| 1210 | /* Expiry for HTLCs is absolute. And add one to give some margin, |
| 1211 | and use bitcoind's block height, even if we're behind in processing */ |
| 1212 | base_expiry = get_network_blockheight(ld->topology) + 1; |
| 1213 | |
| 1214 | path = sphinx_path_new(tmpctx, rhash->u.u8, sizeof(rhash->u.u8)); |
| 1215 | /* Extract IDs for each hop: create_onionpacket wants array. */ |
| 1216 | for (i = 0; i < n_hops; i++) |
| 1217 | ids[i] = route[i].node_id; |
| 1218 | |
| 1219 | /* Create sphinx path */ |
| 1220 | for (i = 0; i < n_hops - 1; i++) { |
| 1221 | ret = pubkey_from_node_id(&pubkey, &ids[i]); |
| 1222 | assert(ret); |
| 1223 | |
| 1224 | if (dev_legacy_hop && i == n_hops - 2) { |
| 1225 | sphinx_add_v0_hop(path, &pubkey, |
| 1226 | &route[i + 1].scid, |
| 1227 | route[i + 1].amount, |
| 1228 | base_expiry + route[i + 1].delay); |
| 1229 | continue; |
| 1230 | } |
| 1231 | |
| 1232 | sphinx_add_hop_has_length(path, &pubkey, |
| 1233 | take(onion_nonfinal_hop(NULL, |
| 1234 | &route[i + 1].scid, |
| 1235 | route[i + 1].amount, |
| 1236 | base_expiry + route[i + 1].delay))); |
| 1237 | } |
| 1238 | |
| 1239 | /* And finally set the final hop to the special values in |
no test coverage detected