Skip to content

Commit 380ee14

Browse files
committed
devtools: create conversion tool for old gossip stores, use it for pyln-client ones.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 714dc17 commit 380ee14

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
-64 Bytes
Binary file not shown.

devtools/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DEVTOOLS := devtools/bolt11-cli devtools/decodemsg devtools/onion devtools/dump-gossipstore devtools/gossipwith devtools/create-gossipstore devtools/mkcommit devtools/mkfunding devtools/mkclose devtools/mkgossip devtools/mkencoded devtools/mkquery devtools/lightning-checkmessage devtools/topology devtools/route devtools/bolt12-cli devtools/encodeaddr devtools/features devtools/fp16 devtools/rune devtools/gossmap-compress devtools/bip137-verifysignature
1+
DEVTOOLS := devtools/bolt11-cli devtools/decodemsg devtools/onion devtools/dump-gossipstore devtools/gossipwith devtools/create-gossipstore devtools/mkcommit devtools/mkfunding devtools/mkclose devtools/mkgossip devtools/mkencoded devtools/mkquery devtools/lightning-checkmessage devtools/topology devtools/route devtools/bolt12-cli devtools/encodeaddr devtools/features devtools/fp16 devtools/rune devtools/gossmap-compress devtools/bip137-verifysignature devtools/convert-gossmap
22
ifeq ($(HAVE_SQLITE3),1)
33
DEVTOOLS += devtools/checkchannels
44
endif
@@ -72,6 +72,9 @@ devtools/dump-gossipstore: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS)
7272

7373
devtools/dump-gossipstore.o: gossipd/gossip_store_wiregen.h
7474

75+
devtools/convert-gossmap: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o devtools/convert-gossmap.o
76+
devtools/convert-gossmap.o: gossipd/gossip_store_wiregen.h
77+
7578
devtools/create-gossipstore: $(DEVTOOLS_COMMON_OBJS) $(JSMN_OBJS) $(BITCOIN_OBJS) wire/fromwire.o wire/towire.o devtools/create-gossipstore.o gossipd/gossip_store_wiregen.o
7679
devtools/create-gossipstore.o: gossipd/gossip_store_wiregen.h
7780

devtools/convert-gossmap.c

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* Tool we can use to convert our testing gossip_store files */
2+
#include "config.h"
3+
#include <ccan/crc32c/crc32c.h>
4+
#include <ccan/err/err.h>
5+
#include <ccan/opt/opt.h>
6+
#include <ccan/read_write_all/read_write_all.h>
7+
#include <common/gossip_store.h>
8+
#include <fcntl.h>
9+
#include <gossipd/gossip_store_wiregen.h>
10+
#include <stdio.h>
11+
#include <unistd.h>
12+
#include <wire/peer_wire.h>
13+
14+
/* Current versions we support */
15+
#define GSTORE_MAJOR 0
16+
#define GSTORE_MINOR 15
17+
18+
/* Obsolete ZOMBIE bit */
19+
#define GOSSIP_STORE_ZOMBIE_BIT_V13 0x1000U
20+
21+
static bool upgrade_field(u8 oldversion,
22+
be16 *hdr_flags,
23+
u8 **msg)
24+
{
25+
int type = fromwire_peektype(*msg);
26+
27+
switch (oldversion) {
28+
case 10:
29+
/* Remove old channel_update with no htlc_maximum_msat */
30+
if (type == WIRE_CHANNEL_UPDATE
31+
&& tal_bytelen(*msg) == 130) {
32+
*msg = tal_free(*msg);
33+
return true;
34+
}
35+
/* fall thru */
36+
case 11:
37+
case 12:
38+
/* Remove private entries */
39+
if (type == WIRE_GOSSIP_STORE_PRIVATE_CHANNEL_OBS) {
40+
*msg = tal_free(*msg);
41+
return true;
42+
} else if (type == WIRE_GOSSIP_STORE_PRIVATE_UPDATE_OBS) {
43+
*msg = tal_free(*msg);
44+
return true;
45+
}
46+
/* fall thru */
47+
case 13:
48+
/* Discard any zombies */
49+
if (be16_to_cpu(*hdr_flags) & GOSSIP_STORE_ZOMBIE_BIT_V13) {
50+
*msg = tal_free(*msg);
51+
return true;
52+
}
53+
case 14:
54+
/* Add completed field */
55+
*hdr_flags |= CPU_TO_BE16(GOSSIP_STORE_COMPLETED_BIT);
56+
/* fall thru */
57+
case 15:
58+
/* Noop */
59+
return true;
60+
}
61+
62+
return false;
63+
}
64+
65+
int main(int argc, char *argv[])
66+
{
67+
u8 oldversion, version;
68+
struct gossip_hdr hdr;
69+
70+
setup_locale();
71+
if (!read_all(STDIN_FILENO, &oldversion, sizeof(oldversion)))
72+
errx(1, "Empty file");
73+
74+
if (GOSSIP_STORE_MAJOR_VERSION(oldversion) != GSTORE_MAJOR)
75+
errx(1, "Unsupported major gossip_version %u (expected %u)",
76+
GOSSIP_STORE_MAJOR_VERSION(oldversion), GSTORE_MAJOR);
77+
78+
version = ((GSTORE_MAJOR << 5) | GSTORE_MINOR);
79+
if (!write_all(STDOUT_FILENO, &version, sizeof(version)))
80+
err(1, "Write error");
81+
82+
while (read_all(STDIN_FILENO, &hdr, sizeof(hdr))) {
83+
u8 *msg;
84+
msg = tal_arr(NULL, u8, be16_to_cpu(hdr.len));
85+
if (!read_all(STDIN_FILENO, msg, tal_bytelen(msg)))
86+
err(1, "truncated file");
87+
if (!upgrade_field(oldversion, &hdr.flags, &msg))
88+
errx(1, "Cannot upgrade from version %u", oldversion);
89+
if (msg) {
90+
if (!write_all(STDOUT_FILENO, &hdr, sizeof(hdr))
91+
|| !write_all(STDOUT_FILENO, msg, tal_bytelen(msg)))
92+
err(1, "Write error");
93+
tal_free(msg);
94+
}
95+
}
96+
return 0;
97+
}

0 commit comments

Comments
 (0)