Skip to content
This repository was archived by the owner on Apr 17, 2020. It is now read-only.

Commit c99906a

Browse files
rustyrussellcdecker
authored andcommitted
per-peer-daemons: tie in gossip filter.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 5292f11 commit c99906a

File tree

13 files changed

+33
-3
lines changed

13 files changed

+33
-3
lines changed

channeld/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ CHANNELD_COMMON_OBJS := \
4848
common/features.o \
4949
common/gen_status_wire.o \
5050
common/gen_peer_status_wire.o \
51+
common/gossip_rcvd_filter.o \
5152
common/gossip_store.o \
5253
common/htlc_state.o \
5354
common/htlc_trim.o \

closingd/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ CLOSINGD_COMMON_OBJS := \
5757
common/features.o \
5858
common/gen_peer_status_wire.o \
5959
common/gen_status_wire.o \
60+
common/gossip_rcvd_filter.o \
6061
common/gossip_store.o \
6162
common/htlc_wire.o \
6263
common/key_derive.o \
@@ -66,6 +67,7 @@ CLOSINGD_COMMON_OBJS := \
6667
common/peer_failed.o \
6768
common/per_peer_state.o \
6869
common/permute_tx.o \
70+
common/pseudorand.o \
6971
common/read_peer_msg.o \
7072
common/socket_close.o \
7173
common/status.o \

common/gossip_store.c

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <assert.h>
22
#include <ccan/crc32c/crc32c.h>
33
#include <common/features.h>
4+
#include <common/gossip_rcvd_filter.h>
45
#include <common/gossip_store.h>
56
#include <common/per_peer_state.h>
67
#include <common/status.h>
@@ -122,6 +123,12 @@ u8 *gossip_store_next(const tal_t *ctx, struct per_peer_state *pps)
122123
0, SEEK_CUR) - msglen,
123124
tal_hex(tmpctx, msg));
124125

126+
/* Don't send back gossip they sent to us! */
127+
if (gossip_rcvd_filter_del(pps->grf, msg)) {
128+
msg = tal_free(msg);
129+
continue;
130+
}
131+
125132
/* Ignore gossipd internal messages. */
126133
type = fromwire_peektype(msg);
127134
if (type != WIRE_CHANNEL_ANNOUNCEMENT

common/per_peer_state.c

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <assert.h>
22
#include <ccan/fdpass/fdpass.h>
3+
#include <common/gossip_rcvd_filter.h>
34
#include <common/per_peer_state.h>
45
#include <unistd.h>
56
#include <wire/wire.h>
@@ -22,6 +23,7 @@ struct per_peer_state *new_per_peer_state(const tal_t *ctx,
2223
pps->cs = *cs;
2324
pps->gs = NULL;
2425
pps->peer_fd = pps->gossip_fd = pps->gossip_store_fd = -1;
26+
pps->grf = new_gossip_rcvd_filter(pps);
2527
tal_add_destructor(pps, destroy_per_peer_state);
2628
return pps;
2729
}
@@ -70,6 +72,7 @@ void towire_per_peer_state(u8 **pptr, const struct per_peer_state *pps)
7072
towire_bool(pptr, pps->gs != NULL);
7173
if (pps->gs)
7274
towire_gossip_state(pptr, pps->gs);
75+
/* We don't pass the gossip_rcvd_filter: it's merely an optimization */
7376
}
7477

7578
void per_peer_state_fdpass_send(int fd, const struct per_peer_state *pps)
@@ -138,4 +141,5 @@ void per_peer_state_reset_gossip_timer(struct per_peer_state *pps)
138141
t = time_from_msec(pps->dev_gossip_broadcast_msec);
139142
#endif
140143
pps->gs->next_gossip = timemono_add(time_mono(), t);
144+
gossip_rcvd_filter_age(pps->grf);
141145
}

