Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ in order.
### Cache

In order to avoid rebuilding all dependencies for each build, the binaries are
cached and re-used when possible. Changes in the dependency-generator will
cached and reused when possible. Changes in the dependency-generator will
trigger cache-invalidation and rebuilds as necessary.
2 changes: 1 addition & 1 deletion depends/description.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ etc), and as well as a hash of the same data for each recursive dependency. If
any portion of a package's build recipe changes, it will be rebuilt as well as
any other package that depends on it. If any of the main makefiles (Makefile,
funcs.mk, etc) are changed, all packages will be rebuilt. After building, the
results are cached into a tarball that can be re-used and distributed.
results are cached into a tarball that can be reused and distributed.

### Package build results are (relatively) deterministic.

Expand Down
45 changes: 43 additions & 2 deletions doc/developer-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,47 @@ General Dash Core
- *Explanation*: If the test suite is to be updated for a change, this has to
be done first.

Logging
-------

The macros `LogInfo`, `LogDebug`, `LogTrace`, `LogWarning` and `LogError` are available for
logging messages. They should be used as follows:

- `LogDebug(BCLog::CATEGORY, fmt, params...)` is what you want
most of the time, and it should be used for log messages that are
useful for debugging and can reasonably be enabled on a production
system (that has sufficient free storage space). They will be logged
if the program is started with `-debug=category` or `-debug=1`.
Note that `LogPrint(BCLog::CATEGORY, fmt, params...)` is a deprecated
alias for `LogDebug`.

- `LogInfo(fmt, params...)` should only be used rarely, e.g. for startup
messages or for infrequent and important events such as a new block tip
being found or a new outbound connection being made. These log messages
are unconditional, so care must be taken that they can't be used by an
attacker to fill up storage. Note that `LogPrintf(fmt, params...)` is
a deprecated alias for `LogInfo`.

- `LogError(fmt, params...)` should be used in place of `LogInfo` for
severe problems that require the node (or a subsystem) to shut down
entirely (e.g., insufficient storage space).

- `LogWarning(fmt, params...)` should be used in place of `LogInfo` for
severe problems that the node admin should address, but are not
severe enough to warrant shutting down the node (e.g., system time
appears to be wrong, unknown soft fork appears to have activated).

- `LogTrace(BCLog::CATEGORY, fmt, params...)` should be used in place of
`LogDebug` for log messages that would be unusable on a production
system, e.g. due to being too noisy in normal use, or too resource
intensive to process. These will be logged if the startup
options `-debug=category -loglevel=category:trace` or `-debug=1
-loglevel=trace` are selected.

Note that the format strings and parameters of `LogDebug` and `LogTrace`
are only evaluated if the logging category is enabled, so you must be
careful to avoid side-effects in those expressions.

Wallet
-------

Expand Down Expand Up @@ -899,7 +940,7 @@ Strings and formatting
`wcstoll`, `wcstombs`, `wcstoul`, `wcstoull`, `wcstoumax`, `wcswidth`,
`wcsxfrm`, `wctob`, `wctomb`, `wctrans`, `wctype`, `wcwidth`, `wprintf`

- For `strprintf`, `LogPrint`, `LogPrintf` formatting characters don't need size specifiers.
- For `strprintf`, `LogInfo`, `LogDebug`, etc formatting characters don't need size specifiers.

- *Rationale*: Dash Core uses tinyformat, which is type safe. Leave them out to avoid confusion.

Expand All @@ -911,7 +952,7 @@ Strings and formatting

- *Rationale*: Although this is guaranteed to be safe starting with C++11, `.data()` communicates the intent better.

- Do not use it when passing strings to `tfm::format`, `strprintf`, `LogPrint[f]`.
- Do not use it when passing strings to `tfm::format`, `strprintf`, `LogInfo`, `LogDebug`, etc.

- *Rationale*: This is redundant. Tinyformat handles strings.

Expand Down
43 changes: 16 additions & 27 deletions src/banman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ BanMan::~BanMan()

void BanMan::LoadBanlist()
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);

if (m_client_interface) m_client_interface->InitMessage(_("Loading banlist…").translated);

Expand All @@ -51,16 +51,17 @@ void BanMan::DumpBanlist()

banmap_t banmap;
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
SweepBanned();
if (!BannedSetIsDirty()) return;
if (!m_is_dirty) return;
banmap = m_banned;
SetBannedSetDirty(false);
m_is_dirty = false;
}

const auto start{SteadyClock::now()};
if (!m_ban_db.Write(banmap)) {
SetBannedSetDirty(true);
LOCK(m_banned_mutex);
m_is_dirty = true;
}

