Skip to content

Commit 206f590

Browse files
Crypt-iQfanquake
authored andcommitted
config: add DEBUG_ONLY -logratelimit
Use -nologratelimit by default in functional tests if the bitcoind version supports it. Co-Authored-By: stickies-v <[email protected]> Github-Pull: #33011 Rebased-From: 5c74a0b
1 parent dfdd407 commit 206f590

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/init.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,10 +1384,14 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
13841384
}
13851385
}, std::chrono::minutes{5});
13861386

1387-
LogInstance().SetRateLimiting(BCLog::LogRateLimiter::Create(
1388-
[&scheduler](auto func, auto window) { scheduler.scheduleEvery(std::move(func), window); },
1389-
BCLog::RATELIMIT_MAX_BYTES,
1390-
BCLog::RATELIMIT_WINDOW));
1387+
if (args.GetBoolArg("-logratelimit", BCLog::DEFAULT_LOGRATELIMIT)) {
1388+
LogInstance().SetRateLimiting(BCLog::LogRateLimiter::Create(
1389+
[&scheduler](auto func, auto window) { scheduler.scheduleEvery(std::move(func), window); },
1390+
BCLog::RATELIMIT_MAX_BYTES,
1391+
BCLog::RATELIMIT_WINDOW));
1392+
} else {
1393+
LogInfo("Log rate limiting disabled");
1394+
}
13911395

13921396
assert(!node.validation_signals);
13931397
node.validation_signals = std::make_unique<ValidationSignals>(std::make_unique<SerialTaskRunner>(scheduler));

src/init/common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ void AddLoggingArgs(ArgsManager& argsman)
3838
argsman.AddArg("-logsourcelocations", strprintf("Prepend debug output with name of the originating source location (source file, line number and function name) (default: %u)", DEFAULT_LOGSOURCELOCATIONS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
3939
argsman.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
4040
argsman.AddArg("-loglevelalways", strprintf("Always prepend a category and level (default: %u)", DEFAULT_LOGLEVELALWAYS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
41+
argsman.AddArg("-logratelimit", strprintf("Apply rate limiting to unconditional logging to mitigate disk-filling attacks (default: %u)", BCLog::DEFAULT_LOGRATELIMIT), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
4142
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);
4243
argsman.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
4344
}

src/logging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ namespace BCLog {
107107
constexpr size_t DEFAULT_MAX_LOG_BUFFER{1'000'000}; // buffer up to 1MB of log data prior to StartLogging
108108
constexpr uint64_t RATELIMIT_MAX_BYTES{1024 * 1024}; // maximum number of bytes per source location that can be logged within the RATELIMIT_WINDOW
109109
constexpr auto RATELIMIT_WINDOW{1h}; // time window after which log ratelimit stats are reset
110+
constexpr bool DEFAULT_LOGRATELIMIT{true};
110111

111112
//! Fixed window rate limiter for logging.
112113
class LogRateLimiter

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def __init__(self, i, datadir_path, *, chain, rpchost, timewait, timeout_factor,
137137
self.args.append("-logsourcelocations")
138138
if self.version_is_at_least(239000):
139139
self.args.append("-loglevel=trace")
140+
if self.version_is_at_least(299900):
141+
self.args.append("-nologratelimit")
140142

141143
# Default behavior from global -v2transport flag is added to args to persist it over restarts.
142144
# May be overwritten in individual tests, using extra_args.

0 commit comments

Comments
 (0)