mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-22 22:45:27 +01:00
devtools/dump-gossipstore: add flag to show deleted entries.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
a3273d4c84
commit
5592cfb174
1 changed files with 33 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
||||||
#include <ccan/crc32c/crc32c.h>
|
#include <ccan/crc32c/crc32c.h>
|
||||||
#include <ccan/err/err.h>
|
#include <ccan/err/err.h>
|
||||||
|
#include <ccan/opt/opt.h>
|
||||||
#include <common/type_to_string.h>
|
#include <common/type_to_string.h>
|
||||||
#include <common/utils.h>
|
#include <common/utils.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -19,11 +20,19 @@ int main(int argc, char *argv[])
|
||||||
u8 version;
|
u8 version;
|
||||||
struct gossip_hdr hdr;
|
struct gossip_hdr hdr;
|
||||||
size_t off;
|
size_t off;
|
||||||
|
bool print_deleted = false;
|
||||||
|
|
||||||
setup_locale();
|
setup_locale();
|
||||||
|
opt_register_noarg("--print-deleted", opt_set_bool, &print_deleted,
|
||||||
|
"Print deleted entries too");
|
||||||
|
opt_register_noarg("--help|-h", opt_usage_and_exit,
|
||||||
|
"[<gossip_store>]"
|
||||||
|
"Dump all gossip messages in the store",
|
||||||
|
"Print this message.");
|
||||||
|
|
||||||
|
opt_parse(&argc, argv, opt_log_stderr_exit);
|
||||||
if (argc > 2)
|
if (argc > 2)
|
||||||
errx(1, "Need the filename of a gossip store, or stdin");
|
opt_usage_and_exit("Too many arguments");
|
||||||
|
|
||||||
if (argc == 2) {
|
if (argc == 2) {
|
||||||
fd = open(argv[1], O_RDONLY);
|
fd = open(argv[1], O_RDONLY);
|
||||||
|
@ -46,7 +55,9 @@ int main(int argc, char *argv[])
|
||||||
struct amount_sat sat;
|
struct amount_sat sat;
|
||||||
u32 msglen = be32_to_cpu(hdr.len);
|
u32 msglen = be32_to_cpu(hdr.len);
|
||||||
u8 *msg, *inner;
|
u8 *msg, *inner;
|
||||||
bool deleted = (msglen & GOSSIP_STORE_LEN_DELETED_BIT);
|
bool deleted;
|
||||||
|
|
||||||
|
deleted = (msglen & GOSSIP_STORE_LEN_DELETED_BIT);
|
||||||
|
|
||||||
msglen &= ~GOSSIP_STORE_LEN_DELETED_BIT;
|
msglen &= ~GOSSIP_STORE_LEN_DELETED_BIT;
|
||||||
msg = tal_arr(NULL, u8, msglen);
|
msg = tal_arr(NULL, u8, msglen);
|
||||||
|
@ -57,33 +68,37 @@ int main(int argc, char *argv[])
|
||||||
!= crc32c(be32_to_cpu(hdr.timestamp), msg, msglen))
|
!= crc32c(be32_to_cpu(hdr.timestamp), msg, msglen))
|
||||||
warnx("Checksum verification failed");
|
warnx("Checksum verification failed");
|
||||||
|
|
||||||
if (deleted) {
|
printf("%zu: %s", off, deleted ? "DELETED " : "");
|
||||||
printf("%zu: DELETED\n", off);
|
if (deleted && !print_deleted) {
|
||||||
} else if (fromwire_gossip_store_channel_amount(msg, &sat)) {
|
printf("\n");
|
||||||
printf("%zu: channel_amount: %s\n", off,
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromwire_gossip_store_channel_amount(msg, &sat)) {
|
||||||
|
printf("channel_amount: %s\n",
|
||||||
type_to_string(tmpctx, struct amount_sat, &sat));
|
type_to_string(tmpctx, struct amount_sat, &sat));
|
||||||
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
|
||||||
printf("%zu: t=%u channel_announcement: %s\n",
|
printf("t=%u channel_announcement: %s\n",
|
||||||
off, be32_to_cpu(hdr.timestamp),
|
be32_to_cpu(hdr.timestamp),
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_UPDATE) {
|
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_UPDATE) {
|
||||||
printf("%zu: t=%u channel_update: %s\n",
|
printf("t=%u channel_update: %s\n",
|
||||||
off, be32_to_cpu(hdr.timestamp),
|
be32_to_cpu(hdr.timestamp),
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
} else if (fromwire_peektype(msg) == WIRE_NODE_ANNOUNCEMENT) {
|
} else if (fromwire_peektype(msg) == WIRE_NODE_ANNOUNCEMENT) {
|
||||||
printf("%zu: t=%u node_announcement: %s\n",
|
printf("t=%u node_announcement: %s\n",
|
||||||
off, be32_to_cpu(hdr.timestamp),
|
be32_to_cpu(hdr.timestamp),
|
||||||
tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
} else if (fromwire_peektype(msg) == WIRE_GOSSIPD_LOCAL_ADD_CHANNEL) {
|
} else if (fromwire_peektype(msg) == WIRE_GOSSIPD_LOCAL_ADD_CHANNEL) {
|
||||||
printf("%zu: local_add_channel: %s\n",
|
printf("local_add_channel: %s\n",
|
||||||
off, tal_hex(msg, msg));
|
tal_hex(msg, msg));
|
||||||
} else if (fromwire_gossip_store_private_update(msg, msg,
|
} else if (fromwire_gossip_store_private_update(msg, msg,
|
||||||
&inner)) {
|
&inner)) {
|
||||||
printf("%zu: private channel_update: %s\n",
|
printf("private channel_update: %s\n",
|
||||||
off, tal_hex(msg, inner));
|
tal_hex(msg, inner));
|
||||||
} else {
|
} else {
|
||||||
warnx("%zu: Unknown message %u",
|
warnx("Unknown message %u",
|
||||||
off, fromwire_peektype(msg));
|
fromwire_peektype(msg));
|
||||||
}
|
}
|
||||||
off += sizeof(hdr) + msglen;
|
off += sizeof(hdr) + msglen;
|
||||||
tal_free(msg);
|
tal_free(msg);
|
||||||
|
|
Loading…
Add table
Reference in a new issue