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

Function main

plugins/test/run-route-overlong.c:332–407  ·  view source on GitHub ↗

We create an arrangement of nodes, each node N connected to N+1 and * to node 1. The cost for each N to N+1 route is 1, for N to 1 is * 2^N. That means it's always cheapest to go the longer route */

Source from the content-addressed store, hash-verified

330 * to node 1. The cost for each N to N+1 route is 1, for N to 1 is
331 * 2^N. That means it's always cheapest to go the longer route */
332int main(int argc, char *argv[])
333{
334 struct node_id ids[NUM_NODES];
335 int store_fd;
336 struct payment *p;
337 struct payment_modifier **mods;
338 char gossip_version = 10;
339 char *gossipfilename;
340
341 common_setup(argv[0]);
342 chainparams = chainparams_for_network("regtest");
343 store_fd = tmpdir_mkstemp(tmpctx, "run-route-overlong.XXXXXX", &gossipfilename);
344 assert(write(store_fd, &gossip_version, sizeof(gossip_version))
345 == sizeof(gossip_version));
346
347 global_gossmap = gossmap_load(tmpctx, gossipfilename, NULL);
348
349 for (size_t i = 0; i < NUM_NODES; i++) {
350 struct privkey tmp;
351 memset(&tmp, i+1, sizeof(tmp));
352 node_id_from_privkey(&tmp, &ids[i]);
353 }
354
355 mods = tal_arrz(tmpctx, struct payment_modifier *, 1);
356 p = payment_new(mods, tal(tmpctx, struct command), NULL, mods);
357
358 for (size_t i = 1; i < NUM_NODES; i++) {
359 struct short_channel_id scid;
360
361 if (!mk_short_channel_id(&scid, i, i-1, 0))
362 abort();
363 add_connection(store_fd, &ids[i-1], &ids[i], &scid,
364 AMOUNT_MSAT(0),
365 AMOUNT_MSAT(1000000 * 1000),
366 0, 0, 0);
367 SUPERVERBOSE("Joining %s to %s, fee %u\n",
368 type_to_string(tmpctx, struct node_id, &ids[i-1]),
369 type_to_string(tmpctx, struct node_id, &ids[i]),
370 0);
371
372 if (i <= 2)
373 continue;
374 if (!mk_short_channel_id(&scid, i, 1, 0))
375 abort();
376 add_connection(store_fd, &ids[1], &ids[i], &scid,
377 AMOUNT_MSAT(0),
378 AMOUNT_MSAT(1000000 * 1000),
379 1 << i, 0, 0);
380 SUPERVERBOSE("Joining %s to %s, fee %u\n",
381 type_to_string(tmpctx, struct node_id, &ids[1]),
382 type_to_string(tmpctx, struct node_id, &ids[i]),
383 1 << i);
384 }
385
386 assert(gossmap_refresh(global_gossmap, NULL));
387 for (size_t i = ROUTING_MAX_HOPS; i > 2; i--) {
388 struct gossmap_node *dst, *src;
389 struct route_hop *r;

Callers

nothing calls this directly

Calls 14

common_setupFunction · 0.85
chainparams_for_networkFunction · 0.85
tmpdir_mkstempFunction · 0.85
gossmap_loadFunction · 0.85
payment_newFunction · 0.85
mk_short_channel_idFunction · 0.85
abortFunction · 0.85
gossmap_refreshFunction · 0.85
gossmap_find_nodeFunction · 0.85
routeFunction · 0.85
common_shutdownFunction · 0.85
node_id_from_privkeyFunction · 0.70

Tested by

no test coverage detected