Skip to content
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

Move log messages: tx enqueue to mempool, allocation to blockstorage #27277

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Sjors
Copy link
Member

@Sjors Sjors commented Mar 19, 2023

When running with -debug=validation the log is filled with:

2023-03-19T12:46:01Z [validation] Enqueuing TransactionAddedToMempool: txid=37c8e1ef87d75a67fbaf44e116018fbc70d9c4ef0e27e2ae56861395101f9b8e wtxid=24e2d76012f9cde451d085ead4feab136feddae6cb55d37221a81aac6c0eaf42
2023-03-19T12:46:01Z [validation] TransactionAddedToMempool: txid=37c8e1ef87d75a67fbaf44e116018fbc70d9c4ef0e27e2ae56861395101f9b8e wtxid=24e2d76012f9cde451d085ead4feab136feddae6cb55d37221a81aac6c0eaf42

These log entries are more appropriate for -debug=mempool.

This change limits -debug=validation to messages that are related to blocks and headers. It also downgrades Enqueuing messages to the Trace level.

It makes it easier to run for a long time without excessive log file growth. This debug category is particularly useful for keeping track of problematic headers that were seen, the timing of reorgs, see also #27276.

Since this PR touches validationinterface.cpp anyway, it also includes a commit to drop function names from log messages, since we now have -logsourcelocations.

Similarly, though less important, I moved [validation] Pre-allocating up to position 0x… in rev….dat messages to blockstorage. This reduces the number of [validation] log messages further. to 3 per (normal) block.

The volume of log messages could also have been reduced by changing the log level of these messages to trace. Doing so would prevent a whack-a-mole game of moving log messages to different categories. However in this case I think the change in log category would be justified even if it didn't have a big impact on noise. I.e. someone running with -debug=mempool would expect to see the TransactionAddedToMempool messages and someone running with -debug=blockstorage would perhaps be surprised to not see the Pre-allocating message.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 19, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
Approach ACK ajtowns

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:

  • #29538 (refactor: Improve naming of CBlock::GetHash() -> GetHeaderHash() by fjahr)
  • #29256 (Improve new LogDebug/Trace/Info/Warning/Error Macros by ryanofsky)
  • #28960 (kernel: Remove dependency on CScheduler by TheCharlatan)

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 Sjors force-pushed the 2022/03/log-tx-validation branch from cb37465 to f2c7d95 Compare March 19, 2023 13:41
@Sjors
Copy link
Member Author

Sjors commented Mar 19, 2023

Still investigating the linter issue… (update: figured it out)

src/validationinterface.cpp: Expected 0 argument(s) after format string but found 1 argument(s): LogPrint(category, fmt "\n", __VA_ARGS__)

@Sjors Sjors force-pushed the 2022/03/log-tx-validation branch from f2c7d95 to 8de17cd Compare March 19, 2023 13:45
LOG_EVENT(fmt, local_name, __VA_ARGS__); \
event(); \
}); \
#define ENQUEUE_AND_LOG_EVENT(category, event, fmt, name, ...) \
Copy link
Member Author

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

Note: I don't know if there was any particular reason why the endline characters are vertically aligned (in #16688). If there's no reason, then it would be easier to move them all to the left.

cc @kczyz

