As MarcoFalke noted in #19995 ("Mitigate disk filling attacks by temporarily rate limiting LogPrintf(…)"):
I'd prefer if unconditional logs were only used for the init/shutdown sequence and local system errors, such as data corruption. Anything else the average user probably doesn't care about, and if they did, they could enable the corresponding debug category and provide enough disk space for the debug log file.
And in #19832 (comment):
Generally, it should be possible to run Bitcoin Core with well-defined resource usage in an unsupervised setting. Ideally, the resource usage depends on command line settings and user behaviour, not on remote peer (mis)behaviour. And with "unsupervised" I mean that the users doesn't check the debug log unless there is a local software malfunction or other issue that needs manual debugging.
I agree that we use too much unconditional logging.
It is bad for two reasons:
- From a security perspective unnecessary unconditional logging risks open up for disk fill attacks.
- From a usability perspective unnecessary unconditional logging risks burying important log messages (anomalies) in logs about mundane expected stuff (non-anomalies).
I suggest gradually making non-critical unconditional logging conditional (opt-in via -debug) to reduce risk of disk fill attacks and to improve user experience.
More concretely that would mean changing from LogPrintf("…\n"); to LogPrint(DEBUG_CATEGORY, "…\n");.
Some candidates for changing from unconditional to conditional debug logging:
src/flatfile.cpp: LogPrintf("Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
src/net.cpp: LogPrintf("socket send error %s\n", NetworkErrorString(nErr));
src/net.cpp: LogPrintf("socket sending timeout: %is\n", nTime - pnode->nLastSend);
src/net.cpp: LogPrintf("socket receive timeout: %is\n", nTime - pnode->nLastRecv);
src/net.cpp: LogPrintf("ping timeout: %fs\n", 0.000001 * count_microseconds(GetTime<std::chrono::microseconds>() - pnode->m_ping_start.load()));
src/validation.cpp: LogPrintf("Leaving block file %i: %s\n", nLastBlockFile, vinfoBlockFile[nLastBlockFile].ToString());
These are (AFAICT) either a.) peer triggerable (edit: in low volume at least) or b.) uninteresting from a user perspective :)
Getting rid of the cases above as a start would significantly reduce the amount of log spam when in steady state (non-IBD).