From 01c02fd617d37db118a137bfd1a1f62ff3309287 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 28 Jun 2018 11:04:47 +0930 Subject: [PATCH] devtools/decodemsg: decode encoded_short_ids. $ devtools/decodemsg 010806226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f000000000000ffff0100160178da6360486760606400824c285d00a60111710144 $ devtools/decodemsg 010506226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f00110000006700000100000000690000010000 Before: WIRE_REPLY_CHANNEL_RANGE: chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 first_blocknum=0 number_of_blocks=65535 complete=1 encoded_short_ids=[0178da6360486760606400824c285d00a60111710144] WIRE_QUERY_SHORT_CHANNEL_IDS: chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 encoded_short_ids=[0000006700000100000000690000010000] After: WIRE_REPLY_CHANNEL_RANGE: chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 first_blocknum=0 number_of_blocks=65535 complete=1 encoded_short_ids=[ (ZLIB) 103:1:0 105:1:0 112:1:0 ] WIRE_QUERY_SHORT_CHANNEL_IDS: chain_hash=0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206 encoded_short_ids=[ (UNCOMPRESSED) 103:1:0 105:1:0 ] Signed-off-by: Rusty Russell --- devtools/Makefile | 1 + devtools/decodemsg.c | 1 + devtools/print_wire.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/devtools/Makefile b/devtools/Makefile index 6ef29c40f..3ffa81a19 100644 --- a/devtools/Makefile +++ b/devtools/Makefile @@ -8,6 +8,7 @@ DEVTOOLS_COMMON_OBJS := \ common/bech32.o \ common/bech32_util.o \ common/bolt11.o \ + common/decode_short_channel_ids.o \ common/hash_u5.o \ common/type_to_string.o \ common/utils.o \ diff --git a/devtools/decodemsg.c b/devtools/decodemsg.c index 551fad93d..5e5c94d20 100644 --- a/devtools/decodemsg.c +++ b/devtools/decodemsg.c @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/devtools/print_wire.c b/devtools/print_wire.c index a57081b8b..650d765bd 100644 --- a/devtools/print_wire.c +++ b/devtools/print_wire.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -100,6 +101,46 @@ static void printwire_addresses(const u8 **cursor, size_t *plen, size_t len) printf(" ]\n"); } +static void printwire_encoded_short_ids(const u8 **cursor, size_t *plen, size_t len) +{ + struct short_channel_id *scids; + u8 *arr = tal_arr(tmpctx, u8, len); + + fromwire_u8_array(cursor, plen, arr, len); + if (!*cursor) + return; + + printf("["); + scids = decode_short_ids(tmpctx, arr); + if (scids) { + switch (arr[0]) { + case SHORTIDS_UNCOMPRESSED: + printf(" (UNCOMPRESSED)"); + break; + case SHORTIDS_ZLIB: + printf(" (ZLIB)"); + break; + default: + abort(); + } + for (size_t i = 0; i < tal_count(scids); i++) + printf(" %s", + short_channel_id_to_str(tmpctx, &scids[i])); + } else { + /* If it was unknown, that's different from corrupt */ + if (len == 0 + || arr[0] == SHORTIDS_UNCOMPRESSED + || arr[0] == SHORTIDS_ZLIB) { + printf(" **CORRUPT**"); + return; + } else { + printf(" UNKNOWN:"); + print_hexstring(cursor, plen, len); + } + } + printf(" ]\n"); +} + void printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen, size_t len) { if (streq(fieldname, "node_announcement.alias")) { @@ -110,6 +151,10 @@ void printwire_u8_array(const char *fieldname, const u8 **cursor, size_t *plen, printwire_addresses(cursor, plen, len); return; } + if (strends(fieldname, ".encoded_short_ids")) { + printwire_encoded_short_ids(cursor, plen, len); + return; + } printf("["); if (!print_hexstring(cursor, plen, len))