MCPcopy Create free account
hub / github.com/ElementsProject/lightning / random_seeker

Function random_seeker

gossipd/seeker.c:177–202  ·  view source on GitHub ↗

Get a random peer, but try our preferred peer first, if any. This * biasses us to the peer that told us of unexpected gossip. */

Source from the content-addressed store, hash-verified

175/* Get a random peer, but try our preferred peer first, if any. This
176 * biasses us to the peer that told us of unexpected gossip. */
177static struct peer *random_seeker(struct seeker *seeker,
178 bool (*check_peer)(const struct peer *peer))
179{
180 struct peer *peer = seeker->preferred_peer;
181 struct peer *first;
182 struct peer_node_id_map_iter it;
183
184 /* 80% chance of immediately choosing a peer who reported the missing
185 * stuff: they presumably can tell us more about it. We don't
186 * *always* choose it because it could be simply spamming us with
187 * invalid announcements to get chosen, and we don't handle that case
188 * well yet. */
189 if (peer && check_peer(peer) && pseudorand(5) != 0) {
190 seeker->random_peer = NULL;
191 return peer;
192 }
193
194 /* Rotate through, so we don't favor a single peer. */
195 peer = first = first_random_peer(seeker->daemon, &it);
196 while (peer) {
197 if (check_peer(peer))
198 break;
199 peer = next_random_peer(seeker->daemon, first, &it);
200 }
201 return peer;
202}
203
204static bool peer_made_progress(struct seeker *seeker, const struct peer *peer)
205{

Callers 7

seek_any_unknown_scidsFunction · 0.85
seek_any_stale_scidsFunction · 0.85
process_scid_probeFunction · 0.85
peer_gossip_probe_scidsFunction · 0.85
check_firstpeerFunction · 0.85
maybe_rotate_gossipersFunction · 0.85

Calls 2

first_random_peerFunction · 0.70
next_random_peerFunction · 0.70

Tested by

no test coverage detected