Skip to content

Commit 04180c1

Browse files
endothermicdevrustyrussell
authored andcommitted
gossipd: add separate counter for unsolicted gossip
This will be used to drop underperforming gossipers instead of choosing at random.
1 parent 9956489 commit 04180c1

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

gossipd/gossipd.c

+18
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ void peer_supplied_good_gossip(struct daemon *daemon,
8383
peer->gossip_counter += amount;
8484
}
8585

86+
/* Increase a peer's query_reply_counter, if peer not NULL */
87+
void peer_supplied_query_response(struct daemon *daemon,
88+
const struct node_id *source_peer,
89+
size_t amount)
90+
{
91+
struct peer *peer;
92+
93+
if (!source_peer)
94+
return;
95+
96+
peer = find_peer(daemon, source_peer);
97+
if (!peer)
98+
return;
99+
100+
peer->query_reply_counter += amount;
101+
}
102+
86103
/* Queue a gossip message for the peer: connectd simply forwards it to
87104
* the peer. */
88105
void queue_peer_msg(struct daemon *daemon,
@@ -124,6 +141,7 @@ static void connectd_new_peer(struct daemon *daemon, const u8 *msg)
124141
/* Populate the rest of the peer info. */
125142
peer->daemon = daemon;
126143
peer->gossip_counter = 0;
144+
peer->query_reply_counter = 0;
127145
peer->scid_queries = NULL;
128146
peer->scid_query_idx = 0;
129147
peer->scid_query_nodes = NULL;

gossipd/gossipd.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ struct peer {
100100
/* How much contribution have we made to gossip? */
101101
size_t gossip_counter;
102102

103+
/* How much gossip have we sent in response to gossip queries? */
104+
size_t query_reply_counter;
105+
103106
/* The two features gossip cares about (so far) */
104107
bool gossip_queries_feature, initial_routing_sync_feature;
105108

@@ -128,11 +131,16 @@ struct peer {
128131
/* Search for a peer. */
129132
struct peer *find_peer(struct daemon *daemon, const struct node_id *id);
130133

131-
/* This peer (may be NULL) gave is valid gossip. */
134+
/* This peer (may be NULL) gave us valid gossip. */
132135
void peer_supplied_good_gossip(struct daemon *daemon,
133136
const struct node_id *source_peer,
134137
size_t amount);
135138

139+
/* Increase peer's query_reply_counter, if peer not NULL */
140+
void peer_supplied_query_response(struct daemon *daemon,
141+
const struct node_id *source_peer,
142+
size_t amount);
143+
136144
/* Get a random peer. NULL if no peers. */
137145
struct peer *first_random_peer(struct daemon *daemon,
138146
struct peer_node_id_map_iter *it);

gossipd/gossmap_manage.c

+7
Original file line numberDiff line numberDiff line change
@@ -804,11 +804,15 @@ static const char *process_channel_update(const tal_t *ctx,
804804
htlc_maximum_msat);
805805
}
806806

807+
/* Used to evaluate gossip peers' performance */
808+
peer_supplied_good_gossip(gm->daemon, source_peer, 1);
809+
807810
status_peer_debug(source_peer,
808811
"Received channel_update for channel %s/%d now %s",
809812
fmt_short_channel_id(tmpctx, scid),
810813
dir,
811814
channel_flags & ROUTING_FLAGS_DISABLED ? "DISABLED" : "ACTIVE");
815+
812816
return NULL;
813817
}
814818

@@ -941,6 +945,9 @@ static void process_node_announcement(struct gossmap_manage *gm,
941945
if (gossmap_node_announced(node))
942946
gossip_store_del(gm->daemon->gs, node->nann_off, WIRE_NODE_ANNOUNCEMENT);
943947

948+
/* Used to evaluate gossip peers' performance */
949+
peer_supplied_good_gossip(gm->daemon, source_peer, 1);
950+
944951
status_peer_debug(source_peer,
945952
"Received node_announcement for node %s",
946953
fmt_node_id(tmpctx, node_id));

gossipd/queries.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ const u8 *handle_reply_channel_range(struct peer *peer, const u8 *msg)
338338

339339
/* Credit peer for answering gossip, so seeker doesn't get upset:
340340
* since scids are only 8 bytes, use a discount over normal gossip. */
341-
peer_supplied_good_gossip(peer->daemon, &peer->id, tal_count(scids) / 20);
341+
peer_supplied_query_response(peer->daemon, &peer->id, tal_count(scids) / 20);
342342

343343
/* Old code used to set this to 1 all the time; not setting it implies
344344
* we're talking to an upgraded node. */

gossipd/seeker.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static bool selected_peer(struct seeker *seeker, struct peer *peer)
113113

114114
/* Give it some grace in case we immediately hit timer */
115115
seeker->prev_gossip_count
116-
= peer->gossip_counter - GOSSIP_SEEKER_INTERVAL(seeker);
116+
= peer->query_reply_counter - GOSSIP_SEEKER_INTERVAL(seeker);
117117
return true;
118118
}
119119

@@ -197,9 +197,9 @@ static bool peer_made_progress(struct seeker *seeker, const struct peer *peer)
197197
/* Has it made progress (at least one valid update per second)? If
198198
* not, we assume it's finished, and if it hasn't, we'll end up
199199
* querying backwards in next steps. */
200-
if (peer->gossip_counter
200+
if (peer->query_reply_counter
201201
>= seeker->prev_gossip_count + GOSSIP_SEEKER_INTERVAL(seeker)) {
202-
seeker->prev_gossip_count = peer->gossip_counter;
202+
seeker->prev_gossip_count = peer->query_reply_counter;
203203
return true;
204204
}
205205

@@ -867,7 +867,7 @@ static void check_probe(struct seeker *seeker,
867867

868868
status_peer_debug(&peer->id,
869869
"has only moved gossip %zu->%zu for probe, giving up on it",
870-
seeker->prev_gossip_count, peer->gossip_counter);
870+
seeker->prev_gossip_count, peer->query_reply_counter);
871871
seeker->random_peer = NULL;
872872
restart(seeker);
873873
}

gossipd/test/run-extended-info.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ struct short_channel_id *decode_short_ids(const tal_t *ctx UNNEEDED, const u8 *e
4242
void fromwire_sciddir_or_pubkey(const u8 **cursor UNNEEDED, size_t *max UNNEEDED,
4343
struct sciddir_or_pubkey *sciddpk UNNEEDED)
4444
{ fprintf(stderr, "fromwire_sciddir_or_pubkey called!\n"); abort(); }
45-
/* Generated stub for peer_supplied_good_gossip */
46-
void peer_supplied_good_gossip(struct daemon *daemon UNNEEDED,
47-
const struct node_id *source_peer UNNEEDED,
48-
size_t amount UNNEEDED)
49-
{ fprintf(stderr, "peer_supplied_good_gossip called!\n"); abort(); }
45+
/* Generated stub for peer_supplied_query_response */
46+
void peer_supplied_query_response(struct daemon *daemon UNNEEDED,
47+
const struct node_id *source_peer UNNEEDED,
48+
size_t amount UNNEEDED)
49+
{ fprintf(stderr, "peer_supplied_query_response called!\n"); abort(); }
5050
/* Generated stub for queue_peer_msg */
5151
void queue_peer_msg(struct daemon *daemon UNNEEDED,
5252
const struct node_id *peer UNNEEDED,

0 commit comments

Comments
 (0)