mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-03 18:57:06 +01:00
Save some overhead, plus gets us ready for giving subdaemons direct store access. This is the first time we *upgrade* the gossip_store, rather than just discarding. The downside is that we need to add an extra message after each channel_announcement, containing the channel capacity. After: store_load_msec:28337-30288(28975+/-7.4e+02) vsz_kb:582304-582316(582306+/-4.8) store_rewrite_sec:11.240000-11.800000(11.55+/-0.21) listnodes_sec:1.800000-1.880000(1.84+/-0.028) listchannels_sec:22.690000-26.260000(23.878+/-1.3) routing_sec:2.280000-9.570000(6.842+/-2.8) peer_write_all_sec:48.160000-51.480000(49.608+/-1.1) Differences: -vsz_kb:582320 +vsz_kb:582316 -listnodes_sec:2.100000-2.170000(2.118+/-0.026) +listnodes_sec:1.800000-1.880000(1.84+/-0.028) -peer_write_all_sec:51.600000-52.550000(52.188+/-0.34) +peer_write_all_sec:48.160000-51.480000(49.608+/-1.1) Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
77 lines
2.2 KiB
C
77 lines
2.2 KiB
C
#include <ccan/crc/crc.h>
|
|
#include <ccan/err/err.h>
|
|
#include <common/type_to_string.h>
|
|
#include <common/utils.h>
|
|
#include <fcntl.h>
|
|
#include <gossipd/gen_gossip_peerd_wire.h>
|
|
#include <gossipd/gen_gossip_store.h>
|
|
#include <gossipd/gossip_store.h>
|
|
#include <inttypes.h>
|
|
#include <stdio.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#include <wire/gen_peer_wire.h>
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
int fd;
|
|
u8 version;
|
|
beint32_t belen, becsum;
|
|
|
|
setup_locale();
|
|
|
|
if (argc > 2)
|
|
errx(1, "Need the filename of a gossip store, or stdin");
|
|
|
|
if (argc == 2) {
|
|
fd = open(argv[1], O_RDONLY);
|
|
if (fd < 0)
|
|
err(1, "Opening %s", argv[1]);
|
|
} else
|
|
fd = STDIN_FILENO;
|
|
|
|
if (read(fd, &version, sizeof(version)) != sizeof(version))
|
|
errx(1, "Empty file");
|
|
|
|
if (version != GOSSIP_STORE_VERSION)
|
|
warnx("UNSUPPORTED GOSSIP VERSION %u (expected %u)",
|
|
version, GOSSIP_STORE_VERSION);
|
|
|
|
printf("GOSSIP VERSION %u\n", version);
|
|
|
|
while (read(fd, &belen, sizeof(belen)) == sizeof(belen) &&
|
|
read(fd, &becsum, sizeof(becsum)) == sizeof(becsum)) {
|
|
struct amount_sat sat;
|
|
struct short_channel_id scid;
|
|
u32 msglen = be32_to_cpu(belen);
|
|
u8 *msg = tal_arr(NULL, u8, msglen);
|
|
|
|
if (read(fd, msg, msglen) != msglen)
|
|
errx(1, "Truncated file?");
|
|
|
|
if (be32_to_cpu(becsum) != crc32c(0, msg, msglen))
|
|
warnx("Checksum verification failed");
|
|
|
|
if (fromwire_gossip_store_channel_amount(msg, &sat)) {
|
|
printf("channel_amount: %s\n",
|
|
type_to_string(tmpctx, struct amount_sat, &sat));
|
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
|
|
printf("channel_announcement: %s\n", tal_hex(msg, msg));
|
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_UPDATE) {
|
|
printf("channel_update: %s\n", tal_hex(msg, msg));
|
|
} else if (fromwire_peektype(msg) == WIRE_NODE_ANNOUNCEMENT) {
|
|
printf("node_announcement: %s\n", tal_hex(msg, msg));
|
|
} else if (fromwire_peektype(msg) == WIRE_GOSSIPD_LOCAL_ADD_CHANNEL) {
|
|
printf("local_add_channel: %s\n", tal_hex(msg, msg));
|
|
} else if (fromwire_gossip_store_channel_delete(msg, &scid)) {
|
|
printf("channel_delete: %s\n",
|
|
type_to_string(msg, struct short_channel_id,
|
|
&scid));
|
|
} else {
|
|
warnx("Unknown message %u", fromwire_peektype(msg));
|
|
}
|
|
tal_free(msg);
|
|
}
|
|
return 0;
|
|
}
|