Skip to content

Commit

Permalink
Contains dashification. disables -debug dash
Browse files Browse the repository at this point in the history
Merge bitcoin#9424: Change LogAcceptCategory to use uint32_t rather than sets of strings.

6b3bb3d Change LogAcceptCategory to use uint32_t rather than sets of strings. (Gregory Maxwell)

Tree-SHA512: ebb5bcf9a7d00a32dd1390b727ff4d29330a038423611da01268d8e1d2c0229e52a1098e751d4e6db73ef4ae862e1e96d38249883fcaf12b68f55ebb01035b34
Signed-off-by: Pasta <Pasta@dash.org>

# Conflicts:
#	src/httpserver.cpp
#	src/init.cpp
#	src/net.cpp
#	src/net_processing.cpp
#	src/policy/fees.cpp
#	src/txdb.cpp
#	src/util.cpp
#	src/util.h
#	src/validation.cpp
#	src/wallet/rpcwallet.cpp
#	src/wallet/wallet.cpp
#	src/zmq/zmqpublishnotifier.cpp
  • Loading branch information
PastaPastaPasta committed May 12, 2019
1 parent a173e68 commit a3cbf2c
Show file tree
Hide file tree
Showing 30 changed files with 397 additions and 297 deletions.
2 changes: 1 addition & 1 deletion src/addrman.cpp
Expand Up @@ -248,7 +248,7 @@ void CAddrMan::Good_(const CService& addr, int64_t nTime)
if (nUBucket == -1)
return;

LogPrint("addrman", "Moving %s to tried\n", addr.ToString());
LogPrint(BCLog::ADDRMAN, "Moving %s to tried\n", addr.ToString());

// move nId to the tried tables
MakeTried(info, nId);
Expand Down
12 changes: 7 additions & 5 deletions src/addrman.h
Expand Up @@ -445,7 +445,7 @@ class CAddrMan
}
}
if (nLost + nLostUnk > 0) {
LogPrint("addrman", "addrman lost %i new and %i tried addresses due to collisions\n", nLostUnk, nLost);
LogPrint(BCLog::ADDRMAN, "addrman lost %i new and %i tried addresses due to collisions\n", nLostUnk, nLost);
}

Check();
Expand Down Expand Up @@ -511,8 +511,9 @@ class CAddrMan
Check();
fRet |= Add_(addr, source, nTimePenalty);
Check();
if (fRet)
LogPrint("addrman", "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
if (fRet) {
LogPrint(BCLog::ADDRMAN, "Added %s from %s: %i tried, %i new\n", addr.ToStringIPPort(), source.ToString(), nTried, nNew);
}
return fRet;
}

Expand All @@ -525,8 +526,9 @@ class CAddrMan
for (std::vector<CAddress>::const_iterator it = vAddr.begin(); it != vAddr.end(); it++)
nAdd += Add_(*it, source, nTimePenalty) ? 1 : 0;
Check();
if (nAdd)
LogPrint("addrman", "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
if (nAdd) {
LogPrint(BCLog::ADDRMAN, "Added %i addresses from %s: %i tried, %i new\n", nAdd, source.ToString(), nTried, nNew);
}
return nAdd > 0;
}

Expand Down
9 changes: 5 additions & 4 deletions src/blockencodings.cpp
Expand Up @@ -164,7 +164,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
break;
}

LogPrint("cmpctblock", "Initialized PartiallyDownloadedBlock for block %s using a cmpctblock of size %lu\n", cmpctblock.header.GetHash().ToString(), GetSerializeSize(cmpctblock, SER_NETWORK, PROTOCOL_VERSION));
LogPrint(BCLog::CMPCTBLOCK, "Initialized PartiallyDownloadedBlock for block %s using a cmpctblock of size %lu\n", cmpctblock.header.GetHash().ToString(), GetSerializeSize(cmpctblock, SER_NETWORK, PROTOCOL_VERSION));

return READ_STATUS_OK;
}
Expand Down Expand Up @@ -209,10 +209,11 @@ ReadStatus PartiallyDownloadedBlock::FillBlock(CBlock& block, const std::vector<
return READ_STATUS_CHECKBLOCK_FAILED;
}