@Sjors Sjors force-pushed the 2022/03/log-tx-validation branch from 8de17cd to 4eff439 Compare March 19, 2023 13:57
@Sjors Sjors changed the title Move tx enqueue messages to mempool log Move log messages: tx enqueue to mempool, allocation to blockstorage Mar 19, 2023
src/flatfile.cpp Outdated
@@ -66,7 +66,7 @@ size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_
if (CheckDiskSpace(m_dir, inc_size)) {
FILE *file = Open(pos);
if (file) {
LogPrint(BCLog::VALIDATION, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
LogPrint(BCLog::BLOCKSTORE, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative you could consider would be to use the trace log level, so this would be logged only if the trace loglevel is set with -loglevel, either globally or for this category.

Suggested change
LogPrint(BCLog::BLOCKSTORE, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
LogPrintLevel(BCLog::VALIDATION, BCLog::Level::Trace, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
$ ./src/bitcoind -help-debug | grep -A10 loglevel
  -loglevel=<level>|<category>:<level>
       Set the global or per-category severity level for logging categories
       enabled with the -debug configuration option or the logging RPC:
       info, debug, trace (default=debug); warning and error levels are
       always logged. If <category>:<level> is supplied, the setting
       will override the global one and may be specified multiple times
       to set multiple category-specific levels. <category> can be:
       addrman, bench, blockstorage, cmpctblock, coindb, estimatefee,
       http, i2p, ipc, leveldb, libevent, lock, mempool, mempoolrej,
       net, proxy, prune, qt, rand, reindex, rpc, scan, selectcoins,
       tor, txreconciliation, util, validation, walletdb, zmq.

Copy link
Contributor

Choose a reason for hiding this comment

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

(Just changing the category might only shift verbose logging from one place to another. The idea of the log levels is to allow more granular control over detail).

from src/logging.h

    enum class Level {
        Trace = 0, // High-volume or detailed logging for development/debugging
        Debug,     // Reasonably noisy logging, but still usable in production
        Info,      // Default
        Warning,
        Error,

Copy link
Member Author

Choose a reason for hiding this comment

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

I think blockstorage is correct place for this in any case. E.g. it also logs Leaving block file. I don't know if it makes sense to reduce the log level.

Copy link
Member Author

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

Looking at the history of the BLOCKSTORE category, it was introduced as part of a larger change in #23235 to reduce the default log noise. There was no discussion about this particular line, and my guess is that it was overlooked. cc @ajtowns

Copy link
Contributor

@jonatack jonatack Mar 19, 2023

Choose a reason for hiding this comment

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

The info level is logged by default if -debug=on for the category (as well as the debug level, for now during the transition period) and it would ease the review burden to use the new macros instead of the ones that will have to be updated. You may be right about BLOCKSTORE being a better place.

Copy link
Member Author

Choose a reason for hiding this comment

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

(added a note to the PR description)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll look into switching to the LogPrintLevel function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the history of the BLOCKSTORE category, it was introduced as part of a larger change in #23235 to reduce the default log noise. There was no discussion about this particular line, and my guess is that it was overlooked. cc @ajtowns

That sounds right

@Sjors Sjors force-pushed the 2022/03/log-tx-validation branch from d562077 to 7417743 Compare March 19, 2023 15:21
@maflcko
Copy link
Member

maflcko commented Mar 20, 2023

CI network error https://cirrus-ci.com/task/4864754720702464?logs=ci#L61:

TimeoutError: [Errno 110] Connection timed out

@0xB10C
Copy link
Contributor

0xB10C commented Apr 1, 2023

CI network error https://cirrus-ci.com/task/4864754720702464?logs=ci#L61:

TimeoutError: [Errno 110] Connection timed out

Note: The failed connections seems to be to the launchpad.net PPA with a newer bpfcc. Not using this newer PPA to install an up-to-date bpfcc causes warnings printed to stderr which means interface_usdt_coinselection.py is treated as failed. (The up-coming Ubuntu lunar seems to include an up-to-date bpfcc).

@ajtowns
Copy link
Contributor

ajtowns commented Aug 21, 2023

Approach ACK

@Sjors
Copy link
Member Author

Sjors commented Aug 21, 2023

Rebased after #27632 (a trivial, but silent, conflict, I noticed it while trying to rebase when @DrahtBot asked).

src/flatfile.cpp Outdated
@@ -66,7 +66,7 @@ size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_
if (CheckDiskSpace(m_dir, inc_size)) {
FILE *file = Open(pos);
if (file) {
LogPrint(BCLog::VALIDATION, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
LogPrintLevel(BCLog::BLOCKSTORAGE, BCLog::Level::Info, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this upgraded from Level::Debug to Level::Info ? That makes this logging unconditional?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's more complicated. WillLogCategoryLevel logs >= BCLog::Level::Warning for any category. For Info it first checks if the category is selected, which is only the case if the user set -debug=blockstorage.

Only if the category is set, it looks at category-specific log levels (-loglevel), and defaults to DEFAULT_LOG_LEVEL, which is currently Debug (but I vaguely recall the idea was the raise that to Info).

So this should not cause logging by default. I could still set the level to Debug but perhaps that's better reserver for even lower level block storage stuff, if we ever add that. And indeed it didn't when I briefly tested it .

Copy link
Contributor

Choose a reason for hiding this comment

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

We have Trace available for "even lower level" stuff (currently used by the wallet for sql logging). The only Info logging we currently do with a category is for libevent EVENT_LOG_MSG, which I don't think is even used in the parts of libevent we actually use. I don't think this change makes sense, but that's probably mostly thinking that the logging api we have at the moment is confusing... (cf #28318)

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to Debug

@ajtowns
Copy link
Contributor

ajtowns commented Aug 29, 2023

This reduces the number of [validation] log messages to 3 per (normal) block.

I'm seeing 6 validation logs via validationinterface.cpp: NewPoWValidBlock, BlockChecked, BlockConnected (enqueued and executed), UpdatedBlockTip (enqueued and executed). I think that's with default settings.

There's also "Saw new header", "Saw new cmpctblock header" and "UpdateTip", but those aren't [validation] log messages (they're not categorised and don't require -debug=validation), but if you're only seeing those, you already weren't seeing the "Pre-allocating..." messages...

#define LOG_EVENT(fmt, ...) \
LogPrint(BCLog::VALIDATION, fmt "\n", __VA_ARGS__)
#define LOG_EVENT(category, level, fmt, ...) \
LogPrintLevel(category, level, fmt "\n", __VA_ARGS__)
Copy link
Contributor

Choose a reason for hiding this comment

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

There's not really any need for a separate LOG_EVENT macro anymore -- all it saves now is adding a newline.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got rid of it.

@@ -198,7 +197,7 @@ void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockInd
auto event = [pindexNew, pindexFork, fInitialDownload, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload); });
};
ENQUEUE_AND_LOG_EVENT(event, "%s: new block hash=%s fork block hash=%s (in IBD=%s)", __func__,
ENQUEUE_AND_LOG_EVENT(BCLog::VALIDATION, BCLog::Level::Info, event, "new block hash=%s fork block hash=%s (in IBD=%s)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Also seems pointless to upgrade these to Info... If anything, these seem more appropriate to downgrade to Trace logging (the "Enqueuing" particularly).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll switch these to Debug and downgrade the Enqueuing wrapper to trace.

LOG_EVENT(fmt, local_name, __VA_ARGS__); \
event(); \
}); \
#define ENQUEUE_AND_LOG_EVENT(category, level, event, fmt, ...) \
Copy link
Contributor

Choose a reason for hiding this comment

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

No real need to include the level as a param, I think. Hardcoding it would make things a bit less noisy.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR always sets level to Debug, so we don't need it here. But then any later tweak in log levels would have to edit this macro again.

@Sjors
Copy link
Member Author

Sjors commented Aug 30, 2023

Dropping the function name (by default) made some of these messages ambiguous so I clarified them a bit in the second commit.

@@ -246,17 +242,17 @@ void CMainSignals::ChainStateFlushed(const CBlockLocator &locator) {
auto event = [locator, this] {
m_internals->Iterate([&](CValidationInterface& callbacks) { callbacks.ChainStateFlushed(locator); });
};
ENQUEUE_AND_LOG_EVENT(event, "%s: block hash=%s", __func__,
ENQUEUE_AND_LOG_EVENT(BCLog::VALIDATION, BCLog::Level::Debug, event, "chainstate flushed block hash=%s",
Copy link
Member Author

Choose a reason for hiding this comment

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

As an aside, this gets called 5-10 times for some blocks, zero times for most blocks.

@Sjors
Copy link
Member Author

Sjors commented Dec 4, 2023

Rebased after #28368.

@Sjors
Copy link
Member Author

Sjors commented Feb 13, 2024

Rebased and switched LogPrintLevel(...Debug) to LogDebug(...)

#define ENQUEUE_AND_LOG_EVENT(category, level, event, fmt, name, ...) \
do { \
auto local_name = (name); \
LogTrace(category, "Enqueuing " fmt "\n", local_name, __VA_ARGS__); \
Copy link
Member

Choose a reason for hiding this comment

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

e67ccf0: How is this a refactor? You are changing the behavior from debug to trace, no?

Also, I am not sure about this change. This makes intermittent test failures harder to debug, since trace is disabled. Also, below Debug is still used, so this drops only one of two log lines.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed this should be LogDebug() in order to not change behavior.

The downgrade to trace should be in a different commit. Will look into this again.

This makes intermittent test failures harder to debug, since trace is disabled.

I'll look into what level to use. Lots of things have changed over the past few rebases.

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 the trace level was always disabled, unless explicitly enabled? But I haven't double checked this.

@DrahtBot
Copy link
Contributor

DrahtBot commented Mar 9, 2024

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants