Skip to content

Commit 7c2d322

Browse files
committed
gossipd: put common size restrictions on all maps.
We already limited pending_ann_map and early_ann_map to 10,000 entries: do the same for pending_nannounces, pending_cupdates and early_cupdates. Add CI_UNEXPECTED so CI gets upset if this happens unexpectedly. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
1 parent 686bf87 commit 7c2d322

1 file changed

Lines changed: 36 additions & 4 deletions

File tree

gossipd/gossmap_manage.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sys/wait.h>
3030
#include <unistd.h>
3131

32+
#define PENDING_LIMIT 10000
3233
#define GOSSIP_STORE_COMPACT_FILENAME "gossip_store.compact"
3334

3435
struct pending_cannounce {
@@ -133,9 +134,24 @@ static void enqueue_cupdate(struct pending_cupdate ***queue,
133134
u32 fee_proportional_millionths,
134135
u32 timestamp,
135136
const u8 *update TAKES,
136-
const struct node_id *source_peer TAKES)
137+
const struct node_id *source_peer)
137138
{
138-
struct pending_cupdate *pcu = tal(*queue, struct pending_cupdate);
139+
struct pending_cupdate *pcu;
140+
141+
if (tal_count(*queue) > PENDING_LIMIT) {
142+
static bool warned = false;
143+
status_unusual_once(&warned,
144+
CI_UNEXPECTED
145+
"channel_updates being flooded by %s: dropping some",
146+
source_peer
147+
? fmt_node_id(tmpctx, source_peer)
148+
: "unknown");
149+
tal_free_if_taken(update);
150+
tal_free_if_taken(source_peer);
151+
return;
152+
}
153+
154+
pcu = tal(*queue, struct pending_cupdate);
139155

140156
pcu->scid = scid;
141157
pcu->signature = *signature;
@@ -159,7 +175,22 @@ static void enqueue_nannounce(struct pending_nannounce ***queue,
159175
const u8 *nannounce TAKES,
160176
const struct node_id *source_peer TAKES)
161177
{
162-
struct pending_nannounce *pna = tal(*queue, struct pending_nannounce);
178+
struct pending_nannounce *pna;
179+
180+
if (tal_count(*queue) > PENDING_LIMIT) {
181+
static bool warned = false;
182+
status_unusual_once(&warned,
183+
CI_UNEXPECTED
184+
"node_announcements being flooded by %s: dropping some",
185+
source_peer
186+
? fmt_node_id(tmpctx, source_peer)
187+
: "unknown");
188+
tal_free_if_taken(nannounce);
189+
tal_free_if_taken(source_peer);
190+
return;
191+
}
192+
193+
pna = tal(*queue, struct pending_nannounce);
163194

164195
pna->node_id = *node_id;
165196
pna->timestamp = timestamp;
@@ -183,8 +214,9 @@ static bool map_add(struct cannounce_map *map,
183214
struct pending_cannounce *pca)
184215
{
185216
/* More than 10000 pending things? Stop! */
186-
if (map->count > 10000) {
217+
if (map->count > PENDING_LIMIT) {
187218
status_unusual_once(&map->flood_reported,
219+
CI_UNEXPECTED
188220
"%s being flooded by %s: dropping some",
189221
map->name,
190222
pca->source_peer

0 commit comments

Comments
 (0)