From 8ef4b36a1fdbf55dea764c8914d3ecf0aa731018 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 22 Mar 2023 07:40:53 +1030 Subject: [PATCH] gossipd: send our own gossip aggressively when a new peer connects. This was previously the role of connectd, but it's actually more efficient for us to do it: connectd has to sweep through the entire gossip_store, but we have datastructures for this already. Signed-off-by: Rusty Russell --- gossipd/gossipd.c | 37 +++++++++++++++++++++++++++++++++++++ tests/test_gossip.py | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/gossipd/gossipd.c b/gossipd/gossipd.c index ab9951921..cb561888a 100644 --- a/gossipd/gossipd.c +++ b/gossipd/gossipd.c @@ -402,6 +402,40 @@ update_node_annoucement: maybe_send_own_node_announce(daemon, false); } +/* BOLT #7: + * - if the `gossip_queries` feature is negotiated: + * - MUST NOT relay any gossip messages it did not generate itself, + * unless explicitly requested. + */ +/* i.e. the strong implication is that we spam our own gossip aggressively! + * "Look at me!" "Look at me!!!!". + */ +static void dump_our_gossip(struct daemon *daemon, struct peer *peer) +{ + struct node *me; + struct chan_map_iter i; + struct chan *chan; + + /* Find ourselves; if no channels, nothing to send */ + me = get_node(daemon->rstate, &daemon->id); + if (!me) + return; + + for (chan = first_chan(me, &i); chan; chan = next_chan(me, &i)) { + int dir; + + if (!is_chan_public(chan)) + continue; + + /* Send announce */ + queue_peer_from_store(peer, &chan->bcast); + /* Send update if we have one */ + dir = half_chan_idx(me, chan); + if (is_halfchan_defined(&chan->half[dir])) + queue_peer_from_store(peer, &chan->half[dir].bcast); + } +} + /*~ This is where connectd tells us about a new peer we might want to * gossip with. */ static void connectd_new_peer(struct daemon *daemon, const u8 *msg) @@ -441,6 +475,9 @@ static void connectd_new_peer(struct daemon *daemon, const u8 *msg) if (node) peer_enable_channels(daemon, node); + /* Send everything we know about our own channels */ + dump_our_gossip(daemon, peer); + /* This sends the initial timestamp filter. */ seeker_setup_peer_gossip(daemon->seeker, peer); } diff --git a/tests/test_gossip.py b/tests/test_gossip.py index cc41a6464..9f5dc64c0 100644 --- a/tests/test_gossip.py +++ b/tests/test_gossip.py @@ -1397,7 +1397,7 @@ def test_gossipwith(node_factory): num_msgs += 1 # one channel announcement, two channel_updates, two node announcements. - assert num_msgs == 5 + assert num_msgs == 7 def test_gossip_notices_close(node_factory, bitcoind):