2021-12-04 12:23:56 +01:00
|
|
|
#include "config.h"
|
2019-06-11 07:30:54 +02:00
|
|
|
#include <ccan/crc32c/crc32c.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
#include <ccan/err/err.h>
|
2019-09-12 02:24:00 +02:00
|
|
|
#include <ccan/opt/opt.h>
|
2020-10-22 02:57:07 +02:00
|
|
|
#include <common/gossip_store.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
#include <fcntl.h>
|
2020-08-25 04:05:45 +02:00
|
|
|
#include <gossipd/gossip_store_wiregen.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2020-09-07 23:06:50 +02:00
|
|
|
#include <wire/peer_wire.h>
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2022-09-14 05:50:31 +02:00
|
|
|
/* Current versions we support */
|
|
|
|
#define GSTORE_MAJOR 0
|
2024-02-11 11:29:41 +01:00
|
|
|
#define GSTORE_MINOR 14
|
2022-09-14 05:50:31 +02:00
|
|
|
|
2018-08-30 02:04:28 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
u8 version;
|
2019-06-03 20:17:25 +02:00
|
|
|
struct gossip_hdr hdr;
|
2019-06-03 20:06:25 +02:00
|
|
|
size_t off;
|
2019-09-12 02:24:00 +02:00
|
|
|
bool print_deleted = false;
|
2022-07-15 07:59:26 +02:00
|
|
|
bool print_timestamp = false;
|
2018-08-30 02:04:28 +02:00
|
|
|
|
|
|
|
setup_locale();
|
2019-09-12 02:24:00 +02:00
|
|
|
opt_register_noarg("--print-deleted", opt_set_bool, &print_deleted,
|
|
|
|
"Print deleted entries too");
|
2022-07-15 07:59:26 +02:00
|
|
|
opt_register_noarg("--print-timestamps", opt_set_bool, &print_timestamp,
|
|
|
|
"Print timestamp with entries");
|
2019-09-12 02:24:00 +02:00
|
|
|
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
|
|
|
"[<gossip_store>]"
|
|
|
|
"Dump all gossip messages in the store",
|
|
|
|
"Print this message.");
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-09-12 02:24:00 +02:00
|
|
|
opt_parse(&argc, argv, opt_log_stderr_exit);
|
2018-08-30 02:04:28 +02:00
|
|
|
if (argc > 2)
|
2019-09-12 02:24:00 +02:00
|
|
|
opt_usage_and_exit("Too many arguments");
|
2018-08-30 02:04:28 +02:00
|
|
|
|
|
|
|
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");
|
|
|
|
|
2022-09-14 05:50:31 +02:00
|
|
|
if (GOSSIP_STORE_MAJOR_VERSION(version) != GSTORE_MAJOR)
|
|
|
|
errx(1, "Unsupported major gossip_version %u (expected %u)",
|
|
|
|
GOSSIP_STORE_MAJOR_VERSION(version), GSTORE_MAJOR);
|
|
|
|
|
|
|
|
/* Unsupported minor just means we might not understand all fields,
|
|
|
|
* or all flags. */
|
|
|
|
if (GOSSIP_STORE_MINOR_VERSION(version) != GSTORE_MINOR)
|
|
|
|
warnx("UNKNOWN GOSSIP minor VERSION %u (expected %u)",
|
|
|
|
GOSSIP_STORE_MINOR_VERSION(version), GSTORE_MINOR);
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2022-09-14 05:50:31 +02:00
|
|
|
printf("GOSSIP VERSION %u/%u\n",
|
|
|
|
GOSSIP_STORE_MINOR_VERSION(version),
|
|
|
|
GOSSIP_STORE_MAJOR_VERSION(version));
|
2019-06-03 20:06:25 +02:00
|
|
|
off = 1;
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-06-03 20:17:25 +02:00
|
|
|
while (read(fd, &hdr, sizeof(hdr)) == sizeof(hdr)) {
|
2019-02-21 04:45:55 +01:00
|
|
|
struct amount_sat sat;
|
2020-10-20 05:59:30 +02:00
|
|
|
struct short_channel_id scid;
|
2023-01-30 07:24:08 +01:00
|
|
|
u16 flags = be16_to_cpu(hdr.flags);
|
|
|
|
u16 msglen = be16_to_cpu(hdr.len);
|
2019-06-03 20:09:25 +02:00
|
|
|
u8 *msg, *inner;
|
2024-01-31 05:33:11 +01:00
|
|
|
bool deleted, push, dying;
|
2022-09-14 05:50:32 +02:00
|
|
|
u32 blockheight;
|
2019-09-12 02:24:00 +02:00
|
|
|
|
2023-01-30 07:24:08 +01:00
|
|
|
deleted = (flags & GOSSIP_STORE_DELETED_BIT);
|
|
|
|
push = (flags & GOSSIP_STORE_PUSH_BIT);
|
2023-07-19 08:34:07 +02:00
|
|
|
dying = (flags & GOSSIP_STORE_DYING_BIT);
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-06-03 20:09:25 +02:00
|
|
|
msg = tal_arr(NULL, u8, msglen);
|
2018-08-30 02:04:28 +02:00
|
|
|
if (read(fd, msg, msglen) != msglen)
|
2019-06-03 20:06:25 +02:00
|
|
|
errx(1, "%zu: Truncated file?", off);
|
2018-08-30 02:04:28 +02:00
|
|
|
|
2019-06-03 20:17:25 +02:00
|
|
|
if (be32_to_cpu(hdr.crc)
|
|
|
|
!= crc32c(be32_to_cpu(hdr.timestamp), msg, msglen))
|
2018-08-30 02:04:28 +02:00
|
|
|
warnx("Checksum verification failed");
|
|
|
|
|
2024-01-31 05:33:11 +01:00
|
|
|
printf("%zu: %s%s%s", off,
|
2019-11-04 01:37:02 +01:00
|
|
|
deleted ? "DELETED " : "",
|
2022-05-04 15:48:59 +02:00
|
|
|
push ? "PUSH " : "",
|
2023-07-19 08:34:07 +02:00
|
|
|
dying ? "DYING " : "");
|
2022-07-15 07:59:26 +02:00
|
|
|
if (print_timestamp)
|
|
|
|
printf("T=%u ", be32_to_cpu(hdr.timestamp));
|
2019-09-12 02:24:00 +02:00
|
|
|
if (deleted && !print_deleted) {
|
|
|
|
printf("\n");
|
2019-10-08 03:06:24 +02:00
|
|
|
goto end;
|
2019-09-12 02:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fromwire_gossip_store_channel_amount(msg, &sat)) {
|
|
|
|
printf("channel_amount: %s\n",
|
2024-03-20 01:47:52 +01:00
|
|
|
fmt_amount_sat(tmpctx, sat));
|
2019-05-04 07:53:12 +02:00
|
|
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("t=%u channel_announcement: %s\n",
|
|
|
|
be32_to_cpu(hdr.timestamp),
|
2019-06-03 20:17:25 +02:00
|
|
|
tal_hex(msg, msg));
|
2019-05-04 07:53:12 +02:00
|
|
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_UPDATE) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("t=%u channel_update: %s\n",
|
|
|
|
be32_to_cpu(hdr.timestamp),
|
2019-06-03 20:17:25 +02:00
|
|
|
tal_hex(msg, msg));
|
2019-05-04 07:53:12 +02:00
|
|
|
} else if (fromwire_peektype(msg) == WIRE_NODE_ANNOUNCEMENT) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("t=%u node_announcement: %s\n",
|
|
|
|
be32_to_cpu(hdr.timestamp),
|
2019-06-03 20:17:25 +02:00
|
|
|
tal_hex(msg, msg));
|
2024-01-31 04:16:16 +01:00
|
|
|
} else if (fromwire_gossip_store_private_channel_obs(msg, msg, &sat,
|
2020-10-20 05:59:30 +02:00
|
|
|
&inner)) {
|
|
|
|
printf("private channel_announcement: %s %s\n",
|
2024-03-20 01:47:52 +01:00
|
|
|
fmt_amount_sat(tmpctx, sat),
|
2020-10-20 05:59:30 +02:00
|
|
|
tal_hex(msg, inner));
|
2024-01-31 04:16:16 +01:00
|
|
|
} else if (fromwire_gossip_store_private_update_obs(msg, msg,
|
2019-06-03 20:06:25 +02:00
|
|
|
&inner)) {
|
2019-09-12 02:24:00 +02:00
|
|
|
printf("private channel_update: %s\n",
|
|
|
|
tal_hex(msg, inner));
|
2020-10-20 05:59:30 +02:00
|
|
|
} else if (fromwire_gossip_store_delete_chan(msg, &scid)) {
|
|
|
|
printf("delete channel: %s\n",
|
2024-03-20 01:47:52 +01:00
|
|
|
fmt_short_channel_id(tmpctx, scid));
|
2022-09-14 05:50:32 +02:00
|
|
|
} else if (fromwire_gossip_store_chan_dying(msg, &scid, &blockheight)) {
|
|
|
|
printf("dying channel: %s (deadline %u)\n",
|
2024-03-20 01:47:52 +01:00
|
|
|
fmt_short_channel_id(tmpctx, scid),
|
2022-09-14 05:50:32 +02:00
|
|
|
blockheight);
|
2018-08-30 02:04:28 +02:00
|
|
|
} else {
|
2019-09-12 02:24:00 +02:00
|
|
|
warnx("Unknown message %u",
|
|
|
|
fromwire_peektype(msg));
|
2018-08-30 02:04:28 +02:00
|
|
|
}
|
2019-10-08 03:06:24 +02:00
|
|
|
end:
|
2019-06-03 20:17:25 +02:00
|
|
|
off += sizeof(hdr) + msglen;
|
2018-08-30 02:04:28 +02:00
|
|
|
tal_free(msg);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|