Skip to content

Conversation

@jonatack
Copy link
Member

@jonatack jonatack commented Sep 12, 2021

The -checkblockindex configuration option performs occasional consistency checks of the block tree, chainstate, and other validation data structures.

There is currently no logging of the checks to see when they happen and their duration.

This patch:

  • adds a BLOCK logging category, as the validation category is high-frequency
  • logs the CChainState::CheckBlockIndex() consistency checks and duration

Example (on signet, while catching up to chain tip):

$ ./src/bitcoind -signet -checkaddrman=10 -debug=lock -debug=block
...
2021-09-12T13:03:18Z [msghand] CheckBlockIndex: consistency checks started
2021-09-12T13:03:18Z [opencon] Enter: lock contention cs_main, net_processing.cpp:1152 started
2021-09-12T13:03:18Z [msghand] CheckBlockIndex: consistency checks completed (433.58ms)
2021-09-12T13:03:18Z [msghand] CheckBlockIndex: consistency checks started
2021-09-12T13:03:19Z [msghand] CheckBlockIndex: consistency checks completed (411.67ms)
2021-09-12T13:03:19Z [opencon] Enter: lock contention cs_main, net_processing.cpp:1152 completed (811929μs)

To test:

$ ./src/bitcoind -debug=block

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 12, 2021

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23235 (Reduce unnecessary default logging by ajtowns)

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

@klementtan klementtan left a comment

Choose a reason for hiding this comment

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

Code review and tested ACK 572cf0dd547b69580b7796d2192617ab4a318a5f

2021-09-13T07:01:58Z CheckBlockIndex: consistency checks started
2021-09-13T07:01:58Z CheckBlockIndex: consistency checks completed (63.12ms)
2021-09-13T07:01:58Z CheckBlockIndex: consistency checks started
2021-09-13T07:01:58Z Enter: lock contention ::cs_main, validation.cpp:4876 started
2021-09-13T07:01:58Z CheckBlockIndex: consistency checks completed (57.97ms)

src/logging.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

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

Is there a guideline on which log category to use within validation? There is BENCH used for benchmarking validation. There is VALIDATION used for storage and validation. Now there is BLOCK used for CheckBlockIndex.

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I know of. I published a doc at https://github.com/jonatack/bitcoin-development/blob/master/logging.md#log-categories that is an updated version of this Bitcoin Stack Exchange answer in 2017 by @achow101 and am considering adding it to the RPC logging help.

Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to not re-use the BENCH or VALIDATION category? Seems overkill to introduce a new category for a single log line that is mostly only enabled for devs/debugging.

Copy link
Member Author

@jonatack jonatack Sep 22, 2021

Choose a reason for hiding this comment

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

We did that for instance with MEMPOOLREJ (1 line), QT (1 line), LOCK (1 line), PROXY (1 line), RAND (2 lines), COINDB (3 lines) and CMPCTBLOCK (3 lines), among others.

My thought was that VALIDATION is too busy and BENCH would be ok but seems not directly related to consistency checks (rename it?) We could also rename CMPCTBLOCK to BLOCK and add it to that group.

Copy link
Member

Choose a reason for hiding this comment

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

I think a BLOCK category makes sense in the sense that "block storage" is separate from "validation". We have a separate label for it too. If it is planned to be used for other messages too.

On the other hand this particular functionality is already enabled with a special option (-checkblockindex), so for this specifically I'm not sure also adding a separate category makes sense.

RAND (2 lines)

I think this one should go into a more general UTIL category at some point.

QT (1 line)

One line that captures everything from Qt's internal logging system 😄

Copy link
Member Author

@jonatack jonatack Sep 29, 2021

Choose a reason for hiding this comment

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

I think a BLOCK category makes sense in the sense that "block storage" is separate from "validation". We have a separate label for it too. If it is planned to be used for other messages too.

On the other hand this particular functionality is already enabled with a special option (-checkblockindex), so for this specifically I'm not sure also adding a separate category makes sense.

Right. It doesn't seem ideal to use BCLog::VALIDATION or BCLog::BENCH, and LogPrintf would require bitcoind to be restarted to turn off the -checkblockindex config option. Maybe rename the low-frequency BCLog::CMPCTBLOCK category to BCLog::BLOCK and use that, but it would be a bit more disruptive than the current proposal.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like #23235 did some of the clean-ups here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like #23235 did some of the clean-ups here?

Looked at it, but that change looks like it needs cleaning up and given how this simple change couldn't go through, I didn't attempt it.

@jonatack jonatack force-pushed the CheckBlockIndex-logging branch from 572cf0d to dfca02e Compare October 5, 2021 10:01
@jonatack
Copy link
Member Author

jonatack commented Oct 5, 2021

Rebased following the merge of #20487, which added the UTIL logging category.

@DrahtBot
Copy link
Contributor

🐙 This pull request conflicts with the target branch and needs rebase.

Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft".

@laanwj
Copy link
Member

laanwj commented Nov 12, 2021

Code review ACK (but unfortunately needs rebase again)

@DrahtBot
Copy link
Contributor

There hasn't been much activity lately and the patch still needs rebase. What is the status here?
  • Is it still relevant? ➡️ Please solve the conflicts to make it ready for review and to ensure the CI passes.
  • Is it no longer relevant? ➡️ Please close.
  • Did the author lose interest or time to work on this? ➡️ Please close it and mark it 'Up for grabs' with the label, so that it can be picked up in the future.

@fanquake
Copy link
Member

What is the status of this?

@maflcko
Copy link
Member

maflcko commented May 25, 2022

Closing due to several months of inactivity for a "simple" logging change. Feel free to reopen this or open a new pull request.

@maflcko maflcko closed this May 25, 2022
@jonatack
Copy link
Member Author

Indeed, I thought it would be simple but no agreement on which logging category to use.

@bitcoin bitcoin locked and limited conversation to collaborators May 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants