devtools: enhance dump-gossipstore to show some details of messages.
Not a complete decode, just the highlights (what channel was announced or updated, what node was announced). Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <ccan/err/err.h>
|
||||
#include <ccan/opt/opt.h>
|
||||
#include <common/gossip_store.h>
|
||||
#include <common/setup.h>
|
||||
#include <common/utils.h>
|
||||
#include <fcntl.h>
|
||||
#include <gossipd/gossip_store_wiregen.h>
|
||||
@@ -14,6 +15,61 @@
|
||||
#define GSTORE_MAJOR 0
|
||||
#define GSTORE_MINOR 15
|
||||
|
||||
static bool is_channel_announce(const u8 *msg, struct short_channel_id **scid)
|
||||
{
|
||||
secp256k1_ecdsa_signature sig;
|
||||
u8 *features;
|
||||
struct bitcoin_blkid chain_hash;
|
||||
struct node_id node;
|
||||
struct pubkey key;
|
||||
|
||||
if (fromwire_peektype(msg) != WIRE_CHANNEL_ANNOUNCEMENT)
|
||||
return false;
|
||||
|
||||
*scid = tal(msg, struct short_channel_id);
|
||||
if (!fromwire_channel_announcement(msg, msg, &sig, &sig, &sig, &sig, &features,
|
||||
&chain_hash, *scid, &node, &node, &key, &key))
|
||||
*scid = tal_free(*scid);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_channel_update(const u8 *msg, struct short_channel_id_dir **scidd)
|
||||
{
|
||||
secp256k1_ecdsa_signature sig;
|
||||
struct bitcoin_blkid chain_hash;
|
||||
u32 u32val;
|
||||
u8 message_flags, channel_flags;
|
||||
u16 cltv_expiry_delta;
|
||||
struct amount_msat msat;
|
||||
|
||||
if (fromwire_peektype(msg) != WIRE_CHANNEL_UPDATE)
|
||||
return false;
|
||||
|
||||
*scidd = tal(msg, struct short_channel_id_dir);
|
||||
if (fromwire_channel_update(msg, &sig, &chain_hash, &(*scidd)->scid, &u32val, &message_flags, &channel_flags, &cltv_expiry_delta, &msat, &u32val, &u32val, &msat))
|
||||
(*scidd)->dir = (channel_flags & ROUTING_FLAGS_DIRECTION);
|
||||
else
|
||||
*scidd = tal_free(*scidd);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool is_node_announcement(const u8 *msg, struct node_id **node)
|
||||
{
|
||||
secp256k1_ecdsa_signature sig;
|
||||
u8 *u8arr;
|
||||
u32 timestamp;
|
||||
u8 rgb_color[3], alias[32];
|
||||
struct tlv_node_ann_tlvs *tlvs;
|
||||
|
||||
if (fromwire_peektype(msg) != WIRE_NODE_ANNOUNCEMENT)
|
||||
return false;
|
||||
|
||||
*node = tal(msg, struct node_id);
|
||||
if (!fromwire_node_announcement(msg, msg, &sig, &u8arr, ×tamp, *node, rgb_color, alias, &u8arr, &tlvs))
|
||||
*node = tal_free(*node);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
@@ -23,7 +79,7 @@ int main(int argc, char *argv[])
|
||||
bool print_deleted = false;
|
||||
bool print_timestamp = false;
|
||||
|
||||
setup_locale();
|
||||
common_setup(argv[0]);
|
||||
opt_register_noarg("--print-deleted", opt_set_bool, &print_deleted,
|
||||
"Print deleted entries too");
|
||||
opt_register_noarg("--print-timestamps", opt_set_bool, &print_timestamp,
|
||||
@@ -64,7 +120,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
while (read(fd, &hdr, sizeof(hdr)) == sizeof(hdr)) {
|
||||
struct amount_sat sat;
|
||||
struct short_channel_id scid;
|
||||
struct short_channel_id scid, *scidptr;
|
||||
struct short_channel_id_dir *sciddptr;
|
||||
struct node_id *nodeptr;
|
||||
u16 flags = be16_to_cpu(hdr.flags);
|
||||
u16 msglen = be16_to_cpu(hdr.len);
|
||||
u8 *msg, *inner;
|
||||
@@ -95,17 +153,20 @@ int main(int argc, char *argv[])
|
||||
if (fromwire_gossip_store_channel_amount(msg, &sat)) {
|
||||
printf("channel_amount: %s\n",
|
||||
fmt_amount_sat(tmpctx, sat));
|
||||
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_ANNOUNCEMENT) {
|
||||
printf("t=%u channel_announcement: %s\n",
|
||||
} else if (is_channel_announce(msg, &scidptr)) {
|
||||
printf("t=%u channel_announcement(%s): %s\n",
|
||||
be32_to_cpu(hdr.timestamp),
|
||||
scidptr ? fmt_short_channel_id(tmpctx, *scidptr) : "?",
|
||||
tal_hex(msg, msg));
|
||||
} else if (fromwire_peektype(msg) == WIRE_CHANNEL_UPDATE) {
|
||||
printf("t=%u channel_update: %s\n",
|
||||
} else if (is_channel_update(msg, &sciddptr)) {
|
||||
printf("t=%u channel_update(%s): %s\n",
|
||||
be32_to_cpu(hdr.timestamp),
|
||||
sciddptr ? fmt_short_channel_id_dir(tmpctx, sciddptr) : "?",
|
||||
tal_hex(msg, msg));
|
||||
} else if (fromwire_peektype(msg) == WIRE_NODE_ANNOUNCEMENT) {
|
||||
printf("t=%u node_announcement: %s\n",
|
||||
} else if (is_node_announcement(msg, &nodeptr)) {
|
||||
printf("t=%u node_announcement(%s): %s\n",
|
||||
be32_to_cpu(hdr.timestamp),
|
||||
nodeptr ? fmt_node_id(tmpctx, nodeptr) : "?",
|
||||
tal_hex(msg, msg));
|
||||
} else if (fromwire_gossip_store_private_channel_obs(msg, msg, &sat,
|
||||
&inner)) {
|
||||
@@ -131,5 +192,6 @@ int main(int argc, char *argv[])
|
||||
off += sizeof(hdr) + msglen;
|
||||
tal_free(msg);
|
||||
}
|
||||
common_shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user