common/per_peer_state.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct per_peer_state {
2020
struct crypto_state cs;
2121
/* NULL if it's not initialized yet */
2222
struct gossip_state *gs;
23+
/* Cache of msgs we have received, to avoid re-xmitting from store */
24+
struct gossip_rcvd_filter *grf;
2325
#if DEVELOPER
2426
/* Normally 60000, but adjustable for dev mode */
2527
u32 dev_gossip_broadcast_msec;

common/read_peer_msg.c

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <ccan/fdpass/fdpass.h>
22
#include <common/crypto_sync.h>
3+
#include <common/gossip_rcvd_filter.h>
34
#include <common/gossip_store.h>
45
#include <common/peer_failed.h>
56
#include <common/per_peer_state.h>
@@ -166,6 +167,7 @@ bool handle_peer_gossip_or_error(struct per_peer_state *pps,
166167
if (handle_timestamp_filter(pps, msg))
167168
return true;
168169
else if (is_msg_for_gossipd(msg)) {
170+
gossip_rcvd_filter_add(pps->grf, msg);
169171
wire_sync_write(pps->gossip_fd, msg);
170172
/* wire_sync_write takes, so don't take again. */
171173
return true;

connectd/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ CONNECTD_COMMON_OBJS := \
5151
common/dev_disconnect.o \
5252
common/features.o \
5353
common/gen_status_wire.o \
54+
common/gossip_rcvd_filter.o \
5455
common/key_derive.o \
5556
common/memleak.o \
5657
common/msg_queue.o \

devtools/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ DEVTOOLS_COMMON_OBJS := \
1616
common/crypto_state.o \
1717
common/decode_short_channel_ids.o \
1818
common/features.o \
19+
common/gossip_rcvd_filter.o \
1920
common/hash_u5.o \
2021
common/memleak.o \
2122
common/node_id.o \
2223
common/per_peer_state.o \
24+
common/pseudorand.o \
2325
common/json.o \
2426
common/json_helpers.o \
2527
common/type_to_string.o \

gossipd/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ GOSSIPD_COMMON_OBJS := \
5151
common/dev_disconnect.o \
5252
common/features.o \
5353
common/gen_status_wire.o \
54+
common/gossip_rcvd_filter.o \
5455
common/key_derive.o \
5556
common/memleak.o \
5657
common/msg_queue.o \

lightningd/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ LIGHTNINGD_COMMON_OBJS := \
3131
common/funding_tx.o \
3232
common/gen_peer_status_wire.o \
3333
common/gen_status_wire.o \
34+
common/gossip_rcvd_filter.o \
3435
common/hash_u5.o \
3536
common/htlc_state.o \
3637
common/htlc_trim.o \

openingd/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ OPENINGD_COMMON_OBJS := \
5151
common/funding_tx.o \
5252
common/gen_status_wire.o \
5353
common/gen_peer_status_wire.o \
54+
common/gossip_rcvd_filter.o \
5455
common/gossip_store.o \
5556
common/htlc_wire.o \
5657
common/initial_channel.o \

openingd/openingd.c

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <common/features.h>
2222
#include <common/funding_tx.h>
2323
#include <common/gen_peer_status_wire.h>
24+
#include <common/gossip_rcvd_filter.h>
2425
#include <common/gossip_store.h>
2526
#include <common/initial_channel.h>
2627
#include <common/key_derive.h>
@@ -377,6 +378,7 @@ static u8 *opening_negotiate_msg(const tal_t *ctx, struct state *state,
377378

378379
/* Some messages go straight to gossipd. */
379380
if (is_msg_for_gossipd(msg)) {
381+
gossip_rcvd_filter_add(state->pps->grf, msg);
380382
wire_sync_write(state->pps->gossip_fd, take(msg));
381383
continue;
382384
}

tests/test_gossip.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -978,8 +978,13 @@ def test_node_reannounce(node_factory, bitcoind):
978978
nannouncement = l2.daemon.wait_for_log(r'{}.*\[IN\] 0101.*{}'.format(l1.info['id'], l1.info['id'])).split('[IN] ')[1]
979979
wait_for(lambda: only_one(l2.rpc.listnodes(l1.info['id'])['nodes'])['alias'] == 'SENIORBEAM')
980980

981-
# Restart should re-xmit exact same update on reconnect.
982-
l1.restart()
981+
# Restart should re-xmit exact same update on reconnect, but make sure
982+
# l2 doesn't send it first!
983+
l1.stop()
984+
l2.stop()
985+
os.remove(os.path.join(l2.daemon.lightning_dir, 'gossip_store'))
986+
l2.start()
987+
l1.start()
983988

984989
# l1 should retransmit it exactly the same (no timestamp change!)
985990
l2.daemon.wait_for_log(r'{}.*\[IN\] {}'.format(l1.info['id'], nannouncement))
@@ -1377,7 +1382,6 @@ def test_gossip_announce_unknown_block(node_factory, bitcoind):
13771382
sync_blockheight(bitcoind, [l1])
13781383

13791384

1380-
@pytest.mark.xfail(strict=True)
13811385
@unittest.skipIf(not DEVELOPER, "gossip without DEVELOPER=1 is slow")
13821386
def test_gossip_no_backtalk(node_factory):
13831387
l1, l2 = node_factory.line_graph(2, wait_for_announce=True)

0 commit comments

Comments
 (0)