net/log: standardize peer+addr log formatting via LogPeer#34389
net/log: standardize peer+addr log formatting via LogPeer#34389sedited merged 4 commits intobitcoin:masterfrom
LogPeer#34389Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/34389. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
d515f7c to
fd8aaac
Compare
fd8aaac to
af07341
Compare
naiyoma
left a comment
There was a problem hiding this comment.
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-
LogPeernet 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.
Lines 1984 to 1987 in 0165132
and in
bitcoin/src/net_processing.cpp
Line 4285 in 0165132
bitcoin/src/net_processing.cpp
Line 4299 in 0165132
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>", |
There was a problem hiding this comment.
nit: feel free to ignore
IMO <unknown-entry> or <unknown-addr> is clearer
There was a problem hiding this comment.
Thanks, will apply the nits if we need another push
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Added "<unknown-addr>"
af07341 to
74bb2b3
Compare
src/net_processing.cpp
Outdated
| index.nHeight, | ||
| peer.GetId(), | ||
| peer.LogIP(fLogIPs) | ||
| peer.LogPeer(fLogIPs) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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>
74bb2b3 to
2233547
Compare
|
Thanks for the reviews!
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. |
|
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. |
|
It's the same bugfix that #34293 adjusts (missing comma in logs that was previously there), applied systematically. |
|
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. |
|
#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. |
|
ACK 2233547 |
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 beforepeeraddr=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 emitspeer=<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=1and observe peer log lines now showpeer=<id>, peeraddr=<addr>(comma-separated). The new assertion infeature_logging.pyautomates this check.