elements/src/init
Niklas Gögge d23b6c86d0 [log] Introduce log rate limiter class
The LogRatelimiter class implements a fixed window rate limiter. The
rate limiter allows a fixed amount of bytes to be consumed within a
fixed time window.

[log] Introduce source location type

The SourceLocation type stores the filename and line of a source code
location.
In a later commit we use this type as the key type in an unordered map
and set to keep track of rate limters for each location.

[config] Add -ratelimitlogging config option

The -ratelimitlogging can be used to enable/disable the rate limiting to
disk. Rate limiting is enabled by default.

[log] Add two new categories for unconditional logging

We create two new categories `UNCONDITIONAL_ALWAYS` and
`UNCONDITIONAL_RATE_LIMITED` that are always enabled by default.

LogPrintf now logs using the `UNCONDITIONAL_RATE_LIMITED` category which
will start to apply rate limiting in a later commit.

For some log locations it might be safe to allow more frequent logging
without rate limiting. These locations should use the
`UNCONDITIONAL_ALWAYS` category.

[validation] Exempt UpdateTipLog from rate limiting

UpdateTipLog logs everytime a new tip is activated. This occurs at an
increased frequency during IBD and should therefore be exempt from rate
limiting.

[log] Add rate limiting to LogPrintf

To mitigate disk filling attacks caused by unsafe usages of LogPrintf,
we rate limit LogPrintf by using the fixed window rate limiter
(BCLog::LogRatelimiter) introduced in an earlier commit.

The rate limiting logic is applied per source location instead of
globally. A source location is allowed to log up to 1 MiB per hour.
Source locations that violate the limit will have their logs supressed
for up to one hour.

[test util] Mark ~DebugLogHelper as noexcept(false)

We mark ~DebugLogHelper as noexcept(false) to be able to catch the
exception it throws. This lets us use it in test in combination with
BOOST_CHECK_THROW and BOOST_CHECK_NO_THROW to check that certain log
messages are (not) logged.

[test] Check for expected log rate limiting messages

[test] Test for expected file size changes when rate limiting is enabled

[test] Check that log rate limiting is disabled for exempt source locations

[test] Check that rate limiting can be disabled
2025-11-24 13:36:23 +00:00
..
bitcoin-gui.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
bitcoin-node.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
bitcoin-qt.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
bitcoin-wallet.cpp multiprocess: Add new bitcoin-gui, bitcoin-qt, bitcoin-wallet init implementations 2021-09-16 13:17:01 -05:00
bitcoind.cpp Add src/node/* code to node:: namespace 2022-01-06 22:14:16 -05:00
common.cpp [log] Introduce log rate limiter class 2025-11-24 13:36:23 +00:00
common.h Move common package version code to init/common 2021-04-19 06:11:38 -04:00