-
Notifications
You must be signed in to change notification settings - Fork 37.7k
Log new headers #27278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Log new headers #27278
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. 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. |
babe8ac
to
75ee0d4
Compare
75ee0d4
to
dbd1442
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
Unconditionally logging headers (outside of IBD) makes sense to me. It doubles the number of messages per block, but since we check their proof-of-work, it's not too bad.
Similarly for compact blocks we check the PoW before logging.
utACK dbd1442
src/validation.cpp
Outdated
@@ -3832,6 +3832,18 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida | |||
if (ppindex) | |||
*ppindex = pindex; | |||
|
|||
const auto msg = strprintf("saw new valid header hash=%s", hash.ToString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add an anti-footgun note here, since I almost made that mistake:
// Not all valid headers have a known height, so we don't log pindex->nHeight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, let's capitalize the log message: Saw new …
If you drop hash =
from the message then the hash aligns with UpdateTip
, which makes the log easier to skim over. Update: no it doesn't :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you have a valid header without a known height? If you don't know all the ancestors, you can't tell if the nBits
value is valid, which we check in ContextualCheckBlockHeader
earlier in this function... (A missing prev block should result in return Invalid(BLOCK_MISSING_PREV)
prior to that) The only case where we don't do all that is if we're looking at the genesis block header, but we know its height is 0... What am I missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddToBlockIndex
checks if hashPrevBlock
is already in the index, and if not it won't set pprev
and nHeight
on the CBlockIndex
entry it returns. But I didn't check if that condition can ever be reached from the call in AcceptBlockHeader
.
Update: and indeed AcceptBlockHeader(
checks for this case and rejects it with prev-blk-not-found
.
So in that case it would be nice to log the height.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only other call site for AddToBlockIndex()
is LoadGenesisBlock()
, so I guess that's the only reason for the (generic looking) check of hashPrevBlock
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed this code is pretty ancient (and could use a comment): https://github.com/bitcoin/bitcoin/blame/f3ae51dcced8a16175426051ce888130cc2493af/src/main.cpp#L2056-L2063
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
Prefer this over #27276 as well I think.
Maybe add the peer id to the log locations as well?
Retracting ACK because I missed that |
Concept ACK. |
dbd1442
to
6d2f4d5
Compare
Thanks for quick feedback, all. I think the latest update should make everyone happy. |
I wrote:
I should have tested that, because it actually does print Maybe we should just stick to |
That said, it seems quite trivial to just change the default log level: Sjors@0ecb829 So far that's not generating noise for me. |
6d2f4d5
to
2c3a90f
Compare
I'm happy to do that and revert the revert if people will ACK. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK 2c3a90f
Prefer if you leave it like this and leave log level tweaks to a followup.
"Saw new header hash=%s height=%d", hash.ToString(), pindex->nHeight); | ||
|
||
if (ActiveChainstate().IsInitialBlockDownload()) { | ||
LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Debug, "%s\n", msg); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This creates a nice flood of messages when running with -debug=validation
right after our headers presync succeeds. But that's probably fine if someone is actively debugging IBD.
Optionally could just go for |
FWIW I plan to leave this as-is. |
Code review ACK 2c3a90f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK 2c3a90f
There were some great suggestions for how this could be improved, but I think it's smart to address them in a follow-up, considering this is useful as-is and addresses a real need.
const auto msg = strprintf( | ||
"Saw new header hash=%s height=%d", hash.ToString(), pindex->nHeight); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leaving this style nit in case someone ends up re-touching this in a follow-up, because this makes my eyes burn 😭
const auto msg = strprintf( | |
"Saw new header hash=%s height=%d", hash.ToString(), pindex->nHeight); | |
const auto msg = strprintf( | |
"Saw new header hash=%s height=%d", hash.ToString(), pindex->nHeight | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@josibake Our clang-format wouldn't agree. It would revert your diff to what was merged (and propose this change instead).
@@ -4224,7 +4224,7 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
if (received_new_header) {
LogPrintfCategory(BCLog::NET, "Saw new cmpctblock header hash=%s peer=%d\n",
- blockhash.ToString(), pfrom.GetId());
+ blockhash.ToString(), pfrom.GetId());
}
If this is something that we might want in the next released version of Core (24.1), then I think that's preferable. As we'd rather backport a less-involved patch. |
ACK 2c3a90f |
It triples them, the unconditional log output when we receive a header via compact block looks like this with this PR:
I'm concept ACK on adding unconditional logging, but why do there need to be two almost identical messages for this every time? |
@mzumsande this can be reduced to one, but requires some additional complexity: #27278 (comment) . Basically it involves handling the messages in net_processing rather than validation, but being careful not to introduce a log-spam DoS vector. |
2c3a90f log: on new valid header (James O'Beirne) e5ce857 log: net: new header over cmpctblock (James O'Beirne) Pull request description: Alternate to bitcoin#27276. Devs were [suprised to realize](https://twitter.com/jamesob/status/1637237917201383425) last night that we don't have definitive logging for when a given header was first received. This logs to the main stream when new headers are received outside of IBD, as well as when headers come in over cmpctblocks. The rationale of not hiding these under log categories is that they may be useful to have widely available when debugging strange network activity, and the marginal volume is modest. ACKs for top commit: dergoegge: Code review ACK 2c3a90f achow101: ACK 2c3a90f Sjors: tACK 2c3a90f josibake: ACK bitcoin@2c3a90f Tree-SHA512: 49fdcbe07799c8adc24143d7e5054a0c93fef120d2e9d5fddbd3b119550d895e2985be6ac10dd1825ea23a6fa5479c1b76d5518c136fbd983fa76c0d39dc354f
eb7cc9f Rename CalculateHeadersWork to CalculateClaimedHeadersWork (Greg Sanders) Pull request description: And clean up some comments. Confusion about what this is doing seems to be a running theme: #29549 (comment) #27278 (comment) ACKs for top commit: achow101: ACK eb7cc9f pablomartin4btc: ACK eb7cc9f 0xB10C: ACK eb7cc9f dergoegge: ACK eb7cc9f BrandonOdiwuor: ACK eb7cc9f Tree-SHA512: 6ccbc5e417155516487bb220753d189b5341dec05366db88a3fa5b1932eace21fbfaf23408c639bb54b36169a8d0a7536a1ee5e63b4ce5a3b70f2ff8407b6e07
Alternate to #27276.
Devs were suprised to realize last night that we don't have definitive logging for when a given header was first received.
This logs to the main stream when new headers are received outside of IBD, as well as when headers come in over cmpctblocks. The rationale of not hiding these under log categories is that they may be useful to have widely available when debugging strange network activity, and the marginal volume is modest.