From 895e552475569a9f60dddd126cfaa3de0b60cd25 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Fri, 20 Sep 2019 16:27:20 +0930 Subject: [PATCH] BOLT: update to master with gossip_queries_ex. Signed-off-by: Rusty Russell --- Makefile | 2 +- common/decode_short_channel_ids.c | 2 +- common/decode_short_channel_ids.h | 2 +- common/features.h | 14 ++++---- devtools/mkgossip.c | 2 +- gossipd/gossipd.c | 53 +++++++++++++++++++------------ 6 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 41ad389c9..c6f03043b 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ CCANDIR := ccan # Where we keep the BOLT RFCs BOLTDIR := ../lightning-rfc/ -BOLTVERSION := 03fd18e5bc604213a0f4514982cb6045bdb4c5b2 +BOLTVERSION := c8e53fe5bf131db142d231e88f2adb3a84876836 -include config.vars diff --git a/common/decode_short_channel_ids.c b/common/decode_short_channel_ids.c index de5e1b76f..89fc766ca 100644 --- a/common/decode_short_channel_ids.c +++ b/common/decode_short_channel_ids.c @@ -71,7 +71,7 @@ bigsize_t *decode_scid_query_flags(const tal_t *ctx, size_t max = tal_count(encoded); bigsize_t *flags; - /* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: + /* BOLT #7: * * The receiver: *... diff --git a/common/decode_short_channel_ids.h b/common/decode_short_channel_ids.h index 3af356551..12021054d 100644 --- a/common/decode_short_channel_ids.h +++ b/common/decode_short_channel_ids.h @@ -20,7 +20,7 @@ enum scid_encode_types { struct short_channel_id *decode_short_ids(const tal_t *ctx, const u8 *encoded); -/* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: +/* BOLT #7: * * `encoded_query_flags` is an array of bitfields, one varint per bitfield, * one bitfield for each `short_channel_id`. Bits have the following meaning: diff --git a/common/features.h b/common/features.h index e76ed0e75..d5c93b77d 100644 --- a/common/features.h +++ b/common/features.h @@ -25,7 +25,7 @@ const char **list_supported_features(const tal_t *ctx); bool feature_is_set(const u8 *features, size_t bit); void set_feature_bit(u8 **ptr, u32 bit); -/* BOLT-531c8d7d9b01ab610b8a73a0deba1b9e9c83e1ed #9: +/* BOLT #9: * * Flags are numbered from the least-significant bit, at bit 0 (i.e. 0x1, * an _even_ bit). They are generally assigned in pairs so that features @@ -36,7 +36,7 @@ void set_feature_bit(u8 **ptr, u32 bit); #define COMPULSORY_FEATURE(x) ((x) & 0xFFFFFFFE) #define OPTIONAL_FEATURE(x) ((x) | 1) -/* BOLT-531c8d7d9b01ab610b8a73a0deba1b9e9c83e1ed #9: +/* BOLT #9: * * ## Assigned `localfeatures` flags *... @@ -45,19 +45,19 @@ void set_feature_bit(u8 **ptr, u32 bit); * | 3 | `initial_routing_sync` |... * | 4/5 | `option_upfront_shutdown_script` |... * | 6/7 | `gossip_queries` |... - * | 12/13| `option_static_remotekey` |... + * | 10/11 | `gossip_queries_ex` |... */ #define LOCAL_DATA_LOSS_PROTECT 0 #define LOCAL_INITIAL_ROUTING_SYNC 2 #define LOCAL_UPFRONT_SHUTDOWN_SCRIPT 4 #define LOCAL_GOSSIP_QUERIES 6 -#define LOCAL_STATIC_REMOTEKEY 12 +#define LOCAL_GOSSIP_QUERIES_EX 10 -/* BOLT-927c96daab2338b716708a57cd75c84a2d169e0e #9: +/* BOLT-531c8d7d9b01ab610b8a73a0deba1b9e9c83e1ed #9: * | Bits | Name |... - * | 10/11 | `gossip_queries_ex` |... + * | 12/13| `option_static_remotekey` |... */ -#define LOCAL_GOSSIP_QUERIES_EX 10 +#define LOCAL_STATIC_REMOTEKEY 12 /* BOLT #9: * diff --git a/devtools/mkgossip.c b/devtools/mkgossip.c index 08b2d0882..8d62c289a 100644 --- a/devtools/mkgossip.c +++ b/devtools/mkgossip.c @@ -79,7 +79,7 @@ static char *sig_as_hex(const secp256k1_ecdsa_signature *sig) return tal_hexstr(NULL, compact_sig, sizeof(compact_sig)); } -/* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: +/* BOLT #7: * * The checksum of a `channel_update` is the CRC32C checksum as specified in * [RFC3720](https://tools.ietf.org/html/rfc3720#appendix-B.4) of this diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index 539cf3d39..c5557e053 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -634,6 +634,15 @@ static const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg tal_hex(tmpctx, msg)); } if (tlvs->query_flags) { + /* BOLT #7: + * + * The receiver: + *... + * - if the incoming message includes + * `query_short_channel_ids_tlvs`: + * - if `encoding_type` is not a known encoding type: + * - MAY fail the connection + */ flags = decode_scid_query_flags(tmpctx, tlvs->query_flags); if (!flags) { return towire_errorfmt(peer, NULL, @@ -677,11 +686,10 @@ static const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg tal_hex(tmpctx, encoded)); } - /* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: + /* BOLT #7: * * The receiver: *... - * - if the incoming message includes `query_short_channel_ids_tlvs`: * - if `encoded_query_flags` does not decode to exactly one flag per * `short_channel_id`: * - MAY fail the connection. @@ -700,8 +708,8 @@ static const u8 *handle_query_short_channel_ids(struct peer *peer, const u8 *msg /* BOLT #7: * - * - MUST respond to each known `short_channel_id` with a `channel_announcement` - * and the latest `channel_update` for each end + * - MUST respond to each known `short_channel_id`: + *... * - SHOULD NOT wait for the next outgoing gossip flush to send * these. */ @@ -785,7 +793,7 @@ static void reply_channel_range(struct peer *peer, queue_peer_msg(peer, take(msg)); } -/* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: +/* BOLT #7: * * `query_option_flags` is a bitfield represented as a minimally-encoded varint. * Bits have the following meaning: @@ -800,7 +808,7 @@ enum query_option_flags { QUERY_ADD_CHECKSUMS = 0x2, }; -/* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: +/* BOLT #7: * * The checksum of a `channel_update` is the CRC32C checksum as specified in * [RFC3720](https://tools.ietf.org/html/rfc3720#appendix-B.4) of this @@ -1286,10 +1294,6 @@ static void uniquify_node_ids(struct node_id **ids) size_t dst, src; /* BOLT #7: - * - * - MUST follow with any `node_announcement`s for each - * `channel_announcement` - * * - SHOULD avoid sending duplicate `node_announcements` in * response to a single `query_short_channel_ids`. */ @@ -1320,10 +1324,7 @@ static void maybe_create_next_scid_reply(struct peer *peer) /* BOLT #7: * - * - MUST respond to each known `short_channel_id` with a - * `channel_announcement` and the latest `channel_update` for each end - * - SHOULD NOT wait for the next outgoing gossip flush - * to send these. + * - MUST respond to each known `short_channel_id`: */ /* Search for next short_channel_id we know about. */ num = tal_count(peer->scid_queries); @@ -1334,7 +1335,7 @@ static void maybe_create_next_scid_reply(struct peer *peer) if (!chan || !is_chan_public(chan)) continue; - /* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: + /* BOLT #7: * - if bit 0 of `query_flag` is set: * - MUST reply with a `channel_announcement` */ @@ -1343,7 +1344,7 @@ static void maybe_create_next_scid_reply(struct peer *peer) sent = true; } - /* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: + /* BOLT #7: * - if bit 1 of `query_flag` is set and it has received a * `channel_update` from `node_id_1`: * - MUST reply with the latest `channel_update` for @@ -1363,7 +1364,7 @@ static void maybe_create_next_scid_reply(struct peer *peer) sent = true; } - /* BOLT-61a1365a45cc8b463ddbbe3429d350f8eac787dd #7: + /* BOLT #7: * - if bit 3 of `query_flag` is set and it has received * a `node_announcement` from `node_id_1`: * - MUST reply with the latest `node_announcement` for @@ -1390,10 +1391,20 @@ static void maybe_create_next_scid_reply(struct peer *peer) /* BOLT #7: * - * - MUST follow with any `node_announcement`s for each - * `channel_announcement` - * - SHOULD avoid sending duplicate `node_announcements` in response - * to a single `query_short_channel_ids`. + * - if the incoming message does not include `encoded_query_flags`: + * ... + * - MUST follow with any `node_announcement`s for each + * `channel_announcement` + * - otherwise: + * ... + * - if bit 3 of `query_flag` is set and it has received a + * `node_announcement` from `node_id_1`: + * - MUST reply with the latest `node_announcement` for + * `node_id_1` + * - if bit 4 of `query_flag` is set and it has received a + * `node_announcement` from `node_id_2`: + * - MUST reply with the latest `node_announcement` for + * `node_id_2` */ /* If we haven't sent anything above, we look for the next * node_announcement to send. */