mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-17 13:07:54 +02:00
[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
This commit is contained in:
parent
817c68a64f
commit
d23b6c86d0
9 changed files with 362 additions and 50 deletions
|
|
@ -76,6 +76,7 @@ void AddLoggingArgs(ArgsManager& argsman)
|
|||
argsman.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -daemon. To disable logging to file, set -nodebuglogfile)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
||||
argsman.AddArg("-ratelimitlogging", strprintf("Rate limit unconditional logging to disk (default: %u)", DEFAULT_RATELIMITLOGGING), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
||||
}
|
||||
|
||||
void SetLoggingOptions(const ArgsManager& args)
|
||||
|
|
@ -89,6 +90,7 @@ void SetLoggingOptions(const ArgsManager& args)
|
|||
LogInstance().m_log_threadnames = args.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
|
||||
#endif
|
||||
LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS);
|
||||
LogInstance().m_ratelimit = args.GetBoolArg("-ratelimitlogging", DEFAULT_RATELIMITLOGGING);
|
||||
|
||||
fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue