Skip to content

Conversation

jamesob
Copy link
Contributor

@jamesob jamesob commented Mar 19, 2023

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 19, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK Sjors, dergoegge, josibake, achow101
Concept ACK darosior

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26969 (net, refactor: net_processing, add ProcessCompactBlockTxns by brunoerg)

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.

@Sjors
Copy link
Member

Sjors commented Mar 19, 2023

The second commit 8828f03 (compact blocks) is useful regardless of whether this PR or #27276 makes it in. I'll let you rebase it in the latter case, because if I were to cherry-pick it, it would make my PR less trivial to review :-)

@jamesob jamesob force-pushed the 2023-03-log-new-headers branch 2 times, most recently from babe8ac to 75ee0d4 Compare March 19, 2023 14:44
Copy link
Member

@Sjors Sjors 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

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

@@ -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());
Copy link
Member

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.

Copy link
Member

@Sjors Sjors Mar 19, 2023

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 :-(

Copy link
Contributor

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?

Copy link
Member

@Sjors Sjors Mar 20, 2023

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

@dergoegge dergoegge 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

Prefer this over #27276 as well I think.

Maybe add the peer id to the log locations as well?

@Sjors
Copy link
Member

Sjors commented Mar 20, 2023

Retracting ACK because I missed that CalculateHeadersWork doesn't check the work, see #27278 (comment)

@darosior
Copy link
Member

Concept ACK.

@jamesob jamesob force-pushed the 2023-03-log-new-headers branch from dbd1442 to 6d2f4d5 Compare March 20, 2023 12:40
@jamesob
Copy link
Contributor Author

jamesob commented Mar 20, 2023

Thanks for quick feedback, all. I think the latest update should make everyone happy.

@Sjors
Copy link
Member

Sjors commented Mar 20, 2023

I wrote:

using warning for now seems fine, since we don't actually print the word "warning" in the log.

I should have tested that, because it actually does print [validation:warning] in the log.

Maybe we should just stick to fprintf and change the TODO to say this should be validation level info once LogPrintf prints those by default.

@Sjors
Copy link
Member

Sjors commented Mar 20, 2023

That said, it seems quite trivial to just change the default log level: Sjors@0ecb829

So far that's not generating noise for me.

@jamesob jamesob force-pushed the 2023-03-log-new-headers branch from 6d2f4d5 to 2c3a90f Compare March 20, 2023 17:05
@jamesob
Copy link
Contributor Author

jamesob commented Mar 20, 2023

That said, it seems quite trivial to just change the default log level: Sjors@0ecb829

So far that's not generating noise for me.

I'm happy to do that and revert the revert if people will ACK.

Copy link
Member

@Sjors Sjors left a 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);
Copy link
Member

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.

@jonatack
Copy link
Member

jonatack commented Mar 20, 2023

I should have tested that, because it actually does print [validation:warning] in the log.

Maybe we should just stick to fprintf and change the TODO to say this should be validation level info once LogPrintf prints those by default.

Optionally could just go for info, unless it has to be unconditionally logged asap in which case maybe pull in 118c756. Making info unconditionally logged is near the top of the next steps in the parent PR #25203 i.e. 118c756 (@Sjors, your version doesn't update the docs). Until then, -debug=validation or enabling the validation category with the logging RPC will print it as well.

@jamesob
Copy link
Contributor Author

jamesob commented Mar 21, 2023

FWIW I plan to leave this as-is.

@dergoegge
Copy link
Member

Code review ACK 2c3a90f

Copy link
Member

@josibake josibake left a 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.

Comment on lines +3843 to +3844
const auto msg = strprintf(
"Saw new header hash=%s height=%d", hash.ToString(), pindex->nHeight);
Copy link
Member

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 😭

Suggested change
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
);

Copy link
Member

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());
         }

@fanquake
Copy link
Member

FWIW I plan to leave this as-is.

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.

@achow101
Copy link
Member

ACK 2c3a90f

@achow101 achow101 merged commit 664500f into bitcoin:master Mar 21, 2023
@mzumsande
Copy link
Contributor

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.

It triples them, the unconditional log output when we receive a header via compact block looks like this with this PR:

2023-03-21T17:10:55Z Saw new header hash=0000000000000000000198c04342dff96f7940111d874c7bc73730a33b268225 height=781829
2023-03-21T17:10:55Z [net] Saw new cmpctblock header hash=0000000000000000000198c04342dff96f7940111d874c7bc73730a33b268225 peer=12
2023-03-21T17:10:55Z UpdateTip: new best=0000000000000000000198c04342dff96f7940111d874c7bc73730a33b268225 height=781829 version=0x20a00000 log2_work=94.071477 tx=816272773 date='2023-03-21T17:10:10Z' progress=1.000000 cache=48.5MiB(24209txo)

I'm concept ACK on adding unconditional logging, but why do there need to be two almost identical messages for this every time?

@Sjors
Copy link
Member

Sjors commented Mar 21, 2023

@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.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 21, 2023
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
achow101 added a commit that referenced this pull request Mar 9, 2024
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
@bitcoin bitcoin locked and limited conversation to collaborators Mar 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.