LogPrint(BCLog::NET, "Flushed %d banned node addresses/subnets to disk %dms\n", banmap.size(),
Expand All @@ -70,7 +71,7 @@ void BanMan::DumpBanlist()
void BanMan::ClearBanned()
{
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
m_banned.clear();
m_is_dirty = true;
}
Expand All @@ -81,7 +82,7 @@ void BanMan::ClearBanned()
void BanMan::ClearDiscouraged()
{
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
m_discouraged.reset();
m_is_dirty = true;
}
Expand All @@ -90,14 +91,14 @@ void BanMan::ClearDiscouraged()

bool BanMan::IsDiscouraged(const CNetAddr& net_addr)
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
return m_discouraged.contains(net_addr.GetAddrBytes());
}

bool BanMan::IsBanned(const CNetAddr& net_addr)
{
auto current_time = GetTime();
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
for (const auto& it : m_banned) {
CSubNet sub_net = it.first;
CBanEntry ban_entry = it.second;
Expand All @@ -112,7 +113,7 @@ bool BanMan::IsBanned(const CNetAddr& net_addr)
bool BanMan::IsBanned(const CSubNet& sub_net)
{
auto current_time = GetTime();
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
banmap_t::iterator i = m_banned.find(sub_net);
if (i != m_banned.end()) {
CBanEntry ban_entry = (*i).second;
Expand All @@ -131,7 +132,7 @@ void BanMan::Ban(const CNetAddr& net_addr, int64_t ban_time_offset, bool since_u

void BanMan::Discourage(const CNetAddr& net_addr)
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
m_discouraged.insert(net_addr.GetAddrBytes());
}

Expand All @@ -148,7 +149,7 @@ void BanMan::Ban(const CSubNet& sub_net, int64_t ban_time_offset, bool since_uni
ban_entry.nBanUntil = (normalized_since_unix_epoch ? 0 : GetTime()) + normalized_ban_time_offset;

{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
if (m_banned[sub_net].nBanUntil < ban_entry.nBanUntil) {
m_banned[sub_net] = ban_entry;
m_is_dirty = true;
Expand All @@ -170,7 +171,7 @@ bool BanMan::Unban(const CNetAddr& net_addr)
bool BanMan::Unban(const CSubNet& sub_net)
{
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
if (m_banned.erase(sub_net) == 0) return false;
m_is_dirty = true;
}
Expand All @@ -181,15 +182,15 @@ bool BanMan::Unban(const CSubNet& sub_net)

void BanMan::GetBanned(banmap_t& banmap)
{
LOCK(m_cs_banned);
LOCK(m_banned_mutex);
// Sweep the banlist so expired bans are not returned
SweepBanned();
banmap = m_banned; //create a thread safe copy
}

void BanMan::SweepBanned()
{
AssertLockHeld(m_cs_banned);
AssertLockHeld(m_banned_mutex);

int64_t now = GetTime();
bool notify_ui = false;
Expand All @@ -212,15 +213,3 @@ void BanMan::SweepBanned()
m_client_interface->BannedListChanged();
}
}

bool BanMan::BannedSetIsDirty()
{
LOCK(m_cs_banned);
return m_is_dirty;
}

void BanMan::SetBannedSetDirty(bool dirty)
{
LOCK(m_cs_banned); //reuse m_banned lock for the m_is_dirty flag
m_is_dirty = dirty;
}
39 changes: 18 additions & 21 deletions src/banman.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,41 +60,38 @@ class BanMan
public:
~BanMan();
BanMan(fs::path ban_file, CClientUIInterface* client_interface, int64_t default_ban_time);
void Ban(const CNetAddr& net_addr, int64_t ban_time_offset = 0, bool since_unix_epoch = false);
void Ban(const CSubNet& sub_net, int64_t ban_time_offset = 0, bool since_unix_epoch = false);
void Discourage(const CNetAddr& net_addr);
void ClearBanned();
void ClearDiscouraged();
void Ban(const CNetAddr& net_addr, int64_t ban_time_offset = 0, bool since_unix_epoch = false) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
void Ban(const CSubNet& sub_net, int64_t ban_time_offset = 0, bool since_unix_epoch = false) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
void Discourage(const CNetAddr& net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
void ClearBanned() EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
void ClearDiscouraged() EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);

//! Return whether net_addr is banned
bool IsBanned(const CNetAddr& net_addr);
bool IsBanned(const CNetAddr& net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);

//! Return whether sub_net is exactly banned
bool IsBanned(const CSubNet& sub_net);
bool IsBanned(const CSubNet& sub_net) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);

//! Return whether net_addr is discouraged.
bool IsDiscouraged(const CNetAddr& net_addr);
bool IsDiscouraged(const CNetAddr& net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);

bool Unban(const CNetAddr& net_addr);
bool Unban(const CSubNet& sub_net);
void GetBanned(banmap_t& banmap);
void DumpBanlist();
bool Unban(const CNetAddr& net_addr) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
bool Unban(const CSubNet& sub_net) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
void GetBanned(banmap_t& banmap) EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
void DumpBanlist() EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);

private:
void LoadBanlist() EXCLUSIVE_LOCKS_REQUIRED(!m_cs_banned);
bool BannedSetIsDirty();
//!set the "dirty" flag for the banlist
void SetBannedSetDirty(bool dirty = true);
void LoadBanlist() EXCLUSIVE_LOCKS_REQUIRED(!m_banned_mutex);
//!clean unused entries (if bantime has expired)
void SweepBanned() EXCLUSIVE_LOCKS_REQUIRED(m_cs_banned);
void SweepBanned() EXCLUSIVE_LOCKS_REQUIRED(m_banned_mutex);

RecursiveMutex m_cs_banned;
banmap_t m_banned GUARDED_BY(m_cs_banned);
bool m_is_dirty GUARDED_BY(m_cs_banned){false};
Mutex m_banned_mutex;
banmap_t m_banned GUARDED_BY(m_banned_mutex);
bool m_is_dirty GUARDED_BY(m_banned_mutex){false};
CClientUIInterface* m_client_interface = nullptr;
CBanDB m_ban_db;
const int64_t m_default_ban_time;
CRollingBloomFilter m_discouraged GUARDED_BY(m_cs_banned) {50000, 0.000001};
CRollingBloomFilter m_discouraged GUARDED_BY(m_banned_mutex) {50000, 0.000001};
};

#endif // BITCOIN_BANMAN_H
5 changes: 2 additions & 3 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ bool InitHTTPServer()
workQueueDepthExternal = std::max((long)gArgs.GetIntArg("-rpcexternalworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
g_external_usernames = SplitString(rpc_externaluser, ',');
}
LogPrintfCategory(BCLog::HTTP, "creating work queue of depth %d external_depth %d\n", workQueueDepth, workQueueDepthExternal);
LogDebug(BCLog::HTTP, "creating work queue of depth %d external_depth %d\n", workQueueDepth, workQueueDepthExternal);
g_work_queue = std::make_unique<WorkQueue<HTTPClosure>>(workQueueDepth, workQueueDepthExternal);
// transfer ownership to eventBase/HTTP via .release()
eventBase = base_ctr.release();
Expand All @@ -459,9 +459,8 @@ static std::vector<std::thread> g_thread_http_workers;

void StartHTTPServer()
{
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
int rpcThreads = std::max((long)gArgs.GetIntArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
LogPrintfCategory(BCLog::HTTP, "starting %d worker threads\n", rpcThreads);
LogInfo("Starting HTTP server with %d worker threads\n", rpcThreads);
g_thread_http = std::thread(ThreadHTTP, eventBase);

for (int i = 0; i < rpcThreads; i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
uiInterface.InitMessage(_("Verifying blocks…").translated);
auto check_blocks = args.GetIntArg("-checkblocks", DEFAULT_CHECKBLOCKS);
if (chainman.m_blockman.m_have_pruned && check_blocks > MIN_BLOCKS_TO_KEEP) {
LogPrintfCategory(BCLog::PRUNE, "pruned datadir may not have more than %d blocks; only checking available blocks\n",
LogWarning("pruned datadir may not have more than %d blocks; only checking available blocks\n",
MIN_BLOCKS_TO_KEEP);
}
maybe_verify_error = VerifyLoadedChainstate(chainman,
Expand Down
2 changes: 2 additions & 0 deletions src/init/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void AddLoggingArgs(ArgsManager& argsman)
argsman.AddArg("-logthreadnames", strprintf("Prepend debug output with name of the originating thread (only available on platforms supporting thread_local) (default: %u)", DEFAULT_LOGTHREADNAMES), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
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);
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("-loglevelalways", strprintf("Always prepend a category and level (default: %u)", DEFAULT_LOGLEVELALWAYS), ArgsManager::ALLOW_ANY, 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);
}
Expand All @@ -83,6 +84,7 @@ void SetLoggingOptions(const ArgsManager& args)
LogInstance().m_log_time_micros = args.GetBoolArg("-logtimemicros", DEFAULT_LOGTIMEMICROS);
LogInstance().m_log_threadnames = args.GetBoolArg("-logthreadnames", DEFAULT_LOGTHREADNAMES);
LogInstance().m_log_sourcelocations = args.GetBoolArg("-logsourcelocations", DEFAULT_LOGSOURCELOCATIONS);
LogInstance().m_always_print_category_level = args.GetBoolArg("-loglevelalways", DEFAULT_LOGLEVELALWAYS);

fLogIPs = args.GetBoolArg("-logips", DEFAULT_LOGIPS);
}
Expand Down
Loading
Loading