From 7c8dc620359f6d3e614551e9491c70e9d07e2d31 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 16 Jun 2022 17:02:39 +0930 Subject: [PATCH] channeld: take over gossip_rcvd_filter.c and is_msg_gossip_broadcast. channeld is the only user of these functions, since it now streams all gossip itself. Signed-off-by: Rusty Russell --- channeld/Makefile | 1 - closingd/Makefile | 1 - common/Makefile | 1 - common/gossip_store.c | 1 - connectd/Makefile | 2 +- connectd/connectd.c | 1 - {common => connectd}/gossip_rcvd_filter.c | 2 +- {common => connectd}/gossip_rcvd_filter.h | 6 +- connectd/multiplex.c | 56 ++++++++++++++++++- .../test/run-gossip_rcvd_filter.c | 5 +- devtools/Makefile | 1 - gossipd/Makefile | 1 - lightningd/Makefile | 1 - openingd/Makefile | 1 - openingd/dualopend.c | 1 - openingd/openingd.c | 1 - wire/peer_wire.c | 54 ------------------ wire/peer_wire.h | 2 - 18 files changed, 64 insertions(+), 74 deletions(-) rename {common => connectd}/gossip_rcvd_filter.c (98%) rename {common => connectd}/gossip_rcvd_filter.h (81%) rename {common => connectd}/test/run-gossip_rcvd_filter.c (98%) diff --git a/channeld/Makefile b/channeld/Makefile index bdab8ffa0c13..1b9a7317c200 100644 --- a/channeld/Makefile +++ b/channeld/Makefile @@ -48,7 +48,6 @@ CHANNELD_COMMON_OBJS := \ common/ecdh_hsmd.o \ common/features.o \ common/fee_states.o \ - common/gossip_rcvd_filter.o \ common/peer_io.o \ common/peer_status_wiregen.o \ common/status_wiregen.o \ diff --git a/closingd/Makefile b/closingd/Makefile index 7ee284fbb98e..b7da71f42ef9 100644 --- a/closingd/Makefile +++ b/closingd/Makefile @@ -30,7 +30,6 @@ CLOSINGD_COMMON_OBJS := \ common/daemon.o \ common/daemon_conn.o \ common/derive_basepoints.o \ - common/gossip_rcvd_filter.o \ common/gossip_store.o \ common/htlc_wire.o \ common/key_derive.o \ diff --git a/common/Makefile b/common/Makefile index 86f1588b421b..3665baf4f4ca 100644 --- a/common/Makefile +++ b/common/Makefile @@ -34,7 +34,6 @@ COMMON_SRC_NOGEN := \ common/features.c \ common/fee_states.c \ common/fp16.c \ - common/gossip_rcvd_filter.c \ common/gossip_store.c \ common/gossmap.c \ common/hash_u5.c \ diff --git a/common/gossip_store.c b/common/gossip_store.c index eba8a5ab03c4..b36897aca653 100644 --- a/common/gossip_store.c +++ b/common/gossip_store.c @@ -1,6 +1,5 @@ #include "config.h" #include -#include #include #include #include diff --git a/connectd/Makefile b/connectd/Makefile index 8b1ea8907606..684349c41ed6 100644 --- a/connectd/Makefile +++ b/connectd/Makefile @@ -5,6 +5,7 @@ CONNECTD_HEADERS := connectd/connectd_wiregen.h \ connectd/connectd.h \ connectd/peer_exchange_initmsg.h \ connectd/handshake.h \ + connectd/gossip_rcvd_filter.h \ connectd/multiplex.h \ connectd/netaddress.h \ connectd/onion_message.h \ @@ -55,7 +56,6 @@ CONNECTD_COMMON_OBJS := \ common/hmac.o \ common/status_wiregen.o \ common/gossip_store.o \ - common/gossip_rcvd_filter.o \ common/key_derive.o \ common/memleak.o \ common/msg_queue.o \ diff --git a/connectd/connectd.c b/connectd/connectd.c index e20bf7f7f2ae..13a4bffbe050 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include diff --git a/common/gossip_rcvd_filter.c b/connectd/gossip_rcvd_filter.c similarity index 98% rename from common/gossip_rcvd_filter.c rename to connectd/gossip_rcvd_filter.c index 0c6b3d350ff0..914bd03f8c6b 100644 --- a/common/gossip_rcvd_filter.c +++ b/connectd/gossip_rcvd_filter.c @@ -1,9 +1,9 @@ #include "config.h" #include #include -#include #include #include +#include #include static u64 msg_key(const u8 *msg) diff --git a/common/gossip_rcvd_filter.h b/connectd/gossip_rcvd_filter.h similarity index 81% rename from common/gossip_rcvd_filter.h rename to connectd/gossip_rcvd_filter.h index a2495efa4a48..1a7d0a21ce4e 100644 --- a/common/gossip_rcvd_filter.h +++ b/connectd/gossip_rcvd_filter.h @@ -1,7 +1,7 @@ /* This implements a cheap gossip cache, so we can recognize what gossip * msgs this peer sent us, thus avoid retransmitting gossip it sent. */ -#ifndef LIGHTNING_COMMON_GOSSIP_RCVD_FILTER_H -#define LIGHTNING_COMMON_GOSSIP_RCVD_FILTER_H +#ifndef LIGHTNING_CONNECTD_GOSSIP_RCVD_FILTER_H +#define LIGHTNING_CONNECTD_GOSSIP_RCVD_FILTER_H #include "config.h" #include #include @@ -19,4 +19,4 @@ bool gossip_rcvd_filter_del(struct gossip_rcvd_filter *map, const u8 *msg); /* Flush out old entries. */ void gossip_rcvd_filter_age(struct gossip_rcvd_filter *map); -#endif /* LIGHTNING_COMMON_GOSSIP_RCVD_FILTER_H */ +#endif /* LIGHTNING_CONNECTD_GOSSIP_RCVD_FILTER_H */ diff --git a/connectd/multiplex.c b/connectd/multiplex.c index 1f50ab6831a6..331d1b680630 100644 --- a/connectd/multiplex.c +++ b/connectd/multiplex.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -23,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -640,6 +640,60 @@ static bool handle_custommsg(struct daemon *daemon, } } +static bool is_msg_gossip_broadcast(const u8 *cursor) +{ + switch ((enum peer_wire)fromwire_peektype(cursor)) { + case WIRE_CHANNEL_ANNOUNCEMENT: + case WIRE_NODE_ANNOUNCEMENT: + case WIRE_CHANNEL_UPDATE: + return true; + case WIRE_QUERY_SHORT_CHANNEL_IDS: + case WIRE_REPLY_SHORT_CHANNEL_IDS_END: + case WIRE_QUERY_CHANNEL_RANGE: + case WIRE_REPLY_CHANNEL_RANGE: + case WIRE_ONION_MESSAGE: + case WIRE_OBS2_ONION_MESSAGE: + case WIRE_WARNING: + case WIRE_INIT: + case WIRE_PING: + case WIRE_PONG: + case WIRE_ERROR: + case WIRE_OPEN_CHANNEL: + case WIRE_ACCEPT_CHANNEL: + case WIRE_FUNDING_CREATED: + case WIRE_FUNDING_SIGNED: + case WIRE_FUNDING_LOCKED: + case WIRE_SHUTDOWN: + case WIRE_CLOSING_SIGNED: + case WIRE_UPDATE_ADD_HTLC: + case WIRE_UPDATE_FULFILL_HTLC: + case WIRE_UPDATE_FAIL_HTLC: + case WIRE_UPDATE_FAIL_MALFORMED_HTLC: + case WIRE_COMMITMENT_SIGNED: + case WIRE_REVOKE_AND_ACK: + case WIRE_UPDATE_FEE: + case WIRE_UPDATE_BLOCKHEIGHT: + case WIRE_CHANNEL_REESTABLISH: + case WIRE_ANNOUNCEMENT_SIGNATURES: + case WIRE_GOSSIP_TIMESTAMP_FILTER: + case WIRE_TX_ADD_INPUT: + case WIRE_TX_REMOVE_INPUT: + case WIRE_TX_ADD_OUTPUT: + case WIRE_TX_REMOVE_OUTPUT: + case WIRE_TX_COMPLETE: + case WIRE_TX_SIGNATURES: + case WIRE_OPEN_CHANNEL2: + case WIRE_ACCEPT_CHANNEL2: + case WIRE_INIT_RBF: + case WIRE_ACK_RBF: +#if EXPERIMENTAL_FEATURES + case WIRE_STFU: +#endif + break; + } + return false; +} + /* We handle pings and gossip messages. */ static bool handle_message_locally(struct peer *peer, const u8 *msg) { diff --git a/common/test/run-gossip_rcvd_filter.c b/connectd/test/run-gossip_rcvd_filter.c similarity index 98% rename from common/test/run-gossip_rcvd_filter.c rename to connectd/test/run-gossip_rcvd_filter.c index 473229bdec88..7a6dfd3dbb7a 100644 --- a/common/test/run-gossip_rcvd_filter.c +++ b/connectd/test/run-gossip_rcvd_filter.c @@ -1,7 +1,7 @@ #include "config.h" #include "../gossip_rcvd_filter.c" -#include "../pseudorand.c" #include "../../wire/fromwire.c" +#include #include #include @@ -53,6 +53,9 @@ void towire_secp256k1_ecdsa_signature(u8 **pptr UNNEEDED, /* Generated stub for towire_sha256 */ void towire_sha256(u8 **pptr UNNEEDED, const struct sha256 *sha256 UNNEEDED) { fprintf(stderr, "towire_sha256 called!\n"); abort(); } +/* Generated stub for towire_u16 */ +void towire_u16(u8 **pptr UNNEEDED, u16 v UNNEEDED) +{ fprintf(stderr, "towire_u16 called!\n"); abort(); } /* Generated stub for towire_u32 */ void towire_u32(u8 **pptr UNNEEDED, u32 v UNNEEDED) { fprintf(stderr, "towire_u32 called!\n"); abort(); } diff --git a/devtools/Makefile b/devtools/Makefile index ba529da0f66f..35ba6da51ced 100644 --- a/devtools/Makefile +++ b/devtools/Makefile @@ -25,7 +25,6 @@ DEVTOOLS_COMMON_OBJS := \ common/decode_array.o \ common/features.o \ common/fee_states.o \ - common/gossip_rcvd_filter.o \ common/hash_u5.o \ common/hmac.o \ common/htlc_state.o \ diff --git a/gossipd/Makefile b/gossipd/Makefile index c31f3486c6d1..2a2b8a40f2f0 100644 --- a/gossipd/Makefile +++ b/gossipd/Makefile @@ -44,7 +44,6 @@ GOSSIPD_COMMON_OBJS := \ common/ecdh_hsmd.o \ common/features.o \ common/status_wiregen.o \ - common/gossip_rcvd_filter.o \ common/key_derive.o \ common/lease_rates.o \ common/memleak.o \ diff --git a/lightningd/Makefile b/lightningd/Makefile index 8876dc55c929..f1f1607ea388 100644 --- a/lightningd/Makefile +++ b/lightningd/Makefile @@ -92,7 +92,6 @@ LIGHTNINGD_COMMON_OBJS := \ common/peer_status_wiregen.o \ common/status_levels.o \ common/status_wiregen.o \ - common/gossip_rcvd_filter.o \ common/hash_u5.o \ common/hmac.o \ common/hsm_encryption.o \ diff --git a/openingd/Makefile b/openingd/Makefile index 608268399655..1da236ac3df5 100644 --- a/openingd/Makefile +++ b/openingd/Makefile @@ -47,7 +47,6 @@ OPENINGD_COMMON_OBJS := \ common/derive_basepoints.o \ common/features.o \ common/fee_states.o \ - common/gossip_rcvd_filter.o \ common/gossip_store.o \ common/htlc_state.o \ common/htlc_wire.o \ diff --git a/openingd/dualopend.c b/openingd/dualopend.c index 2afcc4993586..8c425af01b5c 100644 --- a/openingd/dualopend.c +++ b/openingd/dualopend.c @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include diff --git a/openingd/openingd.c b/openingd/openingd.c index b929a998f9b0..8870c34d9919 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/wire/peer_wire.c b/wire/peer_wire.c index 35089e48f1d7..0aca55a5d488 100644 --- a/wire/peer_wire.c +++ b/wire/peer_wire.c @@ -109,60 +109,6 @@ bool is_msg_for_gossipd(const u8 *cursor) return false; } -bool is_msg_gossip_broadcast(const u8 *cursor) -{ - switch ((enum peer_wire)fromwire_peektype(cursor)) { - case WIRE_CHANNEL_ANNOUNCEMENT: - case WIRE_NODE_ANNOUNCEMENT: - case WIRE_CHANNEL_UPDATE: - return true; - case WIRE_QUERY_SHORT_CHANNEL_IDS: - case WIRE_REPLY_SHORT_CHANNEL_IDS_END: - case WIRE_QUERY_CHANNEL_RANGE: - case WIRE_REPLY_CHANNEL_RANGE: - case WIRE_ONION_MESSAGE: - case WIRE_OBS2_ONION_MESSAGE: - case WIRE_WARNING: - case WIRE_INIT: - case WIRE_PING: - case WIRE_PONG: - case WIRE_ERROR: - case WIRE_OPEN_CHANNEL: - case WIRE_ACCEPT_CHANNEL: - case WIRE_FUNDING_CREATED: - case WIRE_FUNDING_SIGNED: - case WIRE_FUNDING_LOCKED: - case WIRE_SHUTDOWN: - case WIRE_CLOSING_SIGNED: - case WIRE_UPDATE_ADD_HTLC: - case WIRE_UPDATE_FULFILL_HTLC: - case WIRE_UPDATE_FAIL_HTLC: - case WIRE_UPDATE_FAIL_MALFORMED_HTLC: - case WIRE_COMMITMENT_SIGNED: - case WIRE_REVOKE_AND_ACK: - case WIRE_UPDATE_FEE: - case WIRE_UPDATE_BLOCKHEIGHT: - case WIRE_CHANNEL_REESTABLISH: - case WIRE_ANNOUNCEMENT_SIGNATURES: - case WIRE_GOSSIP_TIMESTAMP_FILTER: - case WIRE_TX_ADD_INPUT: - case WIRE_TX_REMOVE_INPUT: - case WIRE_TX_ADD_OUTPUT: - case WIRE_TX_REMOVE_OUTPUT: - case WIRE_TX_COMPLETE: - case WIRE_TX_SIGNATURES: - case WIRE_OPEN_CHANNEL2: - case WIRE_ACCEPT_CHANNEL2: - case WIRE_INIT_RBF: - case WIRE_ACK_RBF: -#if EXPERIMENTAL_FEATURES - case WIRE_STFU: -#endif - break; - } - return false; -} - /* Return true if it's an unknown ODD message. cursor is a tal ptr. */ bool is_unknown_msg_discardable(const u8 *cursor) { diff --git a/wire/peer_wire.h b/wire/peer_wire.h index d57a84d20bd7..12c951b8ff3e 100644 --- a/wire/peer_wire.h +++ b/wire/peer_wire.h @@ -23,8 +23,6 @@ bool is_unknown_msg_discardable(const u8 *cursor); /* Return true if it's a message for gossipd. */ bool is_msg_for_gossipd(const u8 *cursor); -/* Return true if it's a gossip update or announcement. */ -bool is_msg_gossip_broadcast(const u8 *cursor); /* Extract channel_id from various packets, return true if possible. */ bool extract_channel_id(const u8 *in_pkt, struct channel_id *channel_id);