Skip to content

Commit

Permalink
channeld: take over gossip_rcvd_filter.c and is_msg_gossip_broadcast.
Browse files Browse the repository at this point in the history
channeld is the only user of these functions, since it now streams
all gossip itself.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
  • Loading branch information
rustyrussell committed Jun 17, 2022
1 parent ecdfbbf commit 7c8dc62
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 74 deletions.
1 change: 0 additions & 1 deletion channeld/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion closingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion common/gossip_store.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "config.h"
#include <ccan/crc32c/crc32c.h>
#include <common/gossip_rcvd_filter.h>
#include <common/gossip_store.h>
#include <common/per_peer_state.h>
#include <common/status.h>
Expand Down
2 changes: 1 addition & 1 deletion connectd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <common/daemon_conn.h>
#include <common/dev_disconnect.h>
#include <common/ecdh_hsmd.h>
#include <common/gossip_rcvd_filter.h>
#include <common/gossip_store.h>
#include <common/jsonrpc_errors.h>
#include <common/memleak.h>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include "config.h"
#include <ccan/crypto/siphash24/siphash24.h>
#include <ccan/htable/htable.h>
#include <common/gossip_rcvd_filter.h>
#include <common/memleak.h>
#include <common/pseudorand.h>
#include <connectd/gossip_rcvd_filter.h>
#include <wire/peer_wire.h>

static u64 msg_key(const u8 *msg)
Expand Down
6 changes: 3 additions & 3 deletions common/gossip_rcvd_filter.h → connectd/gossip_rcvd_filter.h
Original file line number Diff line number Diff line change
@@ -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 <ccan/short_types/short_types.h>
#include <ccan/tal/tal.h>
Expand All @@ -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 */
56 changes: 55 additions & 1 deletion connectd/multiplex.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <common/dev_disconnect.h>
#include <common/features.h>
#include <common/gossip_constants.h>
#include <common/gossip_rcvd_filter.h>
#include <common/gossip_store.h>
#include <common/memleak.h>
#include <common/per_peer_state.h>
Expand All @@ -23,6 +22,7 @@
#include <connectd/connectd.h>
#include <connectd/connectd_gossipd_wiregen.h>
#include <connectd/connectd_wiregen.h>
#include <connectd/gossip_rcvd_filter.h>
#include <connectd/multiplex.h>
#include <connectd/onion_message.h>
#include <errno.h>
Expand Down Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "config.h"
#include "../gossip_rcvd_filter.c"
#include "../pseudorand.c"
#include "../../wire/fromwire.c"
#include <assert.h>
#include <common/setup.h>
#include <stdio.h>

Expand Down Expand Up @@ -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(); }
Expand Down
1 change: 0 additions & 1 deletion devtools/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion gossipd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion lightningd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion openingd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion openingd/dualopend.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <common/billboard.h>
#include <common/blockheight_states.h>
#include <common/channel_type.h>
#include <common/gossip_rcvd_filter.h>
#include <common/gossip_store.h>
#include <common/initial_channel.h>
#include <common/lease_rates.h>
Expand Down
1 change: 0 additions & 1 deletion openingd/openingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <ccan/tal/str/str.h>
#include <common/channel_type.h>
#include <common/fee_states.h>
#include <common/gossip_rcvd_filter.h>
#include <common/gossip_store.h>
#include <common/initial_channel.h>
#include <common/memleak.h>
Expand Down
54 changes: 0 additions & 54 deletions wire/peer_wire.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 0 additions & 2 deletions wire/peer_wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7c8dc62

Please sign in to comment.