Skip to content

net/log: standardize peer+addr log formatting via LogPeer#34389

Merged
sedited merged 4 commits intobitcoin:masterfrom
l0rinc:l0rinc/log-peer-formatting
Mar 11, 2026
Merged

net/log: standardize peer+addr log formatting via LogPeer#34389
sedited merged 4 commits intobitcoin:masterfrom
l0rinc:l0rinc/log-peer-formatting

Conversation

@l0rinc
Copy link
Contributor

@l0rinc l0rinc commented Jan 23, 2026

This is an alternative to #34293, but aims to address the remaining logging inconsistencies more broadly.
It extends the example fixed there to every instance, restores the original separator behavior, applies it consistently via a single helper, and adds tests for logips (covering both current and new behavior).

Problem

After #28521 centralized peer address logging into CNode::LogIP(), the original comma separator before peeraddr= was lost, resulting in inconsistent formatting across net (and recent private broadcast) logs.
Some lines also had double spaces, empty fields, or mismatched format specifiers.

Fix

Introduces CNode::LogPeer(bool) which always emits peer=<id> and, when -logips=1, appends , peeraddr=<addr>. This eliminates hand-rolled separators and makes peer identification predictable.
Minor issues (double spaces, empty placeholders, format specifiers) are fixed along the way in separate commits.

Reproducer

Run with -debug=net -logips=1 and observe peer log lines now show peer=<id>, peeraddr=<addr> (comma-separated). The new assertion in feature_logging.py automates this check.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 23, 2026

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34389.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK vasild, naiyoma, sedited

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #34743 (p2p: protect manual evictions by willcl-ark)
  • #34707 (net: keep finished private broadcast txs in memory, rebroadcast if evicted from mempool by andrewtoth)
  • #34588 (refactor: decompose Peer struct into focused sub-components by w0xlt)
  • #34565 (refactor: extract BlockDownloadManager from PeerManagerImpl by w0xlt)
  • #34271 (net_processing: make m_tx_for_private_broadcast optional by vasild)
  • #34059 (refactor: Use NodeClock::time_point for m_addr_token_timestamp by maflcko)
  • #30343 (wallet, logging: Replace WalletLogPrintf() with LogInfo() by ryanofsky)
  • #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@naiyoma naiyoma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

Renaming LogIp to LogPeer, expanding it to also handle peer Id, and restoring the comma separator between peer= and peeraddr=. This refactors improves readability and consistency in the logs.

briefly tested af07341

2026-01-30T12:25:06Z [net] receive version message: /Satoshi:30.0.0/: version 70016, blocks=934343, us=[::]:0, txrelay=1, peer=7, peeraddr=rf66bdjae6n2gziqe4346hrlfe2xxkzysjq6l72p5imbyig7hxwzdkid.onion:8333

reviewed

  • b12c137 log: show placeholders for missing peer fields
  • 6281ebd log: fix minor formatting in debug logs
  • cd49c08 test: add pre-LogPeer net log assertion

changes LGTM

noticed these double spaces and i think they can be removed in 6281ebd, but I’m not sure if they’re intentional.

bitcoin/src/validation.cpp

Lines 1984 to 1987 in 0165132

LogInfo("%s: current best=%s height=%d log2_work=%f date=%s\n", __func__,
tip->GetBlockHash().ToString(), m_chain.Height(), log(tip->nChainWork.getdouble())/log(2.0),
FormatISO8601DateTime(tip->GetBlockTime()));
CheckForkWarningConditions();

and in

LogDebug(BCLog::NET, " getblocks stopping at %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());

LogDebug(BCLog::NET, " getblocks stopping at limit %d %s\n", pindex->nHeight, pindex->GetBlockHash().ToString());

src/addrman.cpp Outdated
auto colliding_entry = mapInfo.find(vvTried[tried_bucket][tried_bucket_pos]);
LogDebug(BCLog::ADDRMAN, "Collision with %s while attempting to move %s to tried table. Collisions=%d\n",
colliding_entry != mapInfo.end() ? colliding_entry->second.ToStringAddrPort() : "",
colliding_entry != mapInfo.end() ? colliding_entry->second.ToStringAddrPort() : "<unknown>",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: feel free to ignore
IMO <unknown-entry> or <unknown-addr> is clearer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, will apply the nits if we need another push

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would designate some addrman corruption, I guess. Just a thought, out of the scope of this PR since it is about logging - maybe add an assert or Assume that colliding_entry != mapInfo.end().

The current change is fine, because, "unknown" it better than an empty string.

Copy link
Contributor Author

@l0rinc l0rinc Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added "<unknown-addr>"

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 74bb2b3

index.nHeight,
peer.GetId(),
peer.LogIP(fLogIPs)
peer.LogPeer(fLogIPs)
Copy link
Contributor

@vasild vasild Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all callers of LogPeer() pass the same global variable fLogIPs, I wouldn't mind if callers are spared of having to do that and the LogPeer() method looks up that global variable internally.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind if callers are spared of having to do that

Excellent, removed all of them, the call sites are so much cleaner. Added you as coauthor.

@DrahtBot DrahtBot requested a review from naiyoma February 13, 2026 11:52
l0rinc and others added 4 commits February 15, 2026 22:54
Avoid logging an empty field when peer user agent or collision entry is missing.

Co-authored-by: naiyoma <lankas.aurelia@gmail.com>
Tidy a few debug log strings to avoid double spaces, concatenated status words, and mismatched format specifiers.

Co-authored-by: naiyoma <lankas.aurelia@gmail.com>
Assert net log output contains `peer=... peeraddr=...` before the comma change.
Use `LogPeer` for peer id plus optional `peeraddr`, separated with a comma.

Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
Co-authored-by: Vasil Dimov <vd@freebsd.org>
@l0rinc l0rinc force-pushed the l0rinc/log-peer-formatting branch from 74bb2b3 to 2233547 Compare February 15, 2026 21:57
@l0rinc
Copy link
Contributor Author

l0rinc commented Feb 15, 2026

Thanks for the reviews!

noticed these double spaces and i think they can be removed

Indeed, applied them and added you as coathor.

Rebased, and since I was modifying all those lines, I have also removed all trailing newlines to leave the campground a bit cleaner that we found it.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2233547

@fanquake
Copy link
Member

This was added to 31.x, but I'm not sure why. It doesn't seem to be a bugfix, or a new feature, or any more pressing than any other PRs? So I've dropped it back off for now.

@fanquake fanquake removed this from the 31.0 milestone Feb 20, 2026
@l0rinc
Copy link
Contributor Author

l0rinc commented Feb 20, 2026

It's the same bugfix that #34293 adjusts (missing comma in logs that was previously there), applied systematically.

@fanquake
Copy link
Member

I'm not sure that a missing comma in a log line, is a bug. If it was the case, then I think it'd be better to merge (and possibly backport) the single commit that fixes the issue, rather than larger, general refactor, right before feature freeze.

@Sjors
Copy link
Member

Sjors commented Feb 24, 2026

#28521 was shipped with v29 and v30 so it's not a newly introduced regression that we want to keep out of v31. It could make sense to, similar to what @fanquake suggests, merge the full change after branch-off and back-port a minimal fix. Though I'm not sure if that's worth doing, unless it's really hurting someone's log parsing.

@naiyoma
Copy link
Contributor

naiyoma commented Feb 26, 2026

ACK 2233547

Copy link
Contributor

@sedited sedited left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2233547

@sedited sedited merged commit e96d9e6 into bitcoin:master Mar 11, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants