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

Function main

devtools/topology.c:238–297  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

236}
237
238int main(int argc, char *argv[])
239{
240 struct timemono tstart, tstop;
241 struct gossmap_node *n, *dst;
242 struct gossmap *map;
243 struct node_id dstid;
244 bool no_singles = false;
245
246 setup_locale();
247 setup_tmpctx();
248
249 opt_register_noarg("--no-single-sources", opt_set_bool, &no_singles,
250 "Eliminate single-channel nodes");
251 opt_register_noarg("-h|--help", opt_usage_and_exit,
252 "<gossipstore> <srcid>|all <dstid>\n"
253 "A topology test program.",
254 "Get usage information");
255 opt_parse(&argc, argv, opt_log_stderr_exit);
256 if (argc != 4)
257 opt_usage_exit_fail("Expect 3 arguments");
258
259 tstart = time_mono();
260 map = gossmap_load(NULL, argv[1], NULL, NULL);
261 if (!map)
262 err(1, "Loading gossip store %s", argv[1]);
263 tstop = time_mono();
264
265 printf("# Time to load: %"PRIu64" msec\n",
266 time_to_msec(timemono_between(tstop, tstart)));
267
268 clean_topo(map, no_singles);
269 printf("# Reduced to %zu nodes and %zu channels\n",
270 gossmap_num_nodes(map), gossmap_num_chans(map));
271
272 if (!node_id_from_hexstr(argv[3], strlen(argv[3]), &dstid))
273 errx(1, "Bad dstid");
274 dst = gossmap_find_node(map, &dstid);
275 if (!dst)
276 errx(1, "Unknown destination node '%s'", argv[3]);
277
278 if (streq(argv[2], "all")) {
279 for (n = gossmap_first_node(map);
280 n;
281 n = gossmap_next_node(map, n)) {
282 measure_least_cost(map, n, dst);
283 clean_tmpctx();
284 }
285 } else {
286 struct node_id srcid;
287 if (!node_id_from_hexstr(argv[2], strlen(argv[2]), &srcid))
288 errx(1, "Bad srcid");
289 n = gossmap_find_node(map, &srcid);
290 if (!n)
291 errx(1, "Unknown source node '%s'", argv[2]);
292 if (!measure_least_cost(map, n, dst))
293 exit(1);
294 }
295

Callers

nothing calls this directly

Calls 15

setup_localeFunction · 0.85
setup_tmpctxFunction · 0.85
opt_parseFunction · 0.85
opt_usage_exit_failFunction · 0.85
time_monoFunction · 0.85
errFunction · 0.85
time_to_msecFunction · 0.85
timemono_betweenFunction · 0.85
clean_topoFunction · 0.85
gossmap_num_nodesFunction · 0.85
gossmap_num_chansFunction · 0.85
errxFunction · 0.85

Tested by

no test coverage detected