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

Function maybe_gossip_msg

connectd/multiplex.c:698–787  ·  view source on GitHub ↗

Gossip response or something from gossip store */

Source from the content-addressed store, hash-verified

696
697/* Gossip response or something from gossip store */
698static const u8 *maybe_gossip_msg(const tal_t *ctx, struct peer *peer)
699{
700 const u8 *msg;
701 struct timemono query_start;
702 struct gossmap *gossmap;
703 u32 timestamp;
704 const u8 **msgs;
705 u64 cpu_budget, wait_usec;
706 bool answering;
707
708 maybe_reset_usage_window(peer);
709
710 cpu_budget = peer_cpu_budget(peer);
711
712 wait_usec = maybe_throttle_usec(peer, &peer->gs.throttle_warned, "outgoing",
713 peer->gs.bytes_this_second, peer->daemon->gossip_stream_limit,
714 peer->gs.cpu_usec_this_second, cpu_budget);
715 if (wait_usec) {
716 /* Replace normal timer with a timer after throttle. */
717 peer->gs.active = false;
718 tal_free(peer->gs.gossip_timer);
719 peer->gs.gossip_timer
720 = new_abstimer(&peer->daemon->timers,
721 peer,
722 timemono_add(time_mono(), time_from_usec(wait_usec)),
723 wake_gossip, peer);
724 return NULL;
725 }
726
727 gossmap = get_gossmap(peer->daemon);
728
729 /* This can return more than one: it's the expensive part (gossmap
730 * walks, checksum/timestamp lookups), so it's what we charge for
731 * cpu_usec_this_second above. But only while we're answering a
732 * query: we're called every time the output queue drains, and the
733 * rest of the time it's a no-op. */
734 answering = peer->scid_queries || peer->range_scids;
735 query_start = time_mono();
736 msgs = maybe_create_query_responses(tmpctx, peer, gossmap);
737 if (answering)
738 peer->gs.cpu_usec_this_second
739 += time_to_usec(timemono_between(time_mono(),
740 query_start));
741 if (tal_count(msgs) > 0) {
742 /* We return the first one for immediate sending, and queue
743 * others for future. We add all the lengths now though! */
744 for (size_t i = 0; i < tal_count(msgs); i++) {
745 peer->gs.bytes_this_second += tal_bytelen(msgs[i]);
746 status_peer_io(LOG_IO_OUT, &peer->id, msgs[i]);
747 if (i > 0)
748 msg_to_peer_outq(peer, take(msgs[i]));
749 }
750 return msgs[0];
751 }
752
753 /* dev-mode can suppress all gossip */
754 if (peer->daemon->dev_suppress_gossip)
755 return NULL;

Callers 1

next_msg_for_peerFunction · 0.85

Calls 15

maybe_reset_usage_windowFunction · 0.85
peer_cpu_budgetFunction · 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

Tested by

no test coverage detected