Commit graph

10 commits

Author SHA1 Message Date
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
fanquake
eca159c305
refactor: remove unneeded calls to strprintf() 2021-12-14 10:09:42 +08:00
Russell Yanofsky
6544ea5035 refactor: Block unsafe fs::path std::string conversion calls
There is no change in behavior. This just helps prepare for the
transition from boost::filesystem to std::filesystem by avoiding calls
to methods which will be unsafe after the transaction to std::filesystem
to due lack of a boost::filesystem::path::imbue equivalent and inability
to set a predictable locale.

Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
Co-authored-by: Kiminuo <kiminuo@protonmail.com>
Co-authored-by: MarcoFalke <falke.marco@gmail.com>
2021-10-05 11:10:47 -04:00
Kiminuo
4c3a5dcbfc scripted-diff: Replace GetDataDir() calls with gArgs.GetDataDirNet() calls
-BEGIN VERIFY SCRIPT-
git ls-files -- 'src' ':(exclude)src/util/system.h' ':(exclude)src/util/system.cpp' | xargs sed -i 's/GetDataDir()/gArgs.GetDataDirNet()/g';
-END VERIFY SCRIPT-
2021-05-24 10:29:58 +02:00
Russell Yanofsky
615965cfd1 Move common package version code to init/common 2021-04-19 06:11:38 -04:00
Russell Yanofsky
5bed2ab42c Move common logging start code to init/common 2021-04-19 06:11:38 -04:00
Russell Yanofsky
1fb7fcfa52 Move common logging GetArgs code to init/common 2021-04-19 06:11:38 -04:00
Russell Yanofsky
90469c1690 Move common logging AddArg code to init/common 2021-04-19 06:11:38 -04:00
Russell Yanofsky
387c4cf588 Move common sanity check code to init/common 2021-04-19 06:11:38 -04:00
Russell Yanofsky
a67b54855b Move common global init code to init/common 2021-04-19 06:11:38 -04:00