From d4d184eda9c0f73bc31ece07d5001d887b5c6914 Mon Sep 17 00:00:00 2001 From: 0xb10c Date: Thu, 4 Dec 2025 15:54:54 +0100 Subject: [PATCH] log: don't rate-limit "new peer" with -debug=net Previously, when `debug=net` is enabled, we log "New [..] peer connected" for new inbound peers with `LogInfo`. However, `LogInfo` will get rate-limited since https://github.com/bitcoin/bitcoin/pull/32604. When we specifically turn on `debug=net`, we don't want these log messages to be rate-limited. To fix this, use `LogDebug(BCLog::NET, ...)` for potentially high- rate inbound connections. Otherwise use `LogInfo`. This means we don't rate-limit the messages for inbound peers when `debug=net` is turned on but will rate-limit if we created outbound at a high rate as these are logged via `LogInfo`. -- I ran into this message getting rate-limited on one of my monitoring nodes with `-logsourcelocations=1`: With logsourcelocations, one of these lines is about 338 chars (or 338 bytes) long. We rate-limit after more than 1048576 bytes per hour, which results in about 3100 in- and outbound connections per hour. With evicted and instantly reconnecting connections from an entity like LinkingLion, this can be reached fairly quickly. Co-Authored-By: Eugene Siegel Co-Authored-By: Anthony Towns --- src/net_processing.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index c6bd60c587e..5f61684009f 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -3659,16 +3659,22 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type, return; } + auto new_peer_msg = [&]() { + const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)}; + return strprintf("New %s peer connected: transport: %s, version: %d, blocks=%d peer=%d%s%s\n", + pfrom.ConnectionTypeAsString(), + TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type), + pfrom.nVersion.load(), peer->m_starting_height, + pfrom.GetId(), pfrom.LogIP(fLogIPs), + (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : "")); + }; + // Log successful connections unconditionally for outbound, but not for inbound as those // can be triggered by an attacker at high rate. - if (!pfrom.IsInboundConn() || LogAcceptCategory(BCLog::NET, BCLog::Level::Debug)) { - const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)}; - LogInfo("New %s %s peer connected: version: %d, blocks=%d, peer=%d%s%s\n", - pfrom.ConnectionTypeAsString(), - TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type), - pfrom.nVersion.load(), peer->m_starting_height, - pfrom.GetId(), pfrom.LogIP(fLogIPs), - (mapped_as ? strprintf(", mapped_as=%d", mapped_as) : "")); + if (pfrom.IsInboundConn()) { + LogDebug(BCLog::NET, "%s", new_peer_msg()); + } else { + LogInfo("%s", new_peer_msg()); } if (pfrom.GetCommonVersion() >= SHORT_IDS_BLOCKS_VERSION) {