Skip to content

Commit cca113f

Browse files
committed
Merge bitcoin/bitcoin#34008: log: don't rate-limit "new peer" with -debug=net
d4d184e log: don't rate-limit "new peer" with -debug=net (0xb10c) Pull request description: Previously, when `debug=net` is enabled, we log "New [..] peer connected" for new inbound peers with `LogInfo`. However, `LogInfo` will get rate-limited since bitcoin/bitcoin#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`. The new log messages look similar to: ``` 2025-12-08T00:00:00Z [net] New inbound peer connected: transport=v2 version=70016 blocks=0 peer=1 2025-12-08T00:00:00Z New outbound-full-relay peer connected: transport=v2 version=70016 blocks=281738 peer=5 ``` -- 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. ACKs for top commit: stickies-v: utACK d4d184e Crypt-iQ: tACK d4d184e maflcko: review ACK d4d184e 🚲 rkrux: lgtm code review ACK d4d184e glozow: lgtm ACK d4d184e Tree-SHA512: 14dbf693fa44a74c9822590e7a08167d2deeb1bc6f4b8aeb00c1b035c0df7101087d5c80a3c0d637879d5c52f88b30f0cb4c0577cff6f647d2eb3300f49d8ea3
2 parents 2c44c41 + d4d184e commit cca113f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/net_processing.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3666,16 +3666,22 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
36663666
return;
36673667
}
36683668

3669+
auto new_peer_msg = [&]() {
3670+
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
3671+
return strprintf("New %s peer connected: transport: %s, version: %d, blocks=%d peer=%d%s%s\n",
3672+
pfrom.ConnectionTypeAsString(),
3673+
TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type),
3674+
pfrom.nVersion.load(), peer->m_starting_height,
3675+
pfrom.GetId(), pfrom.LogIP(fLogIPs),
3676+
(mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
3677+
};
3678+
36693679
// Log successful connections unconditionally for outbound, but not for inbound as those
36703680
// can be triggered by an attacker at high rate.
3671-
if (!pfrom.IsInboundConn() || LogAcceptCategory(BCLog::NET, BCLog::Level::Debug)) {
3672-
const auto mapped_as{m_connman.GetMappedAS(pfrom.addr)};
3673-
LogInfo("New %s %s peer connected: version: %d, blocks=%d, peer=%d%s%s\n",
3674-
pfrom.ConnectionTypeAsString(),
3675-
TransportTypeAsString(pfrom.m_transport->GetInfo().transport_type),
3676-
pfrom.nVersion.load(), peer->m_starting_height,
3677-
pfrom.GetId(), pfrom.LogIP(fLogIPs),
3678-
(mapped_as ? strprintf(", mapped_as=%d", mapped_as) : ""));
3681+
if (pfrom.IsInboundConn()) {
3682+
LogDebug(BCLog::NET, "%s", new_peer_msg());
3683+
} else {
3684+
LogInfo("%s", new_peer_msg());
36793685
}
36803686

36813687
if (pfrom.GetCommonVersion() >= SHORT_IDS_BLOCKS_VERSION) {

0 commit comments

Comments
 (0)