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

Function main

devtools/dump-gossipstore.c:87–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87int main(int argc, char *argv[])
88{
89 int fd;
90 u8 version;
91 struct gossip_hdr hdr;
92 size_t off;
93 bool print_deleted = false;
94 bool print_timestamp = false;
95
96 common_setup(argv[0]);
97 opt_register_noarg("--print-deleted", opt_set_bool, &print_deleted,
98 "Print deleted entries too");
99 opt_register_noarg("--print-timestamps", opt_set_bool, &print_timestamp,
100 "Print timestamp with entries");
101 opt_register_noarg("--help|-h", opt_usage_and_exit,
102 "[<gossip_store>]"
103 "Dump all gossip messages in the store",
104 "Print this message.");
105
106 opt_parse(&argc, argv, opt_log_stderr_exit);
107 if (argc > 2)
108 opt_usage_and_exit("Too many arguments");
109
110 if (argc == 2) {
111 fd = open(argv[1], O_RDONLY);
112 if (fd < 0)
113 err(1, "Opening %s", argv[1]);
114 } else
115 fd = STDIN_FILENO;
116
117 if (read(fd, &version, sizeof(version)) != sizeof(version))
118 errx(1, "Empty file");
119
120 if (GOSSIP_STORE_MAJOR_VERSION(version) != GSTORE_MAJOR)
121 errx(1, "Unsupported major gossip_version %u (expected %u)",
122 GOSSIP_STORE_MAJOR_VERSION(version), GSTORE_MAJOR);
123
124 /* Unsupported minor just means we might not understand all fields,
125 * or all flags. */
126 if (GOSSIP_STORE_MINOR_VERSION(version) != GSTORE_MINOR)
127 warnx("UNKNOWN GOSSIP minor VERSION %u (expected %u)",
128 GOSSIP_STORE_MINOR_VERSION(version), GSTORE_MINOR);
129
130 printf("GOSSIP VERSION %u/%u\n",
131 GOSSIP_STORE_MINOR_VERSION(version),
132 GOSSIP_STORE_MAJOR_VERSION(version));
133 off = 1;
134
135 while (read(fd, &hdr, sizeof(hdr)) == sizeof(hdr)) {
136 struct amount_sat sat;
137 struct short_channel_id scid, *scidptr;
138 struct short_channel_id_dir *sciddptr;
139 struct node_id *nodeptr;
140 u16 flags = be16_to_cpu(hdr.flags);
141 u16 msglen = be16_to_cpu(hdr.len);
142 u8 *msg, *inner;
143 bool deleted, dying, complete;
144 u32 blockheight;

Callers

nothing calls this directly

Calls 15

common_setupFunction · 0.85
opt_parseFunction · 0.85
opt_usage_and_exitFunction · 0.85
errFunction · 0.85
errxFunction · 0.85
warnxFunction · 0.85
be16_to_cpuFunction · 0.85
be32_to_cpuFunction · 0.85
crc32cFunction · 0.85
is_channel_announceFunction · 0.85
fmt_short_channel_idFunction · 0.85
tal_hexFunction · 0.85

Tested by

no test coverage detected