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

Function maybe_gossip_msg

connectd/multiplex.c:686–771  ·  view source on GitHub ↗

Gossip response or something from gossip store */

Source from the content-addressed store, hash-verified

684
685/* Gossip response or something from gossip store */
686static const u8 *maybe_gossip_msg(const tal_t *ctx, struct peer *peer)
687{
688 const u8 *msg;
689 struct timemono query_start;
690 struct gossmap *gossmap;
691 u32 timestamp;
692 const u8 **msgs;
693 u64 cpu_budget, wait_usec;
694
695 maybe_reset_usage_window(peer);
696
697 /* Each peer gets its "fair share" of our query-answering CPU */
698 cpu_budget = peer->daemon->cpu_budget_usec_limit
699 / peer_htable_count(peer->daemon->peers);
700
701 wait_usec = maybe_throttle_usec(peer, &peer->gs.throttle_warned, "outgoing",
702 peer->gs.bytes_this_second, peer->daemon->gossip_stream_limit,
703 peer->gs.cpu_usec_this_second, cpu_budget);
704 if (wait_usec) {
705 /* Replace normal timer with a timer after throttle. */
706 peer->gs.active = false;
707 tal_free(peer->gs.gossip_timer);
708 peer->gs.gossip_timer
709 = new_abstimer(&peer->daemon->timers,
710 peer,
711 timemono_add(time_mono(), time_from_usec(wait_usec)),
712 wake_gossip, peer);
713 return NULL;
714 }
715
716 gossmap = get_gossmap(peer->daemon);
717
718 /* This can return more than one: it's the expensive part (gossmap
719 * walks, checksum/timestamp lookups), so it's what we charge for
720 * cpu_usec_this_second above. */
721 query_start = time_mono();
722 msgs = maybe_create_query_responses(tmpctx, peer, gossmap);
723 peer->gs.cpu_usec_this_second
724 += time_to_usec(timemono_between(time_mono(), query_start));
725 if (tal_count(msgs) > 0) {
726 /* We return the first one for immediate sending, and queue
727 * others for future. We add all the lengths now though! */
728 for (size_t i = 0; i < tal_count(msgs); i++) {
729 peer->gs.bytes_this_second += tal_bytelen(msgs[i]);
730 status_peer_io(LOG_IO_OUT, &peer->id, msgs[i]);
731 if (i > 0)
732 msg_to_peer_outq(peer, take(msgs[i]));
733 }
734 return msgs[0];
735 }
736
737 /* dev-mode can suppress all gossip */
738 if (peer->daemon->dev_suppress_gossip)
739 return NULL;
740
741 /* Not streaming right now? */
742 if (!peer->gs.active)
743 return NULL;

Callers 1

next_msg_for_peerFunction · 0.85

Calls 15

maybe_reset_usage_windowFunction · 0.85
maybe_throttle_usecFunction · 0.85
tal_freeFunction · 0.85
timemono_addFunction · 0.85
time_monoFunction · 0.85
time_from_usecFunction · 0.85
time_to_usecFunction · 0.85
timemono_betweenFunction · 0.85
tal_bytelenFunction · 0.85
msg_to_peer_outqFunction · 0.85
gossmap_stream_nextFunction · 0.85

Tested by

no test coverage detected