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

Function gossmap_compact

gossipd/gossmap_manage.c:1831–1924  ·  view source on GitHub ↗

Returns false if already running */

Source from the content-addressed store, hash-verified

1829}
1830/* Returns false if already running */
1831static bool gossmap_compact(struct gossmap_manage *gm, bool dev_compact)
1832{
1833 int childin[2], execfail[2], childout[2];
1834 int saved_errno;
1835
1836 /* Only one at a time please! */
1837 if (gm->compactd)
1838 return false;
1839
1840 /* This checks contents: we want to make sure compactd sees an
1841 * up-to-date version. */
1842 gossmap_manage_get_gossmap(gm);
1843
1844 gm->compactd = tal(gm, struct compactd);
1845 for (size_t i = 0; i < ARRAY_SIZE(gm->compactd->uuid); i++)
1846 gm->compactd->uuid[i] = pseudorand(256);
1847
1848 gm->compactd->old_size = gossip_store_len_written(gm->gs);
1849 status_debug("Executing lightning_gossip_compactd %s %s %s %s",
1850 GOSSIP_STORE_FILENAME,
1851 GOSSIP_STORE_COMPACT_FILENAME,
1852 tal_fmt(tmpctx, "%"PRIu64, gm->compactd->old_size),
1853 tal_hexstr(tmpctx, gm->compactd->uuid, sizeof(gm->compactd->uuid)));
1854
1855 if (pipe(childin) != 0 || pipe(childout) != 0 || pipe(execfail) != 0)
1856 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1857 "Could not create pipes for compactd: %s",
1858 strerror(errno));
1859
1860 if (fcntl(execfail[1], F_SETFD, fcntl(execfail[1], F_GETFD)
1861 | FD_CLOEXEC) < 0)
1862 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1863 "Could not set cloexec on compactd fd: %s",
1864 strerror(errno));
1865
1866 gm->compactd->pid = fork();
1867 if (gm->compactd->pid < 0)
1868 status_failed(STATUS_FAIL_INTERNAL_ERROR,
1869 "Could not fork for compactd: %s",
1870 strerror(errno));
1871
1872 if (gm->compactd->pid == 0) {
1873 close(childin[0]);
1874 close(childout[1]);
1875 close(execfail[0]);
1876
1877 /* In practice, low fds are all open, so we don't have
1878 * to handle those horrible cases */
1879 assert(childin[1] > 2);
1880 assert(childout[0] > 2);
1881 if (dup2(childin[1], STDOUT_FILENO) == -1)
1882 err(1, "Failed to duplicate fd to stdout");
1883 close(childin[1]);
1884 if (dup2(childout[0], STDIN_FILENO) == -1)
1885 err(1, "Failed to duplicate fd to stdin");
1886 close(childout[0]);
1887 closefrom_limit(0);
1888 closefrom(3);

Calls 7

gossip_store_len_writtenFunction · 0.85
tal_hexstrFunction · 0.85
errFunction · 0.85
closefromFunction · 0.85
status_failedFunction · 0.50
closefrom_limitFunction · 0.50

Tested by

no test coverage detected