From b9b623c5391a3c08dc48db478c1db478f135e111 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 27 Mar 2022 10:44:51 -0400 Subject: [PATCH 1/7] Change the name of MRC tests from MRC to mrc_tests to stop linter complaint --- src/test/gridcoin/mrc_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/gridcoin/mrc_tests.cpp b/src/test/gridcoin/mrc_tests.cpp index 81841fcbde..4065ba982d 100644 --- a/src/test/gridcoin/mrc_tests.cpp +++ b/src/test/gridcoin/mrc_tests.cpp @@ -104,7 +104,7 @@ struct Setup { }; } // Anonymous namespace -BOOST_FIXTURE_TEST_SUITE(MRC, Setup) +BOOST_FIXTURE_TEST_SUITE(mrc_tests, Setup) BOOST_AUTO_TEST_CASE(it_properly_records_blocks) { From bbdd83bf869660a5ec49494c7c9d7ca8ad1788bb Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 27 Mar 2022 10:48:56 -0400 Subject: [PATCH 2/7] Add spelling exception to eliminate linter false positive on changelog --- test/lint/lint-spelling.ignore-words.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lint/lint-spelling.ignore-words.txt b/test/lint/lint-spelling.ignore-words.txt index 3577220a37..ff424c9537 100644 --- a/test/lint/lint-spelling.ignore-words.txt +++ b/test/lint/lint-spelling.ignore-words.txt @@ -22,3 +22,4 @@ fo dout nin inout +smoe From 71e99a7635f3dff1779f46386ed67a506da45b7c Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 27 Mar 2022 12:09:37 -0400 Subject: [PATCH 3/7] Eliminate the linter false positive on double include of QtPlugin in bitcoin.cpp --- src/qt/bitcoin.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index bd3a48c6a0..ce37f5c113 100755 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -41,10 +41,14 @@ #include #include +// This eliminates the linter false positive on double include of QtPlugin +#if (defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)) || defined(QT_STATICPLUGIN) +#include +#endif + #if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED) #define _BITCOIN_QT_PLUGINS_INCLUDED #define __INSURE__ -#include Q_IMPORT_PLUGIN(qcncodecs) Q_IMPORT_PLUGIN(qjpcodecs) Q_IMPORT_PLUGIN(qtwcodecs) @@ -53,7 +57,6 @@ Q_IMPORT_PLUGIN(qtaccessiblewidgets) #endif #if defined(QT_STATICPLUGIN) -#include #if defined(QT_QPA_PLATFORM_XCB) Q_IMPORT_PLUGIN(QXcbIntegrationPlugin); #elif defined(QT_QPA_PLATFORM_WINDOWS) From 2d87b6aa37d67844980c65e8d60a4820ccf74ba2 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 27 Mar 2022 12:56:28 -0400 Subject: [PATCH 4/7] Change tfm::format for no stream version to tfm::strformat The linter is confused by the overload of tfm::format to return a string instead of the first argument being a stream. Using a different function name solves the problem. --- src/gridcoin/scraper/http.cpp | 22 +++++++++++----------- src/gridcoin/scraper/scraper.cpp | 6 +++--- src/tinyformat.h | 8 ++++++++ test/lint/lint-format-strings.sh | 1 + 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/gridcoin/scraper/http.cpp b/src/gridcoin/scraper/http.cpp index de8707d81a..a70038e04f 100644 --- a/src/gridcoin/scraper/http.cpp +++ b/src/gridcoin/scraper/http.cpp @@ -210,7 +210,7 @@ void Http::Download( ScopedFile fp(fsbridge::fopen(destination, "wb"), &fclose); if (!fp) throw std::runtime_error( - tfm::format("Error opening target %s: %s (%d)", destination, strerror(errno), errno)); + tfm::strformat("Error opening target %s: %s (%d)", destination, strerror(errno), errno)); std::string buffer; ScopedCurl curl = GetContext(); @@ -221,7 +221,7 @@ void Http::Download( CURLcode res = curl_easy_perform(curl.get()); if (res > 0) - throw std::runtime_error(tfm::format("Failed to download file %s: %s", url, curl_easy_strerror(res))); + throw std::runtime_error(tfm::strformat("Failed to download file %s: %s", url, curl_easy_strerror(res))); } std::string Http::GetEtag( @@ -247,7 +247,7 @@ std::string Http::GetEtag( curl_slist_free_all(headers); if (res > 0) - throw std::runtime_error(tfm::format("Failed to get ETag for URL %s: %s", url, curl_easy_strerror(res))); + throw std::runtime_error(tfm::strformat("Failed to get ETag for URL %s: %s", url, curl_easy_strerror(res))); // Validate HTTP return code. long response_code; @@ -291,7 +291,7 @@ std::string Http::GetLatestVersionResponse() CURLcode res = curl_easy_perform(curl.get()); if (res > 0) - throw std::runtime_error(tfm::format("Failed to get version response from URL %s: %s", + throw std::runtime_error(tfm::strformat("Failed to get version response from URL %s: %s", url, curl_easy_strerror(res))); curl_slist_free_all(headers); @@ -320,7 +320,7 @@ void Http::DownloadSnapshot() DownloadStatus.SetSnapshotDownloadFailed(true); throw std::runtime_error( - tfm::format("Snapshot Downloader: Error opening target %s: %s (%d)", + tfm::strformat("Snapshot Downloader: Error opening target %s: %s (%d)", destination.string(), strerror(errno), errno)); } @@ -374,7 +374,7 @@ void Http::DownloadSnapshot() { DownloadStatus.SetSnapshotDownloadFailed(true); - throw std::runtime_error(tfm::format("Snapshot Downloader: Failed to download file %s: %s", + throw std::runtime_error(tfm::strformat("Snapshot Downloader: Failed to download file %s: %s", url, curl_easy_strerror(res))); } } @@ -458,13 +458,13 @@ void Http::EvaluateResponse(int code, const std::string& url) code == 308) return; else if (code == 400) - throw HttpException(tfm::format("Server returned a http code of Bad Request ", url, code)); + throw HttpException(tfm::strformat("Server returned a http code of Bad Request ", url, code)); else if (code == 401) - throw HttpException(tfm::format("Server returned a http code of Unauthorized ", url, code)); + throw HttpException(tfm::strformat("Server returned a http code of Unauthorized ", url, code)); else if (code == 403) - throw HttpException(tfm::format("Server returned a http code of Forbidden ", url, code)); + throw HttpException(tfm::strformat("Server returned a http code of Forbidden ", url, code)); else if (code == 404) - throw HttpException(tfm::format("Server returned a http code of Not Found ", url, code)); + throw HttpException(tfm::strformat("Server returned a http code of Not Found ", url, code)); - throw HttpException(tfm::format("Server returned a http code ", url, code)); + throw HttpException(tfm::strformat("Server returned a http code ", url, code)); } diff --git a/src/gridcoin/scraper/scraper.cpp b/src/gridcoin/scraper/scraper.cpp index 7e1162c92a..d882275a72 100755 --- a/src/gridcoin/scraper/scraper.cpp +++ b/src/gridcoin/scraper/scraper.cpp @@ -1014,7 +1014,7 @@ void _log(logattribute eType, const std::string& sCall, const std::string& sMess return; } - sOut = tfm::format("%s [%s] <%s> : %s", DateTimeStrFormat("%x %H:%M:%S", GetAdjustedTime()), sType, sCall, sMessage); + sOut = tfm::strformat("%s [%s] <%s> : %s", DateTimeStrFormat("%x %H:%M:%S", GetAdjustedTime()), sType, sCall, sMessage); // This snoops the SCRAPER category setting from the main logger, and uses it as a conditional for the scraper log output. // Logs will be posted to the scraper log when the category is set OR it is not an INFO level... (i.e. critical, warning, @@ -1320,7 +1320,7 @@ void ApplyCache(const std::string& key, T& result) } catch (const std::exception&) { - _log(logattribute::ERR, "ScraperApplyAppCacheEntries", tfm::format("Ignoring bad AppCache entry for %s.", key)); + _log(logattribute::ERR, "ScraperApplyAppCacheEntries", tfm::strformat("Ignoring bad AppCache entry for %s.", key)); } } @@ -2384,7 +2384,7 @@ EXCLUSIVE_LOCKS_REQUIRED(cs_TeamIDMap) if (!ParseInt64(sTeamID, &nTeamID)) { - _log(logattribute::ERR, __func__, tfm::format("Ignoring bad team id for team %s.", sTeamName)); + _log(logattribute::ERR, __func__, tfm::strformat("Ignoring bad team id for team %s.", sTeamName)); continue; } diff --git a/src/tinyformat.h b/src/tinyformat.h index 2fb4c3cedd..bad01ba038 100644 --- a/src/tinyformat.h +++ b/src/tinyformat.h @@ -1061,6 +1061,14 @@ std::string format(const std::string &fmt, const Args&... args) return oss.str(); } +// This is to make the linter happy because it the variadic script/python variadic checker does not deal with +// overloads. +template +std::string strformat(const std::string &fmt, const Args&... args) +{ + return format(fmt, args...); +} + } // namespace tinyformat /** Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for details) */ diff --git a/test/lint/lint-format-strings.sh b/test/lint/lint-format-strings.sh index 8427760e1e..cfe95f3883 100755 --- a/test/lint/lint-format-strings.sh +++ b/test/lint/lint-format-strings.sh @@ -14,6 +14,7 @@ FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS=( "FatalError,0" "fprintf,1" "tfm::format,1" # Assuming tfm::::format(std::ostream&, ... + "tfm::strformat,0" # Assuming tfm::::strformat(fmt, ... "LogConnectFailure,1" "LogPrint,1" "LogPrintf,0" From 0863ea31e20b1348d5b0821a83fa0ae45e7d5cc0 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 27 Mar 2022 13:18:21 -0400 Subject: [PATCH 5/7] Add LogPrint exception to lint-format-strings.py to silence linter false positive --- test/lint/lint-format-strings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/lint/lint-format-strings.py b/test/lint/lint-format-strings.py index c4bbd29c40..38da47fdfc 100755 --- a/test/lint/lint-format-strings.py +++ b/test/lint/lint-format-strings.py @@ -23,6 +23,7 @@ ("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(std::string fmt, Params... parameters)"), ("src/wallet/scriptpubkeyman.h", "LogPrintf((\"%s \" + fmt).c_str(), m_storage.GetDisplayName(), parameters...)"), ("src/logging.h", "LogPrintf(const char* fmt, const Args&... args)"), + ("src/logging.h", "LogPrint(Category category, const char* format, TINYFORMAT_VARARGS(n))"), ("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(const std::string& fmt, const Params&... parameters)"), ] From 02f167ebf309935002a26b027f809ae4c91c9851 Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 27 Mar 2022 13:28:33 -0400 Subject: [PATCH 6/7] Fix several LogPrint related variadic warnings from linter --- src/gridcoin/scraper/scraper_net.cpp | 8 ++--- src/main.cpp | 44 ++++++++++++++++------------ src/miner.cpp | 5 ++-- src/util/time.cpp | 8 ++--- 4 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/gridcoin/scraper/scraper_net.cpp b/src/gridcoin/scraper/scraper_net.cpp index f7d3cbb690..6509141de3 100644 --- a/src/gridcoin/scraper/scraper_net.cpp +++ b/src/gridcoin/scraper/scraper_net.cpp @@ -563,8 +563,8 @@ EXCLUSIVE_LOCKS_REQUIRED(CScraperManifest::cs_mapManifest) iter->second))); if (!iter2.second) { - LogPrint("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same " - "hash = %s, already exists. This should not happen.", __func__, nHash.GetHex()); + LogPrintf("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same " + "hash = %s, already exists. This should not happen.", __func__, nHash.GetHex()); } else { @@ -605,8 +605,8 @@ CScraperManifest::DeleteManifest(std::mapsecond))); if (!iter2.second) { - LogPrint("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same " - "hash = %s, already exists. This should not happen.", __func__, iter->first.GetHex()); + LogPrintf("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same " + "hash = %s, already exists. This should not happen.", __func__, iter->first.GetHex()); } else { diff --git a/src/main.cpp b/src/main.cpp index fc143c2cef..5c8522eba5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3260,36 +3260,44 @@ void PrintBlockTree() EXCLUSIVE_LOCKS_REQUIRED(cs_main) CBlockIndex* pindex = vStack.back().second; vStack.pop_back(); + std::stringstream output; + // print split or gap if (nCol > nPrevCol) { - for (int i = 0; i < nCol-1; i++) - LogPrintf("| "); - LogPrintf("|\\"); + for (int i = 0; i < nCol-1; i++) { + output << "| \n"; + } + + output << "|\\\n"; } else if (nCol < nPrevCol) { - for (int i = 0; i < nCol; i++) - LogPrintf("| "); - LogPrintf("|"); - } + for (int i = 0; i < nCol; i++) { + output << "| \n"; + } + + output << "|\n"; + } nPrevCol = nCol; // print columns - for (int i = 0; i < nCol; i++) - LogPrintf("| "); + for (int i = 0; i < nCol; i++) { + output << "| \n"; + } - // print item + // print item (and also prepend above formatting) CBlock block; ReadBlockFromDisk(block, pindex, Params().GetConsensus()); - LogPrintf("%d (%u,%u) %s %08x %s tx %" PRIszu "", - pindex->nHeight, - pindex->nFile, - pindex->nBlockPos, - block.GetHash(true).ToString().c_str(), - block.nBits, - DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(), - block.vtx.size()); + LogPrintf("%s%d (%u,%u) %s %08x %s tx %" PRIszu "", + output.str(), + pindex->nHeight, + pindex->nFile, + pindex->nBlockPos, + block.GetHash(true).ToString().c_str(), + block.nBits, + DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(), + block.vtx.size()); PrintWallets(block); diff --git a/src/miner.cpp b/src/miner.cpp index b893ed4151..310481ceb7 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -934,7 +934,8 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake if (dSumAllocation + iterSideStake->second > 1.0) { - LogPrintf("WARN: SplitCoinStakeOutput: allocation percentage over 100\%, ending sidestake allocations."); + LogPrintf("WARN: SplitCoinStakeOutput: allocation percentage over 100 percent, " + "ending sidestake allocations."); break; } @@ -1327,7 +1328,7 @@ SideStakeAlloc GetSideStakingStatusAndAlloc() dSumAllocation += dAllocation; if (dSumAllocation > 1.0) { - LogPrintf("WARN: %s: allocation percentage over 100\%, ending sidestake allocations.", __func__); + LogPrintf("WARN: %s: allocation percentage over 100 percent, ending sidestake allocations.", __func__); break; } diff --git a/src/util/time.cpp b/src/util/time.cpp index 34eff52c20..59c5715c64 100644 --- a/src/util/time.cpp +++ b/src/util/time.cpp @@ -261,7 +261,7 @@ int64_t MilliTimer::GetStartTime(const std::string& label) internal_timer = timer_map.at(label); } catch (std::out_of_range&) { - LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zero start time."); + LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zero start time.", __func__); } return internal_timer.start_time; @@ -291,7 +291,7 @@ const MilliTimer::timer MilliTimer::GetTimes(const std::string& log_string, cons } catch (std::out_of_range&) { - LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zeroed timer."); + LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zeroed timer.", __func__); timer = {}; return timer; } @@ -300,8 +300,8 @@ const MilliTimer::timer MilliTimer::GetTimes(const std::string& log_string, cons // minimize lock time. if (internal_timer.log) { - LogPrintf("timer %s: %s: elapsed time: %" PRId64 " ms, time since last check: %" PRId64 " ms.", - label, log_string, timer.elapsed_time, timer.time_since_last_check); + LogPrintf("INFO: %s: timer %s: %s: elapsed time: %" PRId64 " ms, time since last check: %" PRId64 " ms.", + __func__, label, log_string, timer.elapsed_time, timer.time_since_last_check); } return timer; From c16b44812764a2fe4c045b40759350fe9b1674eb Mon Sep 17 00:00:00 2001 From: "James C. Owens" Date: Sun, 27 Mar 2022 18:20:07 -0400 Subject: [PATCH 7/7] Fix typo in comment Co-authored-by: RoboticMind <30132912+RoboticMind@users.noreply.github.com> --- src/tinyformat.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tinyformat.h b/src/tinyformat.h index bad01ba038..e958802642 100644 --- a/src/tinyformat.h +++ b/src/tinyformat.h @@ -1061,7 +1061,7 @@ std::string format(const std::string &fmt, const Args&... args) return oss.str(); } -// This is to make the linter happy because it the variadic script/python variadic checker does not deal with +// This is to make the linter happy because the variadic script/python variadic checker does not deal with // overloads. template std::string strformat(const std::string &fmt, const Args&... args)