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

Function main

gossipd/compactd.c:95–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93}
94
95int main(int argc, char *argv[])
96{
97 int oldfd, newfd;
98 u8 gsversion, byte;
99 u8 uuid[32];
100 u64 old_off, limit;
101
102 common_setup(argv[0]);
103 /* Not really a subdaemon (we don't use status_xxx) but we can pretend */
104 if (argc == 2 && streq(argv[1], "--version")) {
105 printf("%s\n", version());
106 exit(0);
107 }
108
109 if (argc != 5)
110 errx(1, "Usage: %s <oldstore> <newstore> <oldstorelen> <uuid>",
111 argv[0]);
112
113 oldfd = open(argv[1], O_RDONLY);
114 if (oldfd < 0)
115 err(1, "Could not open old gossip_store %s", argv[1]);
116 newfd = open(argv[2], O_WRONLY|O_CREAT|O_TRUNC, 0600);
117 if (newfd < 0)
118 err(1, "Could not open new gossip_store %s", argv[2]);
119 limit = atol(argv[3]);
120 if (!hex_decode(argv[4], strlen(argv[4]), uuid, sizeof(uuid)))
121 errx(1, "Invalid uuid %s", argv[1]);
122
123 /* Copy version byte */
124 old_off = readx(oldfd, &gsversion, sizeof(gsversion));
125 writex(newfd, &gsversion, sizeof(gsversion));
126
127 /* Create uuid hdr. */
128 writerec(newfd, towire_gossip_store_uuid(tmpctx, uuid));
129
130 old_off = copy_records(oldfd, newfd, old_off, limit, false);
131 /* We should hit limit exactly */
132 if (old_off != limit)
133 errx(1, "We reached offset %"PRIu64" past initial limit %"PRIu64,
134 old_off, limit);
135
136 /* Now we tell gossipd we're done, and it pauses while we copy the last bit.
137 * Note that we need to keep any "delete_channel" records here, since that
138 * would have happened since we copied the first part, and we might have
139 * missed the deleted bit on those channels. */
140 byte = 0;
141 writex(STDOUT_FILENO, &byte, sizeof(byte));
142 readx(STDIN_FILENO, &byte, sizeof(byte));
143
144 limit = lseek(oldfd, 0, SEEK_END);
145 lseek(oldfd, old_off, SEEK_SET);
146 old_off = copy_records(oldfd, newfd, old_off, limit, true);
147
148 /* We should hit EOF exactly */
149 if (old_off != limit)
150 errx(1, "We reached offset %"PRIu64" before file size %"PRIu64,
151 old_off, limit);
152

Callers

nothing calls this directly

Calls 10

common_setupFunction · 0.85
versionFunction · 0.85
errxFunction · 0.85
errFunction · 0.85
hex_decodeFunction · 0.85
readxFunction · 0.85
writexFunction · 0.85
writerecFunction · 0.85
copy_recordsFunction · 0.85
common_shutdownFunction · 0.85

Tested by

no test coverage detected