LogPrint("cmpctblock", "Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool (incl at least %lu from extra pool) and %lu txn requested\n", hash.ToString(), prefilled_count, mempool_count, extra_count, vtx_missing.size());
LogPrint(BCLog::CMPCTBLOCK, "Successfully reconstructed block %s with %lu txn prefilled, %lu txn from mempool (incl at least %lu from extra pool) and %lu txn requested\n", hash.ToString(), prefilled_count, mempool_count, extra_count, vtx_missing.size());
if (vtx_missing.size() < 5) {
for (const auto& tx : vtx_missing)
LogPrint("cmpctblock", "Reconstructed block %s required tx %s\n", hash.ToString(), tx->GetHash().ToString());
for (const auto& tx : vtx_missing) {
LogPrint(BCLog::CMPCTBLOCK, "Reconstructed block %s required tx %s\n", hash.ToString(), tx->GetHash().ToString());
}
}

return READ_STATUS_OK;
Expand Down
3 changes: 2 additions & 1 deletion src/dbwrapper.cpp
Expand Up @@ -21,8 +21,9 @@ class CBitcoinLevelDBLogger : public leveldb::Logger {
// This code is adapted from posix_logger.h, which is why it is using vsprintf.
// Please do not do this in normal code
virtual void Logv(const char * format, va_list ap) override {
if (!LogAcceptCategory("leveldb"))
if (!LogAcceptCategory(BCLog::LEVELDB)) {
return;
}
char buffer[500];
for (int iter = 0; iter < 2; iter++) {
char* base;
Expand Down
6 changes: 3 additions & 3 deletions src/httprpc.cpp
Expand Up @@ -233,7 +233,7 @@ static bool InitRPCAuthentication()

bool StartHTTPRPC()
{
LogPrint("rpc", "Starting HTTP RPC server\n");
LogPrint(BCLog::RPC, "Starting HTTP RPC server\n");
if (!InitRPCAuthentication())
return false;

Expand All @@ -247,12 +247,12 @@ bool StartHTTPRPC()

void InterruptHTTPRPC()
{
LogPrint("rpc", "Interrupting HTTP RPC server\n");
LogPrint(BCLog::RPC, "Interrupting HTTP RPC server\n");
}

void StopHTTPRPC()
{
LogPrint("rpc", "Stopping HTTP RPC server\n");
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n");
UnregisterHTTPHandler("/", true);
if (httpRPCTimerInterface) {
RPCUnsetTimerInterface(httpRPCTimerInterface);
Expand Down
39 changes: 20 additions & 19 deletions src/httpserver.cpp
Expand Up @@ -221,7 +221,7 @@ static bool InitHTTPAllowList()
std::string strAllowed;
for (const CSubNet& subnet : rpc_allow_subnets)
strAllowed += subnet.ToString() + " ";
LogPrint("http", "Allowing HTTP connections from: %s\n", strAllowed);
LogPrint(BCLog::HTTP, "Allowing HTTP connections from: %s\n", strAllowed);
return true;
}

Expand Down Expand Up @@ -251,7 +251,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
{
std::unique_ptr<HTTPRequest> hreq(new HTTPRequest(req));

LogPrint("http", "Received a %s request for %s from %s\n",
LogPrint(BCLog::HTTP, "Received a %s request for %s from %s\n",
RequestMethodString(hreq->GetRequestMethod()), hreq->GetURI(), hreq->GetPeer().ToString());

// Early address-based allow check
Expand Down Expand Up @@ -301,18 +301,18 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
/** Callback to reject HTTP requests after shutdown. */
static void http_reject_request_cb(struct evhttp_request* req, void*)
{
LogPrint("http", "Rejecting request while shutting down\n");
LogPrint(BCLog::HTTP, "Rejecting request while shutting down\n");
evhttp_send_error(req, HTTP_SERVUNAVAIL, NULL);
}

/** Event dispatcher thread */
static bool ThreadHTTP(struct event_base* base, struct evhttp* http)
{
RenameThread("dash-http");
LogPrint("http", "Entering http event loop\n");
LogPrint(BCLog::HTTP, "Entering http event loop\n");
event_base_dispatch(base);
// Event loop will be interrupted by InterruptHTTPServer()
LogPrint("http", "Exited http event loop\n");
LogPrint(BCLog::HTTP, "Exited http event loop\n");
return event_base_got_break(base) == 0;
}

Expand Down Expand Up @@ -344,7 +344,7 @@ static bool HTTPBindAddresses(struct evhttp* http)

// Bind addresses
for (std::vector<std::pair<std::string, uint16_t> >::iterator i = endpoints.begin(); i != endpoints.end(); ++i) {
LogPrint("http", "Binding RPC on address %s port %i\n", i->first, i->second);
LogPrint(BCLog::HTTP, "Binding RPC on address %s port %i\n", i->first, i->second);
evhttp_bound_socket *bind_handle = evhttp_bind_socket_with_handle(http, i->first.empty() ? NULL : i->first.c_str(), i->second);
if (bind_handle) {
boundSockets.push_back(bind_handle);
Expand Down Expand Up @@ -373,7 +373,7 @@ static void libevent_log_cb(int severity, const char *msg)
LogPrintf("libevent: %s\n", msg);
// The below code causes log spam on Travis and the output of these logs has never been of any use so far
//else
// LogPrint("libevent", "libevent: %s\n", msg);
// LogPrint(BCLog::LIBEVENT, "libevent: %s\n", msg);
}

bool InitHTTPServer()
Expand All @@ -396,10 +396,11 @@ bool InitHTTPServer()
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
// If -debug=libevent, set full libevent debugging.
// Otherwise, disable all libevent debugging.
if (LogAcceptCategory("libevent"))
if (LogAcceptCategory(BCLog::LIBEVENT)) {
event_enable_debug_logging(EVENT_DBG_ALL);
else
} else {
event_enable_debug_logging(EVENT_DBG_NONE);
}
#endif
#ifdef WIN32
evthread_use_windows_threads();
Expand Down Expand Up @@ -433,7 +434,7 @@ bool InitHTTPServer()
return false;
}

LogPrint("http", "Initialized HTTP server\n");
LogPrint(BCLog::HTTP, "Initialized HTTP server\n");
int workQueueDepth = std::max((long)GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
LogPrintf("HTTP: creating work queue of depth %d\n", workQueueDepth);

Expand All @@ -448,7 +449,7 @@ std::future<bool> threadResult;

bool StartHTTPServer()
{
LogPrint("http", "Starting HTTP server\n");
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
int rpcThreads = std::max((long)GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
std::packaged_task<bool(event_base*, evhttp*)> task(ThreadHTTP);
Expand All @@ -464,7 +465,7 @@ bool StartHTTPServer()

void InterruptHTTPServer()
{
LogPrint("http", "Interrupting HTTP server\n");
LogPrint(BCLog::HTTP, "Interrupting HTTP server\n");
if (eventHTTP) {
// Unlisten sockets
for (evhttp_bound_socket *socket : boundSockets) {
Expand All @@ -479,19 +480,19 @@ void InterruptHTTPServer()

void StopHTTPServer()
{
LogPrint("http", "Stopping HTTP server\n");
LogPrint(BCLog::HTTP, "Stopping HTTP server\n");
if (workQueue) {
LogPrint("http", "Waiting for HTTP worker threads to exit\n");
LogPrint(BCLog::HTTP, "Waiting for HTTP worker threads to exit\n");
#ifndef WIN32
// ToDo: Disabling WaitExit() for Windows platforms is an ugly workaround for the wallet not
// closing during a repair-restart. It doesn't hurt, though, because threadHTTP.timed_join
// below takes care of this and sends a loopbreak.
workQueue->WaitExit();
#endif
#endif
delete workQueue;
}
if (eventBase) {
LogPrint("http", "Waiting for HTTP event thread to exit\n");
LogPrint(BCLog::HTTP, "Waiting for HTTP event thread to exit\n");
// Give event loop a few seconds to exit (to send back last RPC responses), then break it
// Before this was solved with event_base_loopexit, but that didn't work as expected in
// at least libevent 2.0.21 and always introduced a delay. In libevent
Expand All @@ -512,7 +513,7 @@ void StopHTTPServer()
event_base_free(eventBase);
eventBase = 0;
}
LogPrint("http", "Stopped HTTP server\n");
LogPrint(BCLog::HTTP, "Stopped HTTP server\n");
}

struct event_base* EventBase()
Expand Down Expand Up @@ -659,7 +660,7 @@ HTTPRequest::RequestMethod HTTPRequest::GetRequestMethod()

void RegisterHTTPHandler(const std::string &prefix, bool exactMatch, const HTTPRequestHandler &handler)
{
LogPrint("http", "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
LogPrint(BCLog::HTTP, "Registering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
pathHandlers.push_back(HTTPPathHandler(prefix, exactMatch, handler));
}

Expand All @@ -672,7 +673,7 @@ void UnregisterHTTPHandler(const std::string &prefix, bool exactMatch)
break;
if (i != iend)
{
LogPrint("http", "Unregistering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
LogPrint(BCLog::HTTP, "Unregistering HTTP handler for %s (exactmatch %d)\n", prefix, exactMatch);
pathHandlers.erase(i);
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/init.cpp
Expand Up @@ -407,7 +407,7 @@ void OnRPCStopped()
uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange);
RPCNotifyBlockChange(false, nullptr);
cvBlockChange.notify_all();
LogPrint("rpc", "RPC stopped.\n");
LogPrint(BCLog::RPC, "RPC stopped.\n");
}

void OnRPCPreCommand(const CRPCCommand& cmd)
Expand Down Expand Up @@ -553,10 +553,8 @@ std::string HelpMessage(HelpMessageMode mode)
}
std::string debugCategories = "addrman, alert, bench, cmpctblock, coindb, db, http, leveldb, libevent, lock, mempool, mempoolrej, net, proxy, prune, rand, reindex, rpc, selectcoins, tor, zmq, "
"dash (or specifically: chainlocks, gobject, instantsend, keepass, llmq, llmq-dkg, llmq-sigs, masternode, mnpayments, mnsync, privatesend, spork)"; // Don't translate these and qt below
if (mode == HMM_BITCOIN_QT)
debugCategories += ", qt";
strUsage += HelpMessageOpt("-debug=<category>", strprintf(_("Output debugging information (default: %u, supplying <category> is optional)"), 0) + ". " +
_("If <category> is not supplied or if <category> = 1, output all debugging information.") + _("<category> can be:") + " " + debugCategories + ".");
_("If <category> is not supplied or if <category> = 1, output all debugging information.") + " " + _("<category> can be:") + " " + ListLogCategories() + ".");
if (showDebug)
strUsage += HelpMessageOpt("-nodebug", "Turn off debugging messages, same as -debug=0");
strUsage += HelpMessageOpt("-help-debug", _("Show all debugging options (usage: --help -help-debug)"));
Expand Down Expand Up @@ -1132,12 +1130,19 @@ bool AppInitParameterInteraction()

// ********************************************************* Step 3: parameter-to-internal-flags

fDebug = mapMultiArgs.count("-debug");
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
if (fDebug) {
if (mapMultiArgs.count("-debug") > 0) {
// Special-case: if -debug=0/-nodebug is set, turn off debugging messages
const std::vector<std::string>& categories = mapMultiArgs.at("-debug");
if (GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), std::string("0")) != categories.end())
fDebug = false;

if (!(GetBoolArg("-nodebug", false) || find(categories.begin(), categories.end(), std::string("0")) != categories.end())) {
for (const auto& cat : categories) {
uint32_t flag;
if (!GetLogCategory(&flag, &cat)) {
InitWarning(strprintf(_("Unsupported logging category %s.\n"), cat));
}
logCategories |= flag;
}
}
}

// Check for -debugnet
Expand Down Expand Up @@ -1459,7 +1464,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
#ifndef WIN32
CreatePidFile(GetPidFile(), getpid());
#endif
if (GetBoolArg("-shrinkdebugfile", !fDebug)) {
if (GetBoolArg("-shrinkdebugfile", logCategories != BCLog::NONE)) {
// Do this first since it both loads a bunch of debug.log into memory,
// and because this needs to happen before any other debug.log printing
ShrinkDebugFile();
Expand Down Expand Up @@ -1855,7 +1860,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
break;
}
} catch (const std::exception& e) {
if (fDebug) LogPrintf("%s\n", e.what());
LogPrintf("%s\n", e.what());
strLoadError = _("Error opening block database");
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/miner.cpp
Expand Up @@ -255,7 +255,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
}
int64_t nTime2 = GetTimeMicros();

LogPrint("bench", "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart));
LogPrint(BCLog::BENCH, "CreateNewBlock() packages: %.2fms (%d packages, %d updated descendants), validity: %.2fms (total %.2fms)\n", 0.001 * (nTime1 - nTimeStart), nPackagesSelected, nDescendantsUpdated, 0.001 * (nTime2 - nTime1), 0.001 * (nTime2 - nTimeStart));

return std::move(pblocktemplate);
}
Expand Down

0 comments on commit a3cbf2c

Please sign in to comment.