From 7f687fd696b589326789ca3a5a47b8acc245e351 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Thu, 15 Sep 2016 10:50:16 +0400 Subject: [PATCH] spork debug log: (#1016) - add "spork" debug category - move "seen" and "unknown" to new "spork" debug category to reduce log spam - new/updated/seen messages should not overlap --- src/init.cpp | 2 +- src/rpcmisc.cpp | 2 +- src/spork.cpp | 36 ++++++++++++++++++++---------------- src/util.cpp | 1 + 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index f6fbd2fa46..edb7559cd5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -517,7 +517,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-limitdescendantsize=", strprintf("Do not accept transactions if any ancestor would have more than kilobytes of in-mempool descendants (default: %u).", DEFAULT_DESCENDANT_SIZE_LIMIT)); } string debugCategories = "addrman, alert, bench, coindb, db, lock, rand, rpc, selectcoins, mempool, mempoolrej, net, proxy, prune, http, libevent, tor, zmq, " - "dash (or specifically: privatesend, instantsend, masternode, keepass, mnpayments, gobject)"; // Don't translate these and qt below + "dash (or specifically: privatesend, instantsend, masternode, spork, keepass, mnpayments, gobject)"; // Don't translate these and qt below if (mode == HMM_BITCOIN_QT) debugCategories += ", qt"; strUsage += HelpMessageOpt("-debug=", strprintf(_("Output debugging information (default: %u, supplying is optional)"), 0) + ". " + diff --git a/src/rpcmisc.cpp b/src/rpcmisc.cpp index fd8af9e53f..ef1fb7934f 100644 --- a/src/rpcmisc.cpp +++ b/src/rpcmisc.cpp @@ -121,7 +121,7 @@ UniValue debug(const UniValue& params, bool fHelp) throw runtime_error( "debug ( 0|1|addrman|alert|bench|coindb|db|lock|rand|rpc|selectcoins|mempool" "|mempoolrej|net|proxy|prune|http|libevent|tor|zmq|" - "dash|privatesend|instantsend|masternode|keepass|mnpayments|gobject )\n" + "dash|privatesend|instantsend|masternode|spork|keepass|mnpayments|gobject )\n" "Change debug category on the fly. Specify single category or use comma to specify many.\n" "\nExamples:\n" + HelpExampleCli("debug", "dash") diff --git a/src/spork.cpp b/src/spork.cpp index face9f91b5..0560a148c5 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -21,25 +21,29 @@ void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStr if (strCommand == NetMsgType::SPORK) { - // LogPrintf("CSporkManager::ProcessSpork\n"); CDataStream vMsg(vRecv); CSporkMessage spork; vRecv >> spork; - LOCK(cs_main); - if(chainActive.Tip() == NULL) return; - uint256 hash = spork.GetHash(); - if(mapSporksActive.count(spork.nSporkID)) { - if (mapSporksActive[spork.nSporkID].nTimeSigned >= spork.nTimeSigned) { - if(fDebug) LogPrintf("CSporkManager::ProcessSpork -- seen %s block %d\n", hash.ToString(), chainActive.Tip()->nHeight); - return; - } else { - if(fDebug) LogPrintf("CSporkManager::ProcessSpork -- got updated spork %s block %d\n", hash.ToString(), chainActive.Tip()->nHeight); - } + + std::string strLogMsg; + { + LOCK(cs_main); + if(!chainActive.Tip()) return; + strLogMsg = strprintf("SPORK -- hash: %s id: %d value: %10d bestHeight: %d peer=%d", hash.ToString(), spork.nSporkID, spork.nValue, chainActive.Height(), pfrom->id); } - LogPrintf("spork -- hash: %s id: %d value: %10d bestHeight: %d new\n", hash.ToString(), spork.nSporkID, spork.nValue, chainActive.Tip()->nHeight); + if(mapSporksActive.count(spork.nSporkID)) { + if (mapSporksActive[spork.nSporkID].nTimeSigned >= spork.nTimeSigned) { + LogPrint("spork", "%s seen\n", strLogMsg); + return; + } else { + LogPrintf("%s updated\n", strLogMsg); + } + } else { + LogPrintf("%s new\n", strLogMsg); + } if(!spork.CheckSignature()) { LogPrintf("CSporkManager::ProcessSpork -- invalid signature\n"); @@ -109,7 +113,7 @@ bool CSporkManager::IsSporkActive(int nSporkID) case SPORK_12_RECONSIDER_BLOCKS: r = SPORK_12_RECONSIDER_BLOCKS_DEFAULT; break; case SPORK_13_OLD_SUPERBLOCK_FLAG: r = SPORK_13_OLD_SUPERBLOCK_FLAG_DEFAULT; break; default: - LogPrintf("CSporkManager::IsSporkActive -- Unknown Spork %d\n", nSporkID); + LogPrint("spork", "CSporkManager::IsSporkActive -- Unknown Spork ID %d\n", nSporkID); r = 4070908800; // 2099-1-1 i.e. off by default break; } @@ -134,7 +138,7 @@ int64_t CSporkManager::GetSporkValue(int nSporkID) case SPORK_12_RECONSIDER_BLOCKS: return SPORK_12_RECONSIDER_BLOCKS_DEFAULT; case SPORK_13_OLD_SUPERBLOCK_FLAG: return SPORK_13_OLD_SUPERBLOCK_FLAG_DEFAULT; default: - LogPrintf("CSporkManager::GetSporkValue -- Unknown Spork ID %d\n", nSporkID); + LogPrint("spork", "CSporkManager::GetSporkValue -- Unknown Spork ID %d\n", nSporkID); return -1; } @@ -151,7 +155,7 @@ int CSporkManager::GetSporkIDByName(std::string strName) if (strName == "SPORK_12_RECONSIDER_BLOCKS") return SPORK_12_RECONSIDER_BLOCKS; if (strName == "SPORK_13_OLD_SUPERBLOCK_FLAG") return SPORK_13_OLD_SUPERBLOCK_FLAG; - LogPrintf("CSporkManager::GetSporkIDByName -- Unknown Spork name '%s'\n", strName); + LogPrint("spork", "CSporkManager::GetSporkIDByName -- Unknown Spork name '%s'\n", strName); return -1; } @@ -167,7 +171,7 @@ std::string CSporkManager::GetSporkNameByID(int nSporkID) case SPORK_12_RECONSIDER_BLOCKS: return "SPORK_12_RECONSIDER_BLOCKS"; case SPORK_13_OLD_SUPERBLOCK_FLAG: return "SPORK_13_OLD_SUPERBLOCK_FLAG"; default: - LogPrintf("CSporkManager::GetSporkNameByID -- Unknown Spork ID %d\n", nSporkID); + LogPrint("spork", "CSporkManager::GetSporkNameByID -- Unknown Spork ID %d\n", nSporkID); return "Unknown"; } } diff --git a/src/util.cpp b/src/util.cpp index 11bdf98a12..d43e9258bd 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -278,6 +278,7 @@ bool LogAcceptCategory(const char* category) ptrCategory->insert(string("privatesend")); ptrCategory->insert(string("instantsend")); ptrCategory->insert(string("masternode")); + ptrCategory->insert(string("spork")); ptrCategory->insert(string("keepass")); ptrCategory->insert(string("mnpayments")); ptrCategory->insert(string("gobject"));