From 21a9cd3714fabc734179a24331b059fb23eec7c5 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Mon, 30 May 2022 19:32:43 +0530 Subject: [PATCH 1/4] Minor cleanups, log fds --- src/scheduler.cpp | 9 --------- src/util/system.cpp | 3 +++ src/util/threadnames.cpp | 2 +- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/scheduler.cpp b/src/scheduler.cpp index e9492346298..8c8473bf146 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -51,14 +51,6 @@ void CScheduler::serviceQueue() // Wait until either there is a new task, or until // the time of the first item on the queue: - -// wait_until needs boost 1.50 or later; older versions have timed_wait: -#if BOOST_VERSION < 105000 - while (!shouldStop() && !taskQueue.empty() && - newTaskScheduled.timed_wait(lock, toPosixTime(taskQueue.begin()->first))) { - // Keep waiting until timeout - } -#else // Some boost versions have a conflicting overload of wait_until that returns void. // Explicitly use a template here to avoid hitting that overload. while (!shouldStop() && !taskQueue.empty()) { @@ -66,7 +58,6 @@ void CScheduler::serviceQueue() if (newTaskScheduled.wait_until<>(lock, timeToWaitFor) == boost::cv_status::timeout) break; // Exit loop after timeout, it means we reached the time of the event } -#endif // If there are multiple threads, the queue can empty while we're waiting (another // thread may service the task we were waiting on). if (shouldStop() || taskQueue.empty()) diff --git a/src/util/system.cpp b/src/util/system.cpp index ffafb762c36..7b41378e53a 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -1058,8 +1058,11 @@ int RaiseFileDescriptorLimit(int nMinFD) { setrlimit(RLIMIT_NOFILE, &limitFD); getrlimit(RLIMIT_NOFILE, &limitFD); } + LogPrintf("conf: fd limit: req: %d, set %d, max: %d\n", + nMinFD, limitFD.rlim_cur, limitFD.rlim_max); return limitFD.rlim_cur; } + LogPrintf("conf: fd limit: %d, max: unknown\n", nMinFD); return nMinFD; // getrlimit failed, assume it's fine #endif } diff --git a/src/util/threadnames.cpp b/src/util/threadnames.cpp index 07b18d8597f..a641ba1b083 100644 --- a/src/util/threadnames.cpp +++ b/src/util/threadnames.cpp @@ -57,6 +57,6 @@ static void SetInternalName(std::string name) { } void util::ThreadRename(std::string&& name) { - SetThreadName(("defi-" + name).c_str()); + SetThreadName(("defid-" + name).c_str()); SetInternalName(std::move(name)); } From 5cb3dd289c98bb582d89c9b3ee07729404a180e8 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Tue, 31 May 2022 13:20:58 +0530 Subject: [PATCH 2/4] Add missing --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index 307b7670814..028512c6e33 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1889,6 +1889,7 @@ bool AppInitMain(InitInterfaces& interfaces) } return true; }); + ConsolidateRewards(*pcustomcsview, ::ChainActive().Height(), balancesToMigrate, true); } if (fullRewardConsolidation) { LogPrintf("Consolidate rewards for all addresses..\n"); From 1745d642117eb264102b2b34bd01261277d0a4bf Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Tue, 31 May 2022 14:32:37 +0530 Subject: [PATCH 3/4] Fix up mixed up default args --- src/validation.cpp | 8 ++++---- src/validation.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 48840131562..d963d0e9a3b 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3876,7 +3876,7 @@ size_t RewardConsolidationWorkersCount() { } void ConsolidateRewards(CCustomCSView &view, int height, - const std::vector> &items, int numWorkers, bool skipOnShutdown) { + const std::vector> &items, bool interruptOnShutdown, int numWorkers) { int nWorkers = numWorkers < 1 ? RewardConsolidationWorkersCount() : numWorkers; auto rewardsTime = GetTimeMicros(); boost::asio::thread_pool workerPool(nWorkers); @@ -3890,12 +3890,12 @@ void ConsolidateRewards(CCustomCSView &view, int height, // Technically not fully synchronized, but avoid races // due to the segregated areas of operation. boost::asio::post(workerPool, [&, &account = owner]() { - if (skipOnShutdown && ShutdownRequested()) return; + if (interruptOnShutdown && ShutdownRequested()) return; auto tempView = std::make_unique(view); tempView->CalculateOwnerRewards(account, height); boost::asio::post(mergeWorker, [&, tempView = std::move(tempView)]() { - if (skipOnShutdown && ShutdownRequested()) return; + if (interruptOnShutdown && ShutdownRequested()) return; tempView->Flush(); // This entire block is already serialized with single merge worker. @@ -4022,7 +4022,7 @@ static Res PoolSplits(CCustomCSView& view, CAmount& totalBalance, ATTRIBUTES& at return a.second > b.second; }); - ConsolidateRewards(view, pindex->nHeight, balancesToMigrate, nWorkers); + ConsolidateRewards(view, pindex->nHeight, balancesToMigrate, false, nWorkers); // Special case. No liquidity providers in a previously used pool. if (balancesToMigrate.empty() && oldPoolPair->totalLiquidity == CPoolPair::MINIMUM_LIQUIDITY) { diff --git a/src/validation.h b/src/validation.h index 690b58429d7..4232401626d 100644 --- a/src/validation.h +++ b/src/validation.h @@ -857,7 +857,7 @@ inline CAmount CalculateCoinbaseReward(const CAmount blockReward, const uint32_t Res AddNonTxToBurnIndex(const CScript& from, const CBalances& amounts); void ConsolidateRewards(CCustomCSView& view, int height, - const std::vector> &items, int numWorkers = 0, - bool skipOnShutdown = false); + const std::vector> &items, + bool interruptOnShutdown = false, int numWorkers = 0); #endif // DEFI_VALIDATION_H From b545f758c3e70e504ab8ba1316971de922e52506 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Tue, 31 May 2022 16:26:44 +0530 Subject: [PATCH 4/4] Add compiler bug notes --- src/validation.cpp | 7 +++++++ src/validation.h | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/validation.cpp b/src/validation.cpp index d963d0e9a3b..536534e3ed6 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -3875,6 +3875,13 @@ size_t RewardConsolidationWorkersCount() { return workersMax > 2 ? workersMax : 3; } +// Note: Be careful with lambda captures and default args. GCC 11.2.0, appears the if the captures are +// unused in the function directly, but inside the lambda, it completely disassociates them from the fn +// possibly when the lambda is lifted up and with default args, ends up inling the default arg +// completely. TODO: verify with smaller test case. +// But scenario: If `interruptOnShutdown` is set as default arg to false, it will never be set true +// on the below as it's inlined by gcc 11.2.0 on Ubuntu 22.04 incorrectly. Behavior is correct +// in lower versions of gcc or across clang. void ConsolidateRewards(CCustomCSView &view, int height, const std::vector> &items, bool interruptOnShutdown, int numWorkers) { int nWorkers = numWorkers < 1 ? RewardConsolidationWorkersCount() : numWorkers; diff --git a/src/validation.h b/src/validation.h index 4232401626d..72c1c2bf6a3 100644 --- a/src/validation.h +++ b/src/validation.h @@ -858,6 +858,6 @@ Res AddNonTxToBurnIndex(const CScript& from, const CBalances& amounts); void ConsolidateRewards(CCustomCSView& view, int height, const std::vector> &items, - bool interruptOnShutdown = false, int numWorkers = 0); + bool interruptOnShutdown, int numWorkers = 0); #endif // DEFI_VALIDATION_H